From 53639d7a976f1e7a9b5093573943660d5edf38af Mon Sep 17 00:00:00 2001 From: bastianonm Date: Wed, 14 Dec 2011 10:35:25 +0000 Subject: [PATCH] --- WP-GPX-Maps.js | 89 +++++++++++++++++++++++++ readme.txt | 44 +++++++++++++ wp-gpx-maps.php | 150 ++++++++++++++++++++++++++++++++++++++++++ wp-gpx-maps_Utils.php | 97 +++++++++++++++++++++++++++ 4 files changed, 380 insertions(+) create mode 100644 WP-GPX-Maps.js create mode 100644 readme.txt create mode 100644 wp-gpx-maps.php create mode 100644 wp-gpx-maps_Utils.php diff --git a/WP-GPX-Maps.js b/WP-GPX-Maps.js new file mode 100644 index 0000000..172a25f --- /dev/null +++ b/WP-GPX-Maps.js @@ -0,0 +1,89 @@ +function wpgpxmaps(targhetId,mapType,mapData,graphData) +{ + var el = document.getElementById(targhetId); + var el_map = el.childNodes[0]; + var el_chart = el.childNodes[1]; + switch (mapType) + { + case 'TERRAIN': { mapType = google.maps.MapTypeId.TERRAIN; break;} + case 'SATELLITE': { mapType = google.maps.MapTypeId.SATELLITE; break;} + case 'ROADMAP': { mapType = google.maps.MapTypeId.ROADMAP; break;} + default: { mapType = google.maps.MapTypeId.HYBRID; break;} + } + var mapOptions = { + mapTypeId: mapType + }; + var map = new google.maps.Map(el_map, mapOptions); + if (graphData!= '') + { + var data = new google.visualization.DataTable(); + data.addColumn('number', 'Lunghezza'); + data.addColumn('number', 'Altezza'); + data.addRows(graphData); + var chart = new google.visualization.AreaChart(el_chart); + var options = { curveType: "function", + strictFirstColumnType: true, + hAxis : {format : '#,###m', title : "Lunghezza"}, + vAxis : {format : '#,###m', title : "Altitudine"}, + legend : {position : 'none'}, + chartArea: {left:70,top:10,width:"100%",height:"75%"} + }; + chart.draw(data, options); + google.visualization.events.addListener(chart, 'onmouseover', function (e) { + var r = e['row']; + if (marker) + { + var point = getItemFromArray(mapData,r) + marker.setPosition(new google.maps.LatLng(point[0],point[1])); + } + }); + google.visualization.events.addListener(chart, 'onmouseout', function (e) { + if (marker) + { + if (chart.getSelection() != '') + { + var r = chart.getSelection()[0]['row']; + var point = getItemFromArray(mapData,r) + marker.setPosition(new google.maps.LatLng(point[0], point[1])); + } + } + }); + } + if (mapData != '') + { + var points = []; + var bounds = new google.maps.LatLngBounds(); + for(var i in mapData) + { + var p = new google.maps.LatLng(mapData[i][0], mapData[i][1]); + points.push(p); + bounds.extend(p); + } + var poly = new google.maps.Polyline({ + path: points, + strokeColor: "#3366cc", + strokeOpacity: .7, + strokeWeight: 4 + }); + poly.setMap(map); + map.setCenter(bounds.getCenter()); + map.fitBounds(bounds); + var first = getItemFromArray(mapData,0) + var marker = new google.maps.Marker({ + position: new google.maps.LatLng(first[0], first[1]), + title:"Hello World!" + }); + marker.setMap(map); + } +} +function getItemFromArray(arr,index) +{ + try + { + return arr[index]; + } + catch(e) + { + return [0,0]; + } +} diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..cce8efa --- /dev/null +++ b/readme.txt @@ -0,0 +1,44 @@ +=== WP-GPX-Maps === +Contributors: bastianonm +Donate link: http://www.darwinner.it/ +Tags: maps, gpx, graph, google maps, google chart +Requires at least: 2.0.0 +Tested up to: 3.3 +Stable tag: 1.0.0 +License: GPLv2 or later + +Add a gpx trak with altitude graph + +== Description == + +Add a gpx trak with altitude graph + +WP-GPX-Maps + +== Installation == + +This section describes how to install the plugin and get it working. + +e.g. + +1. Use the classic wordpress plugin installer or copy the plugins folder to the `/wp-content/plugins/` directory +1. Activate the plugin through the 'Plugins' menu in WordPress +1. Add the shortcode [sgpx gpx=""] + +== Frequently Asked Questions == + += Is it free? = + +Yes! + += What happening if I've a very large gpx? = + +This plugin will print a small amout of points in orther to speedup javascript and pageload. + +== Screenshots == + + +== Changelog == + += 0.5 = +* Initial release. \ No newline at end of file diff --git a/wp-gpx-maps.php b/wp-gpx-maps.php new file mode 100644 index 0000000..876e409 --- /dev/null +++ b/wp-gpx-maps.php @@ -0,0 +1,150 @@ + + + + + +
+
+ + '; + } + +register_activation_hook(__FILE__,'WP_GPX_Maps_install'); +register_deactivation_hook( __FILE__, 'WP_GPX_Maps_remove'); + +function WP_GPX_Maps_install() { + add_option("wpgpxmaps_width", '100%', '', 'yes'); + add_option("wpgpxmaps_height", '450px', '', 'yes'); + add_option('wpgpxmaps_map_type','HYBRID','','yes'); +} + +function WP_GPX_Maps_remove() { + delete_option('wpgpxmaps_width'); + delete_option('wpgpxmaps_height'); + delete_option('wpgpxmaps_map_type'); +} +?> + + + + +
+

WP GPX Settings

+ +
+ + + + + + + + + + + + + + + + +
Maps Width: + +
Maps Height: + +
Default Map Type: + + + + > This map type displays a transparent layer of major streets on satellite images.
+ > This map type displays a normal street map.
+ > This map type displays satellite images.
+ > This map type displays maps with physical features such as terrain and vegetation.
+ +
+ + + +

+ +

+ +
+
+ + diff --git a/wp-gpx-maps_Utils.php b/wp-gpx-maps_Utils.php new file mode 100644 index 0000000..75c9d13 --- /dev/null +++ b/wp-gpx-maps_Utils.php @@ -0,0 +1,97 @@ + 0)) + { + $gpxOffset = 10; + } + + $realGpxPath = substr (__FILE__, 0, strrpos(__FILE__,'/wp-content/')).$gpxPath; + + if (file_exists($realGpxPath)) + { + + $gpx = simplexml_load_file($realGpxPath); + $gpx->registerXPathNamespace('10', 'http://www.topografix.com/GPX/1/0'); + $gpx->registerXPathNamespace('11', 'http://www.topografix.com/GPX/1/1'); + + foreach($gpx->xpath('//trkpt | //10:trkpt | //11:trkpt') as $trkpt){ + $lat = $trkpt['lat']; + $lon = $trkpt['lon']; + $ele = $trkpt->ele; + if ($lastLat == 0 && $lastLon == 0) + { + //Base Case + array_push($points, array((float)$lat,(float)$lon,(float)round($ele,1),(float)round($dist,1))); + $lastLat=$lat; + $lastLon=$lon; + $lastEle=$ele; + } + else + { + //Normal Case + $offset = calculateDistance($lat, $lon, $ele,$lastLat, $lastLon, $lastEle); + $dist = $dist + $offset; + if (((float) $offset + (float) $lastOffset) > $gpxOffset) + { + //Bigger Offset -> write coordinate + $lastOffset=0; + array_push($points, array((float)$lat,(float)$lon,(float)round($ele,1),(float)round($dist,1))); + } + else + { + //Smoller Offset -> continue.. + $lastOffset= (float) $lastOffset + (float) $offset ; + } + } + $lastLat=$lat; + $lastLon=$lon; + $lastEle=$ele; + } + } + else + { + array_push($points, array((float)0,(float)0,(float)0,(float)0)); + } + + // riduco l'array a circa 200 punti per non appensantire la pagina(mappa e grafico)! + $count=sizeof($points); + if ($count>200) + { + $f = round($count/200); + if ($f>1) + for($i=$count;$i>0;$i--) + if ($i % $f != 0) + unset($points[$i]); + } + return $points; + } + + function toRadians($degrees) + { + return $degrees * 3.1415926535897932385 / 180; + } + + function calculateDistance($lat1,$lon1,$ele1,$lat2,$lon2,$ele2) + { + //Distance in meters + $dLat = toRadians((float) $lat2 - (float) $lat1); + $dLng = toRadians((float) $lon2 - (float) $lon1); + $a = (float) ( sin($dLat / 2) * sin($dLat / 2)) + (float) ( cos( toRadians($lat1)) * cos( toRadians($lat2)) * sin($dLng / 2) * sin($dLng / 2) ); + $dist = 2 * 3958.75 * atan2(sqrt($a), sqrt(1 - (float) $a)); + return sqrt(pow($dist * 1609.00, 2) + pow((float) $lat1 - (float)$lat2, 2)); + } + +?> \ No newline at end of file