diff --git a/WP-GPX-Maps.js b/WP-GPX-Maps.js index 7663964..390b36c 100644 --- a/WP-GPX-Maps.js +++ b/WP-GPX-Maps.js @@ -117,6 +117,16 @@ function setup() } +function get_random_color() { + var letters = '0123456789ABCDEF'.split(''); + var color = '#'; + for (var i = 0; i < 6; i++ ) { + color += letters[Math.round(Math.random() * 15)]; + } + return color; +} + + function _wpgpxmaps(params) { @@ -299,56 +309,86 @@ function _wpgpxmaps(params) // Print Images - var divImages = document.getElementById("ngimages_"+targetId); + jQuery("#ngimages_" + targetId).attr("style","display:block;position:absolute;left:-50000px"); + jQuery("#ngimages_" + targetId + " span").each(function(){ - divImages.style.display='block'; - divImages.style.position='absolute'; - divImages.style.left='-50000px'; - - var img_spans = divImages.getElementsByTagName("span"); - - if (img_spans.length > 0) - { - var bb = new google.maps.LatLngBounds(); - for (var i = 0; i < img_spans.length; i++) { + var imageLat = jQuery(this).attr("lat"); + var imageLon = jQuery(this).attr("lon"); - var imageLat = img_spans[i].getAttribute("lat"); - var imageLon = img_spans[i].getAttribute("lon"); - var imageImg = img_spans[i].getElementsByTagName('img')[0]; - var imageUrl = imageImg.getAttribute("src"); - - var img_w = imageImg.clientWidth; - var img_h = imageImg.clientHeight; - - var p = new google.maps.LatLng(imageLat, imageLon); - bounds.extend(p); + jQuery("img",this).each(function() { + + jQuery(this).load(function(){ + + var imageUrl = jQuery(this).attr("src"); + var img_w = jQuery(this).width(); + var img_h = jQuery(this).height(); + + var p = new google.maps.LatLng(imageLat, imageLon); + bounds.extend(p); + + var mc = new CustomMarker(map, p, imageUrl, img_w, img_h ); + + google.maps.event.addListener(mc, "click", function(div) { + var lat = div.getAttribute("lat"); + var lon = div.getAttribute("lon"); + var a = getClosestImage(lat,lon,targetId).childNodes[0]; + if (a) + { + a.click(); + } + }); - var mc = new CustomMarker(map, p, imageUrl, img_w, img_h ); - - google.maps.event.addListener(mc, "click", function(div) { - var lat = div.getAttribute("lat"); - var lon = div.getAttribute("lon"); - var a = getClosestImage(lat,lon,targetId).childNodes[0]; - if (a) - { - a.click(); - } }); - - } + + if (jQuery(this).width() + jQuery(this).height() > 0) + { + jQuery(this).trigger("load"); + } - } + }); + + }); // Print Track if (mapData != '') { var points = []; + var lastCut=0; + var polylinenes = []; for (i=0; i < mapData.length; i++) + { + if (mapData[i] == null) + { + var poly = new google.maps.Polyline({ + path: points.slice(lastCut,i), + strokeColor: color1, + strokeOpacity: .7, + strokeWeight: 4, + map: map + }); + polylinenes.push(poly); + lastCut=i; + } + else + { + var p = new google.maps.LatLng(mapData[i][0], mapData[i][1]); + points.push(p); + bounds.extend(p); + } + } + + if (points.length != lastCut) { - 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.slice(lastCut), + strokeColor: color1, + strokeOpacity: .7, + strokeWeight: 4, + map: map + }); + polylinenes.push(poly); + currentPoints = []; } if (startIcon != '') @@ -362,6 +402,7 @@ function _wpgpxmaps(params) icon: startIconImage, zIndex: 10 }); + } if (endIcon != '') @@ -377,14 +418,6 @@ function _wpgpxmaps(params) }); } - - var poly = new google.maps.Polyline({ - path: points, - strokeColor: color1, - strokeOpacity: .7, - strokeWeight: 4 - }); - poly.setMap(map); var first = getItemFromArray(mapData,0) @@ -407,34 +440,40 @@ function _wpgpxmaps(params) zIndex: 10 }); - google.maps.event.addListener(poly,'mouseover',function(event){ - if (marker) - { - marker.setPosition(event.latLng); - marker.setTitle(lng.currentPosition); - if (hchart) + for (i=0; i < polylinenes.length; i++) + { + + google.maps.event.addListener(polylinenes[i],'mouseover',function(event){ + if (marker) { - var tooltip = hchart.tooltip; - var l1 = event.latLng.lat(); - var l2 = event.latLng.lng(); - var ci = getClosestIndex(mapData,l1,l2); - var items = []; - var seriesLen = hchart.series.length; - for(var i=0; i 0) + tooltip.refresh(items); } - if (items.length > 0) - tooltip.refresh(items); } - } - }); + }); + } } map.setCenter(bounds.getCenter()); map.fitBounds(bounds); - if (graphDist != '' && (graphEle != '' || graphSpeed != '' || graphHr != '' || graphCad != '')) + var graphh = jQuery('#hchart_' + params.targetId).css("height"); + + if (graphDist != '' && (graphEle != '' || graphSpeed != '' || graphHr != '' || graphCad != '') && graphh != "0px") { var valLen = graphDist.length; @@ -509,7 +548,10 @@ function _wpgpxmaps(params) if(item.x == this.x) { var point = getItemFromArray(mapData,i) - marker.setPosition(new google.maps.LatLng(point[0],point[1])); + if (point) + { + marker.setPosition(new google.maps.LatLng(point[0],point[1])); + } marker.setTitle(lng.currentPosition); i+=10000000; } @@ -560,7 +602,8 @@ function _wpgpxmaps(params) for (i=0; idt; + $points_x_lat = $points->lat; + $points_x_lon = $points->lon; $max_ele = $points->maxEle; $min_ele = $points->minEle; @@ -231,41 +242,62 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') foreach(array_keys($points->lat) as $i) { - - $points_maps .= '['.(float)$points->lat[$i].','.(float)$points->lon[$i].'],'; - - $_ele = (float)$points->ele[$i]; - $_dist = (float)$points->dist[$i]; - if ($uom == '1') + $_lat = (float)$points->lat[$i]; + $_lon = (float)$points->lon[$i]; + + if ( $_lat == 0 && $_lon == 0 ) { - // Miles and feet - $_dist *= 0.000621371192; - $_ele *= 3.2808399; - } else if ($uom == '2') - { - // meters / kilometers - $_dist = (float)($_dist / 1000); + $points_maps .= 'null,'; + $points_graph_dist .= 'null,'; + $points_graph_ele .= 'null,'; + + if ($showSpeed == true) + $points_graph_speed .= 'null,'; + + if ($showHr == true) + $points_graph_hr .= 'null,'; + + if ($showCad == true) + $points_graph_cad .= 'null,'; } - - $points_graph_dist .= $_dist.','; - $points_graph_ele .= $_ele.','; + else + { + $points_maps .= '['.(float)$points->lat[$i].','.(float)$points->lon[$i].'],'; + + $_ele = (float)$points->ele[$i]; + $_dist = (float)$points->dist[$i]; - if ($showSpeed == true) { - - $_speed = (float)$points->speed[$i]; + if ($uom == '1') + { + // Miles and feet + $_dist *= 0.000621371192; + $_ele *= 3.2808399; + } else if ($uom == '2') + { + // meters / kilometers + $_dist = (float)($_dist / 1000); + } - $points_graph_speed .= convertSpeed($_speed,$uomspeed).','; - } - - if ($showHr == true) - { - $points_graph_hr .= $points->hr[$i].','; - } - - if ($showCad == true) - { - $points_graph_cad .= $points->cad[$i].','; + $points_graph_dist .= $_dist.','; + $points_graph_ele .= $_ele.','; + + if ($showSpeed == true) { + + $_speed = (float)$points->speed[$i]; + + $points_graph_speed .= convertSpeed($_speed,$uomspeed).','; + } + + if ($showHr == true) + { + $points_graph_hr .= $points->hr[$i].','; + } + + if ($showCad == true) + { + $points_graph_cad .= $points->cad[$i].','; + } } } @@ -307,9 +339,10 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') } } - $p="/,$/"; + $p="/(,|,null,)$/"; + $points_maps = preg_replace($p, "", $points_maps); - + $points_graph_dist = preg_replace($p, "", $points_graph_dist); $points_graph_ele = preg_replace($p, "", $points_graph_ele); $points_graph_speed = preg_replace($p, "", $points_graph_speed); @@ -338,7 +371,10 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $ngimgs_data = ''; if ( $ngGalleries != '' || $ngImages != '' ) { - $ngimgs = getNGGalleryImages($ngGalleries, $ngImages, $error); + + //print_r($points); + + $ngimgs = getNGGalleryImages($ngGalleries, $ngImages, $points_x_time, $points_x_lat, $points_x_lon, $dtoffset, $error); $ngimgs_data =''; foreach ($ngimgs as $img) { $data = $img['data']; @@ -348,25 +384,37 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') } @file_put_contents($gpxcache, - serialize(array( "points_maps" => $points_maps, - "points_graph_dist" => $points_graph_dist, - "points_graph_ele" => $points_graph_ele, - "points_graph_speed" => $points_graph_speed, - "points_graph_hr" => $points_graph_hr, - "points_graph_cad" => $points_graph_cad, - "waypoints" => $waypoints, - "max_ele" => $max_ele, - "min_ele" => $min_ele, - "total_ele_up" => $total_ele_up, - "total_ele_down" => $total_ele_down, - "avg_speed" => $avg_speed, - "tot_len" => $tot_len + serialize(array( "points_maps" => $points_maps, + "points_x_time" => $points_x_time, + "points_x_lat" => $points_x_lat, + "points_x_lon" => $points_x_lon, + "points_graph_dist" => $points_graph_dist, + "points_graph_ele" => $points_graph_ele, + "points_graph_speed" => $points_graph_speed, + "points_graph_hr" => $points_graph_hr, + "points_graph_cad" => $points_graph_cad, + "waypoints" => $waypoints, + "max_ele" => $max_ele, + "min_ele" => $min_ele, + "total_ele_up" => $total_ele_up, + "total_ele_down" => $total_ele_down, + "avg_speed" => $avg_speed, + "tot_len" => $tot_len ) ), LOCK_EX); @chmod($gpxcache,0755); + if ($gh == "0" || $gh == "0px") + { + $points_graph_dist = ''; + $points_graph_ele = ''; + $points_graph_speed = ''; + $points_graph_hr = ''; + $points_graph_cad = ''; + } + $output = '
diff --git a/wp-gpx-maps_utils.php b/wp-gpx-maps_utils.php index 93c887c..3445cd2 100644 --- a/wp-gpx-maps_utils.php +++ b/wp-gpx-maps_utils.php @@ -82,7 +82,7 @@ if (file_exists($gpxPath)) { - $points = parseXml($gpxPath, $gpxOffset); + $points = @parseXml($gpxPath, $gpxOffset); } else { @@ -98,8 +98,9 @@ $f = round($count/200); if ($f>1) for($i=$count;$i>0;$i--) - if ($i % $f != 0) + if ($i % $f != 0 && $points->lat[$i] != null) { + unset($points->dt[$i]); unset($points->lat[$i]); unset($points->lon[$i]); unset($points->ele[$i]); @@ -118,6 +119,7 @@ $points = null; + $points->dt = array(); $points->lat = array(); $points->lon = array(); $points->ele = array(); @@ -138,136 +140,165 @@ return; $gpx->registerXPathNamespace('10', 'http://www.topografix.com/GPX/1/0'); - $gpx->registerXPathNamespace('11', 'http://www.topografix.com/GPX/1/1'); - $gpx->registerXPathNamespace('gpxx', 'http://www.garmin.com/xmlschemas/GpxExtensions/v3'); + $gpx->registerXPathNamespace('11', 'http://www.topografix.com/GPX/1/1'); $gpx->registerXPathNamespace('gpxtpx', 'http://www.garmin.com/xmlschemas/TrackPointExtension/v1'); - $nodes = $gpx->xpath('//trkpt | //10:trkpt | //11:trkpt | //11:rtept'); + $nodes = $gpx->xpath('//trk | //10:trk | //11:trk'); + + //normal gpx if ( count($nodes) > 0 ) { - $lastLat = 0; - $lastLon = 0; - $lastEle = 0; - $lastTime = 0; - $dist = 0; - $lastOffset = 0; - $speedBuffer = array(); - - // normal case - foreach($nodes as $trkpt) - { - $lat = $trkpt['lat']; - $lon = $trkpt['lon']; - $ele = $trkpt->ele; - $time = $trkpt->time; - $speed = (float)$trkpt->speed; - $hr = 0; - $cad = 0; + foreach($nodes as $_trk) + { + + $trk = simplexml_load_string($_trk->asXML()); - if (isset($trkpt->extensions)) - { - $_hr = @$trkpt->extensions->xpath('gpxtpx:TrackPointExtension/gpxtpx:hr/text()'); - if ($_hr) - { - foreach ($_hr as $node) { - $hr = (float)$node; - } - } + $trk->registerXPathNamespace('10', 'http://www.topografix.com/GPX/1/0'); + $trk->registerXPathNamespace('11', 'http://www.topografix.com/GPX/1/1'); + $trk->registerXPathNamespace('gpxtpx', 'http://www.garmin.com/xmlschemas/TrackPointExtension/v1'); - $_cad = @$trkpt->extensions->xpath('gpxtpx:TrackPointExtension/gpxtpx:cad/text()'); - if ($_cad) - { - foreach ($_cad as $node) { - $cad = (float)$node; - } - } - } + $trkpts = $trk->xpath('//trkpt | //10:trkpt | //11:trkpt'); + + $lastLat = 0; + $lastLon = 0; + $lastEle = 0; + $lastTime = 0; + //$dist = 0; + $lastOffset = 0; + $speedBuffer = array(); + + foreach($trkpts as $trkpt) + { - if ($lastLat == 0 && $lastLon == 0) - { - //Base Case + $lat = $trkpt['lat']; + $lon = $trkpt['lon']; + $ele = $trkpt->ele; + $time = $trkpt->time; + $speed = (float)$trkpt->speed; + $hr = 0; + $cad = 0; - array_push($points->lat, (float)$lat); - array_push($points->lon, (float)$lon); - array_push($points->ele, (float)round($ele,2)); - array_push($points->dist, (float)round($dist,2)); - array_push($points->speed, 0); - array_push($points->hr, $hr); - array_push($points->cad, $cad); - - $lastLat=$lat; - $lastLon=$lon; - $lastEle=$ele; - $lastTime=$time; - } - else - { - //Normal Case - $offset = calculateDistance((float)$lat, (float)$lon, (float)$ele, (float)$lastLat, (float)$lastLon, (float)$lastEle); - $dist = $dist + $offset; - - $points->totalLength = $dist; - - if ($speed == 0) - { - $datediff = (float)my_date_diff($lastTime,$time); - if ($datediff>0) + if (isset($trkpt->extensions)) + { + $_hr = @$trkpt->extensions->xpath('gpxtpx:TrackPointExtension/gpxtpx:hr/text()'); + if ($_hr) { - $speed = $offset / $datediff; + foreach ($_hr as $node) { + $hr = (float)$node; + } + } + + $_cad = @$trkpt->extensions->xpath('gpxtpx:TrackPointExtension/gpxtpx:cad/text()'); + if ($_cad) + { + foreach ($_cad as $node) { + $cad = (float)$node; + } } } - - if ($ele != 0 && $lastEle != 0) + + if ($lastLat == 0 && $lastLon == 0) { - if ((float)$ele > (float)$lastEle) - { - $points->totalEleUp += (float)($ele - $lastEle); - } - else - { - $points->totalEleDown += (float)($lastEle - $ele); - } - } - - array_push($speedBuffer, $speed); - - if (((float) $offset + (float) $lastOffset) > $gpxOffset) - { - //Bigger Offset -> write coordinate - $avgSpeed = 0; - - foreach($speedBuffer as $s) - { - $avgSpeed += $s; - } - - $avgSpeed = $avgSpeed / count($speedBuffer); - $speedBuffer = array(); - - $lastOffset=0; - - array_push($points->lat, (float)$lat ); - array_push($points->lon, (float)$lon ); - array_push($points->ele, (float)round($ele, 2) ); - array_push($points->dist, (float)round($dist, 2) ); - array_push($points->speed, (float)round($avgSpeed, 1) ); - array_push($points->hr, $hr); - array_push($points->cad, $cad); + //Base Case + + array_push($points->dt, strtotime($time)); + array_push($points->lat, (float)$lat); + array_push($points->lon, (float)$lon); + array_push($points->ele, (float)round($ele,2)); + array_push($points->dist, (float)round($dist,2)); + array_push($points->speed, 0); + array_push($points->hr, $hr); + array_push($points->cad, $cad); + $lastLat=$lat; + $lastLon=$lon; + $lastEle=$ele; + $lastTime=$time; } else { - //Smoller Offset -> continue.. - $lastOffset = (float) $lastOffset + (float) $offset ; + //Normal Case + $offset = calculateDistance((float)$lat, (float)$lon, (float)$ele, (float)$lastLat, (float)$lastLon, (float)$lastEle); + $dist = $dist + $offset; + + $points->totalLength = $dist; + + if ($speed == 0) + { + $datediff = (float)my_date_diff($lastTime,$time); + if ($datediff>0) + { + $speed = $offset / $datediff; + } + } + + if ($ele != 0 && $lastEle != 0) + { + if ((float)$ele > (float)$lastEle) + { + $points->totalEleUp += (float)($ele - $lastEle); + } + else + { + $points->totalEleDown += (float)($lastEle - $ele); + } + } + + array_push($speedBuffer, $speed); + + if (((float) $offset + (float) $lastOffset) > $gpxOffset) + { + //Bigger Offset -> write coordinate + $avgSpeed = 0; + + foreach($speedBuffer as $s) + { + $avgSpeed += $s; + } + + $avgSpeed = $avgSpeed / count($speedBuffer); + $speedBuffer = array(); + + $lastOffset=0; + + array_push($points->dt, strtotime($time)); + array_push($points->lat, (float)$lat ); + array_push($points->lon, (float)$lon ); + array_push($points->ele, (float)round($ele, 2) ); + array_push($points->dist, (float)round($dist, 2) ); + array_push($points->speed, (float)round($avgSpeed, 1) ); + array_push($points->hr, $hr); + array_push($points->cad, $cad); + + } + else + { + //Smoller Offset -> continue.. + $lastOffset = (float) $lastOffset + (float) $offset ; + } } + $lastLat=$lat; + $lastLon=$lon; + $lastEle=$ele; + $lastTime=$time; + } - $lastLat=$lat; - $lastLon=$lon; - $lastEle=$ele; - $lastTime=$time; + + array_push($points->dt, null); + array_push($points->lat, null); + array_push($points->lon, null); + array_push($points->ele, null); + array_push($points->dist, null); + array_push($points->speed, null); + array_push($points->hr, null); + array_push($points->cad, null); + + unset($trkpts); + } + unset($nodes); try { @@ -281,6 +312,9 @@ else { + // gpx garmin case + $gpx->registerXPathNamespace('gpxx', 'http://www.garmin.com/xmlschemas/GpxExtensions/v3'); + $nodes = $gpx->xpath('//gpxx:rpt'); if ( count($nodes) > 0 ) @@ -338,13 +372,80 @@ $lastLon=$lon; } unset($nodes); - + } else - { - echo "Empty Gpx or not supported File!"; + { + + //gpx strange case + + $nodes = $gpx->xpath('//rtept | //10:rtept | //11:rtept'); + if ( count($nodes) > 0 ) + { + + $lastLat = 0; + $lastLon = 0; + $lastEle = 0; + $dist = 0; + $lastOffset = 0; + + // Garmin case + foreach($nodes as $rtept) + { + + $lat = $rtept['lat']; + $lon = $rtept['lon']; + if ($lastLat == 0 && $lastLon == 0) + { + //Base Case + array_push($points->lat, (float)$lat ); + array_push($points->lon, (float)$lon ); + array_push($points->ele, 0 ); + array_push($points->dist, 0 ); + array_push($points->speed, 0 ); + array_push($points->hr, 0 ); + array_push($points->cad, 0 ); + $lastLat=$lat; + $lastLon=$lon; + } + else + { + //Normal Case + $offset = calculateDistance($lat, $lon, 0,$lastLat, $lastLon, 0); + $dist = $dist + $offset; + if (((float) $offset + (float) $lastOffset) > $gpxOffset) + { + //Bigger Offset -> write coordinate + $lastOffset=0; + array_push($points->lat, (float)$lat ); + array_push($points->lon, (float)$lon ); + array_push($points->ele, 0 ); + array_push($points->dist, 0 ); + array_push($points->speed, 0 ); + array_push($points->hr, 0 ); + array_push($points->cad, 0 ); + } + else + { + //Smoller Offset -> continue.. + $lastOffset= (float) $lastOffset + (float) $offset; + } + } + $lastLat=$lat; + $lastLon=$lon; + } + unset($nodes); + + } + else + { + echo "Empty Gpx or not supported File!"; + } } + + } + unset($gpx); return $points; } diff --git a/wp-gpx-maps_utils_nggallery.php b/wp-gpx-maps_utils_nggallery.php index 7beeec5..0ac3af3 100644 --- a/wp-gpx-maps_utils_nggallery.php +++ b/wp-gpx-maps_utils_nggallery.php @@ -7,7 +7,7 @@ return is_plugin_active("nextgen-gallery/nggallery.php"); } - function getNGGalleryImages($ngGalleries, $ngImages, &$error) + function getNGGalleryImages($ngGalleries, $ngImages, $dt, $lat, $lon, $dtoffset, &$error) { $result = array(); @@ -16,7 +16,6 @@ if (!isNGGalleryActive()) return ''; - try { $pictures = array(); @@ -26,6 +25,7 @@ foreach ($imgids as $i) { array_push($pictures, nggdb::find_image($i)); } + foreach ($pictures as $p) { $item = array(); $item["data"] = $p->thumbHTML; @@ -39,7 +39,18 @@ if (($item["lat"] != 0) || ($item["lon"] != 0)) { $result[] = $item; - } + } + else if (isset($p->imagedate)) + { + $_dt = strtotime($p->imagedate) + $dtoffset; + $_item = findItemCoordinate($_dt, $dt, $lat, $lon); + if ($_item != null) + { + $item["lat"] = $_item["lat"]; + $item["lon"] = $_item["lon"]; + $result[] = $item; + } + } } } else @@ -55,6 +66,19 @@ return $result; } + function findItemCoordinate($imgdt, $dt, $lat, $lon) + { + foreach(array_keys($dt) as $i) + { + if ($i!=0 && $imgdt >= $dt[$i-1] && $imgdt <= $dt[$i]) + { + if ($lat[$i] != 0 && $lon[$i] != 0) + return array( "lat" => $lat[$i], "lon" => $lon[$i] ); + } + } + return null; + } + function getExifGps($exifCoord, $hemi) { $degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;