This commit is contained in:
bastianonm 2012-07-02 12:51:45 +00:00
parent 9dce1e2583
commit 7bafbcb51f
5 changed files with 480 additions and 248 deletions

View File

@ -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) function _wpgpxmaps(params)
{ {
@ -299,56 +309,86 @@ function _wpgpxmaps(params)
// Print Images // 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'; var imageLat = jQuery(this).attr("lat");
divImages.style.position='absolute'; var imageLon = jQuery(this).attr("lon");
divImages.style.left='-50000px';
var img_spans = divImages.getElementsByTagName("span"); jQuery("img",this).each(function() {
if (img_spans.length > 0) jQuery(this).load(function(){
{
var bb = new google.maps.LatLngBounds();
for (var i = 0; i < img_spans.length; i++) {
var imageLat = img_spans[i].getAttribute("lat"); var imageUrl = jQuery(this).attr("src");
var imageLon = img_spans[i].getAttribute("lon"); var img_w = jQuery(this).width();
var imageImg = img_spans[i].getElementsByTagName('img')[0]; var img_h = jQuery(this).height();
var imageUrl = imageImg.getAttribute("src");
var img_w = imageImg.clientWidth; var p = new google.maps.LatLng(imageLat, imageLon);
var img_h = imageImg.clientHeight; bounds.extend(p);
var p = new google.maps.LatLng(imageLat, imageLon); var mc = new CustomMarker(map, p, imageUrl, img_w, img_h );
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();
}
});
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 // Print Track
if (mapData != '') if (mapData != '')
{ {
var points = []; var points = [];
var lastCut=0;
var polylinenes = [];
for (i=0; i < mapData.length; i++) for (i=0; i < mapData.length; i++)
{ {
var p = new google.maps.LatLng(mapData[i][0], mapData[i][1]); if (mapData[i] == null)
points.push(p); {
bounds.extend(p); 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 poly = new google.maps.Polyline({
path: points.slice(lastCut),
strokeColor: color1,
strokeOpacity: .7,
strokeWeight: 4,
map: map
});
polylinenes.push(poly);
currentPoints = [];
} }
if (startIcon != '') if (startIcon != '')
@ -362,6 +402,7 @@ function _wpgpxmaps(params)
icon: startIconImage, icon: startIconImage,
zIndex: 10 zIndex: 10
}); });
} }
if (endIcon != '') if (endIcon != '')
@ -378,14 +419,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) var first = getItemFromArray(mapData,0)
if (currentIcon == '') if (currentIcon == '')
@ -407,34 +440,40 @@ function _wpgpxmaps(params)
zIndex: 10 zIndex: 10
}); });
google.maps.event.addListener(poly,'mouseover',function(event){ for (i=0; i < polylinenes.length; i++)
if (marker) {
{
marker.setPosition(event.latLng); google.maps.event.addListener(polylinenes[i],'mouseover',function(event){
marker.setTitle(lng.currentPosition); if (marker)
if (hchart)
{ {
var tooltip = hchart.tooltip; marker.setPosition(event.latLng);
var l1 = event.latLng.lat(); marker.setTitle(lng.currentPosition);
var l2 = event.latLng.lng(); if (hchart)
var ci = getClosestIndex(mapData,l1,l2);
var items = [];
var seriesLen = hchart.series.length;
for(var i=0; i<seriesLen;i++)
{ {
items.push(hchart.series[i].data[ci]); 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<seriesLen;i++)
{
items.push(hchart.series[i].data[ci]);
}
if (items.length > 0)
tooltip.refresh(items);
} }
if (items.length > 0)
tooltip.refresh(items);
} }
} });
}); }
} }
map.setCenter(bounds.getCenter()); map.setCenter(bounds.getCenter());
map.fitBounds(bounds); 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; var valLen = graphDist.length;
@ -509,7 +548,10 @@ function _wpgpxmaps(params)
if(item.x == this.x) if(item.x == this.x)
{ {
var point = getItemFromArray(mapData,i) 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); marker.setTitle(lng.currentPosition);
i+=10000000; i+=10000000;
} }
@ -560,7 +602,8 @@ function _wpgpxmaps(params)
for (i=0; i<valLen; i++) for (i=0; i<valLen; i++)
{ {
eleData.push([graphDist[i],graphEle[i]]); if (graphDist[i] != null)
eleData.push([graphDist[i],graphEle[i]]);
} }
var yaxe = { var yaxe = {
@ -628,7 +671,8 @@ function _wpgpxmaps(params)
for (i=0; i<valLen; i++) for (i=0; i<valLen; i++)
{ {
speedData.push([graphDist[i],graphSpeed[i]]); if (graphDist[i] != null)
speedData.push([graphDist[i],graphSpeed[i]]);
} }
var yaxe = { var yaxe = {
@ -676,10 +720,13 @@ function _wpgpxmaps(params)
for (i=0; i<valLen; i++) for (i=0; i<valLen; i++)
{ {
var c = graphHr[i]; if (graphDist[i] != null)
if (c==0) {
c = null; var c = graphHr[i];
hrData.push([graphDist[i],c]); if (c==0)
c = null;
hrData.push([graphDist[i],c]);
}
} }
var yaxe = { var yaxe = {
@ -715,10 +762,13 @@ function _wpgpxmaps(params)
for (i=0; i<valLen; i++) for (i=0; i<valLen; i++)
{ {
var c = graphCad[i]; if (graphDist[i] != null)
if (c==0) {
c = null; var c = graphCad[i];
cadData.push([graphDist[i],c]); if (c==0)
c = null;
cadData.push([graphDist[i],c]);
}
} }
var yaxe = { var yaxe = {

View File

@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
Tags: maps, gpx, gps, graph, chart, google maps, highcharts, track, garmin, image, nextgen-gallery, nextgen, exif, OpenStreetMap, OpenCycleMap, Hike&Bike, heart rate, heartrate, cadence Tags: maps, gpx, gps, graph, chart, google maps, highcharts, track, garmin, image, nextgen-gallery, nextgen, exif, OpenStreetMap, OpenCycleMap, Hike&Bike, heart rate, heartrate, cadence
Requires at least: 2.0.0 Requires at least: 2.0.0
Tested up to: 3.4 Tested up to: 3.4
Stable tag: 1.1.29 Stable tag: 1.1.30
License: GPLv2 or later License: GPLv2 or later
Draws a gpx track with altitude graph. You can also display your nextgen gallery images in the map. Draws a gpx track with altitude graph. You can also display your nextgen gallery images in the map.
@ -19,7 +19,10 @@ Fully configurable:
- Custom icons - Custom icons
- Multiple language support - Multiple language support
Display your NextGen Gallery images inside the map! Check nextgen gallery EXIF support.. NextGen Gallery Integration:
Display your NextGen Gallery images inside the map!
Even if you don't have a gps camera, this plugin can retrive the image position starting from the image date and you gpx file.
- iphone/ipad/ipod Compatible - iphone/ipad/ipod Compatible
@ -117,6 +120,8 @@ The attributes are:
1. summary: Print symmary details of your GPX (default is FALSE) 1. summary: Print symmary details of your GPX (default is FALSE)
1. dtoffset: the difference (in seconds) between your gpx tool date and your camera date
= What happening if I've a very large gpx? = = What happening if I've a very large gpx? =
This plugin will print a small amout of points to speedup javascript and pageload. This plugin will print a small amout of points to speedup javascript and pageload.
@ -133,6 +138,10 @@ Yes!
1. Altitude & Speed & Hearth rate 1. Altitude & Speed & Hearth rate
== Changelog == == Changelog ==
= 1.1.30 =
* If you set Chart Height (shortcode gheight) = 0 means hide the graph
* Fix: All images should work, independent from browser cache
* Next Gen Gallery images positions derived from date. You can adjust the date with the shortcode attribute dtoffset
= 1.1.29 = = 1.1.29 =
* Decimal separator is working with all the browsers * Decimal separator is working with all the browsers
* minutes per mile and minutes per kilometer was wrong * minutes per mile and minutes per kilometer was wrong

View File

@ -3,7 +3,7 @@
Plugin Name: WP-GPX-Maps Plugin Name: WP-GPX-Maps
Plugin URI: http://www.darwinner.it/ Plugin URI: http://www.darwinner.it/
Description: Draws a gpx track with altitude graph Description: Draws a gpx track with altitude graph
Version: 1.1.29 Version: 1.1.30
Author: Bastianon Massimo Author: Bastianon Massimo
Author URI: http://www.pedemontanadelgrappa.it/ Author URI: http://www.pedemontanadelgrappa.it/
License: GPL License: GPL
@ -51,7 +51,7 @@ function enqueue_WP_GPX_Maps_scripts()
wp_enqueue_script( 'googleapis' ); wp_enqueue_script( 'googleapis' );
wp_deregister_script( 'WP-GPX-Maps' ); wp_deregister_script( 'WP-GPX-Maps' );
wp_register_script( 'WP-GPX-Maps', plugins_url('/WP-GPX-Maps.js', __FILE__), array('jquery'), "1.1.29"); wp_register_script( 'WP-GPX-Maps', plugins_url('/WP-GPX-Maps.js', __FILE__), array('jquery'), "1.1.30");
wp_enqueue_script( 'WP-GPX-Maps' ); wp_enqueue_script( 'WP-GPX-Maps' );
wp_deregister_script( 'highcharts' ); wp_deregister_script( 'highcharts' );
@ -129,17 +129,18 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
$startIcon = findValue($attr, "starticon", "wpgpxmaps_map_start_icon", ""); $startIcon = findValue($attr, "starticon", "wpgpxmaps_map_start_icon", "");
$endIcon = findValue($attr, "endicon", "wpgpxmaps_map_end_icon", ""); $endIcon = findValue($attr, "endicon", "wpgpxmaps_map_end_icon", "");
$currentIcon = findValue($attr, "currenticon", "wpgpxmaps_map_current_icon", ""); $currentIcon = findValue($attr, "currenticon", "wpgpxmaps_map_current_icon", "");
$waypointIcon = findValue($attr, "waypointicon", "wpgpxmaps_map_waypoint_icon", ""); $waypointIcon = findValue($attr, "waypointicon", "wpgpxmaps_map_waypoint_icon", "");
$ngGalleries = findValue($attr, "nggalleries", "wpgpxmaps_map_ngGalleries", ""); $ngGalleries = findValue($attr, "nggalleries", "wpgpxmaps_map_ngGalleries", "");
$ngImages = findValue($attr, "ngimages", "wpgpxmaps_map_ngImages", ""); $ngImages = findValue($attr, "ngimages", "wpgpxmaps_map_ngImages", "");
$download = findValue($attr, "download", "wpgpxmaps_download", ""); $download = findValue($attr, "download", "wpgpxmaps_download", "");
$summary = findValue($attr, "summary", "wpgpxmaps_summary", ""); $summary = findValue($attr, "summary", "wpgpxmaps_summary", "");
$dtoffset = findValue($attr, "dtoffset", "wpgpxmaps_dtoffset", 0);
$r = rand(1,5000000); $r = rand(1,5000000);
$gpxurl = $gpx; $gpxurl = $gpx;
$cacheFileName = "$gpx,$w,$mh,$mt,$gh,$showW,$showHr,$showCad,$donotreducegpx,$pointsoffset,$showSpeed,$uomspeed,$uom,v1.1.29"; $cacheFileName = "$gpx,$w,$mh,$mt,$gh,$showW,$showHr,$showCad,$donotreducegpx,$pointsoffset,$showSpeed,$uomspeed,$uom,v1.1.30";
$cacheFileName = md5($cacheFileName); $cacheFileName = md5($cacheFileName);
@ -158,6 +159,9 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
$cache_str = file_get_contents($gpxcache); $cache_str = file_get_contents($gpxcache);
$cache_obj = unserialize($cache_str); $cache_obj = unserialize($cache_str);
$points_maps = $cache_obj["points_maps"]; $points_maps = $cache_obj["points_maps"];
$points_x_time = $cache_obj["points_x_time"];
$points_x_lat = $cache_obj["points_x_lat"];
$points_x_lon = $cache_obj["points_x_lon"];
$points_graph_dist = $cache_obj["points_graph_dist"]; $points_graph_dist = $cache_obj["points_graph_dist"];
$points_graph_ele = $cache_obj["points_graph_ele"]; $points_graph_ele = $cache_obj["points_graph_ele"];
$points_graph_speed = $cache_obj["points_graph_speed"]; $points_graph_speed = $cache_obj["points_graph_speed"];
@ -172,7 +176,10 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
$tot_len = $cache_obj["tot_len"]; $tot_len = $cache_obj["tot_len"];
} catch (Exception $e) { } catch (Exception $e) {
$points_maps= ''; $points_maps = '';
$points_x_time = '';
$points_x_lat = '';
$points_x_lon = '';
$points_graph_dist = ''; $points_graph_dist = '';
$points_graph_ele = ''; $points_graph_ele = '';
$points_graph_speed = ''; $points_graph_speed = '';
@ -222,6 +229,10 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
$points_graph_cad = ''; $points_graph_cad = '';
$waypoints = ''; $waypoints = '';
$points_x_time = $points->dt;
$points_x_lat = $points->lat;
$points_x_lon = $points->lon;
$max_ele = $points->maxEle; $max_ele = $points->maxEle;
$min_ele = $points->minEle; $min_ele = $points->minEle;
$total_ele_up = $points->totalEleUp; $total_ele_up = $points->totalEleUp;
@ -232,40 +243,61 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
foreach(array_keys($points->lat) as $i) foreach(array_keys($points->lat) as $i)
{ {
$points_maps .= '['.(float)$points->lat[$i].','.(float)$points->lon[$i].'],'; $_lat = (float)$points->lat[$i];
$_lon = (float)$points->lon[$i];
$_ele = (float)$points->ele[$i]; if ( $_lat == 0 && $_lon == 0 )
$_dist = (float)$points->dist[$i]; {
$points_maps .= 'null,';
$points_graph_dist .= 'null,';
$points_graph_ele .= 'null,';
if ($uom == '1') if ($showSpeed == true)
{ $points_graph_speed .= 'null,';
// Miles and feet
$_dist *= 0.000621371192; if ($showHr == true)
$_ele *= 3.2808399; $points_graph_hr .= 'null,';
} else if ($uom == '2')
{ if ($showCad == true)
// meters / kilometers $points_graph_cad .= 'null,';
$_dist = (float)($_dist / 1000);
} }
else
$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].','; $points_maps .= '['.(float)$points->lat[$i].','.(float)$points->lon[$i].'],';
}
if ($showCad == true) $_ele = (float)$points->ele[$i];
{ $_dist = (float)$points->dist[$i];
$points_graph_cad .= $points->cad[$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_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,7 +339,8 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
} }
} }
$p="/,$/"; $p="/(,|,null,)$/";
$points_maps = preg_replace($p, "", $points_maps); $points_maps = preg_replace($p, "", $points_maps);
$points_graph_dist = preg_replace($p, "", $points_graph_dist); $points_graph_dist = preg_replace($p, "", $points_graph_dist);
@ -338,7 +371,10 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
$ngimgs_data = ''; $ngimgs_data = '';
if ( $ngGalleries != '' || $ngImages != '' ) 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 =''; $ngimgs_data ='';
foreach ($ngimgs as $img) { foreach ($ngimgs as $img) {
$data = $img['data']; $data = $img['data'];
@ -348,25 +384,37 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
} }
@file_put_contents($gpxcache, @file_put_contents($gpxcache,
serialize(array( "points_maps" => $points_maps, serialize(array( "points_maps" => $points_maps,
"points_graph_dist" => $points_graph_dist, "points_x_time" => $points_x_time,
"points_graph_ele" => $points_graph_ele, "points_x_lat" => $points_x_lat,
"points_graph_speed" => $points_graph_speed, "points_x_lon" => $points_x_lon,
"points_graph_hr" => $points_graph_hr, "points_graph_dist" => $points_graph_dist,
"points_graph_cad" => $points_graph_cad, "points_graph_ele" => $points_graph_ele,
"waypoints" => $waypoints, "points_graph_speed" => $points_graph_speed,
"max_ele" => $max_ele, "points_graph_hr" => $points_graph_hr,
"min_ele" => $min_ele, "points_graph_cad" => $points_graph_cad,
"total_ele_up" => $total_ele_up, "waypoints" => $waypoints,
"total_ele_down" => $total_ele_down, "max_ele" => $max_ele,
"avg_speed" => $avg_speed, "min_ele" => $min_ele,
"tot_len" => $tot_len "total_ele_up" => $total_ele_up,
"total_ele_down" => $total_ele_down,
"avg_speed" => $avg_speed,
"tot_len" => $tot_len
) )
), ),
LOCK_EX); LOCK_EX);
@chmod($gpxcache,0755); @chmod($gpxcache,0755);
if ($gh == "0" || $gh == "0px")
{
$points_graph_dist = '';
$points_graph_ele = '';
$points_graph_speed = '';
$points_graph_hr = '';
$points_graph_cad = '';
}
$output = ' $output = '
<div id="wpgpxmaps_'.$r.'" class="wpgpxmaps"> <div id="wpgpxmaps_'.$r.'" class="wpgpxmaps">
<div id="map_'.$r.'" style="width:'.$w.'; height:'.$mh.'"></div> <div id="map_'.$r.'" style="width:'.$w.'; height:'.$mh.'"></div>

View File

@ -82,7 +82,7 @@
if (file_exists($gpxPath)) if (file_exists($gpxPath))
{ {
$points = parseXml($gpxPath, $gpxOffset); $points = @parseXml($gpxPath, $gpxOffset);
} }
else else
{ {
@ -98,8 +98,9 @@
$f = round($count/200); $f = round($count/200);
if ($f>1) if ($f>1)
for($i=$count;$i>0;$i--) 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->lat[$i]);
unset($points->lon[$i]); unset($points->lon[$i]);
unset($points->ele[$i]); unset($points->ele[$i]);
@ -118,6 +119,7 @@
$points = null; $points = null;
$points->dt = array();
$points->lat = array(); $points->lat = array();
$points->lon = array(); $points->lon = array();
$points->ele = array(); $points->ele = array();
@ -139,135 +141,164 @@
$gpx->registerXPathNamespace('10', 'http://www.topografix.com/GPX/1/0'); $gpx->registerXPathNamespace('10', 'http://www.topografix.com/GPX/1/0');
$gpx->registerXPathNamespace('11', 'http://www.topografix.com/GPX/1/1'); $gpx->registerXPathNamespace('11', 'http://www.topografix.com/GPX/1/1');
$gpx->registerXPathNamespace('gpxx', 'http://www.garmin.com/xmlschemas/GpxExtensions/v3');
$gpx->registerXPathNamespace('gpxtpx', 'http://www.garmin.com/xmlschemas/TrackPointExtension/v1'); $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 ) if ( count($nodes) > 0 )
{ {
$lastLat = 0; foreach($nodes as $_trk)
$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;
if (isset($trkpt->extensions)) $trk = simplexml_load_string($_trk->asXML());
$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');
$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)
{ {
$_hr = @$trkpt->extensions->xpath('gpxtpx:TrackPointExtension/gpxtpx:hr/text()');
if ($_hr) $lat = $trkpt['lat'];
$lon = $trkpt['lon'];
$ele = $trkpt->ele;
$time = $trkpt->time;
$speed = (float)$trkpt->speed;
$hr = 0;
$cad = 0;
if (isset($trkpt->extensions))
{ {
foreach ($_hr as $node) { $_hr = @$trkpt->extensions->xpath('gpxtpx:TrackPointExtension/gpxtpx:hr/text()');
$hr = (float)$node; if ($_hr)
{
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;
}
} }
} }
$_cad = @$trkpt->extensions->xpath('gpxtpx:TrackPointExtension/gpxtpx:cad/text()'); if ($lastLat == 0 && $lastLon == 0)
if ($_cad)
{ {
foreach ($_cad as $node) { //Base Case
$cad = (float)$node;
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
{
//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 ;
} }
} }
}
if ($lastLat == 0 && $lastLon == 0)
{
//Base Case
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; $lastLat=$lat;
$lastLon=$lon; $lastLon=$lon;
$lastEle=$ele; $lastEle=$ele;
$lastTime=$time; $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; 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);
if ($speed == 0) unset($trkpts);
{
$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->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;
} }
unset($nodes); unset($nodes);
try { try {
@ -281,6 +312,9 @@
else else
{ {
// gpx garmin case
$gpx->registerXPathNamespace('gpxx', 'http://www.garmin.com/xmlschemas/GpxExtensions/v3');
$nodes = $gpx->xpath('//gpxx:rpt'); $nodes = $gpx->xpath('//gpxx:rpt');
if ( count($nodes) > 0 ) if ( count($nodes) > 0 )
@ -342,9 +376,76 @@
} }
else 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); unset($gpx);
return $points; return $points;
} }

View File

@ -7,7 +7,7 @@
return is_plugin_active("nextgen-gallery/nggallery.php"); return is_plugin_active("nextgen-gallery/nggallery.php");
} }
function getNGGalleryImages($ngGalleries, $ngImages, &$error) function getNGGalleryImages($ngGalleries, $ngImages, $dt, $lat, $lon, $dtoffset, &$error)
{ {
$result = array(); $result = array();
@ -16,7 +16,6 @@
if (!isNGGalleryActive()) if (!isNGGalleryActive())
return ''; return '';
try { try {
$pictures = array(); $pictures = array();
@ -26,6 +25,7 @@
foreach ($imgids as $i) { foreach ($imgids as $i) {
array_push($pictures, nggdb::find_image($i)); array_push($pictures, nggdb::find_image($i));
} }
foreach ($pictures as $p) { foreach ($pictures as $p) {
$item = array(); $item = array();
$item["data"] = $p->thumbHTML; $item["data"] = $p->thumbHTML;
@ -40,6 +40,17 @@
{ {
$result[] = $item; $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 else
@ -55,6 +66,19 @@
return $result; 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) function getExifGps($exifCoord, $hemi)
{ {
$degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0; $degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;