diff --git a/WP-GPX-Maps.js b/WP-GPX-Maps.js index 16b7f0e..5ee2544 100644 --- a/WP-GPX-Maps.js +++ b/WP-GPX-Maps.js @@ -14,9 +14,11 @@ var loc = loc_en; function wpgpxmaps(targhetId,mapType,mapData,graphData) { - var el = document.getElementById(targhetId); - var el_map = el.childNodes[0]; - var el_chart = el.childNodes[1]; + + var el = document.getElementById("wpgpxmaps_" + targhetId); + var el_map = document.getElementById("map_" + targhetId); + var el_chart = document.getElementById("chart_" + targhetId); + switch (mapType) { case 'TERRAIN': { mapType = google.maps.MapTypeId.TERRAIN; break;} diff --git a/wp-gpx-maps.php b/wp-gpx-maps.php index 17d6ac9..b9048b8 100644 --- a/wp-gpx-maps.php +++ b/wp-gpx-maps.php @@ -59,7 +59,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') jQuery(document).ready(function () { var m_'.$r.' = ['.$points_maps.']; var c_'.$r.' = ['.$points_graph.']; - wpgpxmaps("wpgpxmaps_'.$r.'",\''.$t.'\',m_'.$r.',c_'.$r.'); + wpgpxmaps("'.$r.'",\''.$t.'\',m_'.$r.',c_'.$r.'); }); '; diff --git a/wp-gpx-maps_Utils.php b/wp-gpx-maps_Utils.php index 26f5cb6..00d9fc4 100644 --- a/wp-gpx-maps_Utils.php +++ b/wp-gpx-maps_Utils.php @@ -1,96 +1,96 @@ - 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)); - } - + 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 diff --git a/wp-gpx-maps_admin.php b/wp-gpx-maps_admin.php new file mode 100644 index 0000000..2da04f3 --- /dev/null +++ b/wp-gpx-maps_admin.php @@ -0,0 +1,190 @@ + + +
+

WP GPX Settings

+ + + Can\'t create '.$realGpxPath.' folder. Please create it and make it writable!
+ If not, you will must update the file manually! +
'; + } + } + +?> + +
+ The fastest way to use this plugin: upload the file using the uploader below, than put this + shotcode: [sgpx gpx="/wp-content/uploads/gpx/< gpx file name >"] in the pages/posts. +
+ +
+ + + + + + + + + + + + + + + + +
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.
+
+ + + + +

+ +

+ +
+ + + +
+
+ + Choose a file to upload: + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileLast modifiedFile size (Byte)
FileLast modifiedFile size (Byte)
+ +
+ Delete + | + Download +
+
+
+

+
+
+
+

+
+
+ + + + + +
+ +
+ \ No newline at end of file