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)
{
@ -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<seriesLen;i++)
marker.setPosition(event.latLng);
marker.setTitle(lng.currentPosition);
if (hchart)
{
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.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; i<valLen; i++)
{
eleData.push([graphDist[i],graphEle[i]]);
if (graphDist[i] != null)
eleData.push([graphDist[i],graphEle[i]]);
}
var yaxe = {
@ -628,7 +671,8 @@ function _wpgpxmaps(params)
for (i=0; i<valLen; i++)
{
speedData.push([graphDist[i],graphSpeed[i]]);
if (graphDist[i] != null)
speedData.push([graphDist[i],graphSpeed[i]]);
}
var yaxe = {
@ -676,10 +720,13 @@ function _wpgpxmaps(params)
for (i=0; i<valLen; i++)
{
var c = graphHr[i];
if (c==0)
c = null;
hrData.push([graphDist[i],c]);
if (graphDist[i] != null)
{
var c = graphHr[i];
if (c==0)
c = null;
hrData.push([graphDist[i],c]);
}
}
var yaxe = {
@ -715,10 +762,13 @@ function _wpgpxmaps(params)
for (i=0; i<valLen; i++)
{
var c = graphCad[i];
if (c==0)
c = null;
cadData.push([graphDist[i],c]);
if (graphDist[i] != null)
{
var c = graphCad[i];
if (c==0)
c = null;
cadData.push([graphDist[i],c]);
}
}
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
Requires at least: 2.0.0
Tested up to: 3.4
Stable tag: 1.1.29
Stable tag: 1.1.30
License: GPLv2 or later
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
- 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
@ -117,6 +120,8 @@ The attributes are:
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? =
This plugin will print a small amout of points to speedup javascript and pageload.
@ -133,6 +138,10 @@ Yes!
1. Altitude & Speed & Hearth rate
== 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 =
* Decimal separator is working with all the browsers
* minutes per mile and minutes per kilometer was wrong

View File

@ -3,7 +3,7 @@
Plugin Name: WP-GPX-Maps
Plugin URI: http://www.darwinner.it/
Description: Draws a gpx track with altitude graph
Version: 1.1.29
Version: 1.1.30
Author: Bastianon Massimo
Author URI: http://www.pedemontanadelgrappa.it/
License: GPL
@ -51,7 +51,7 @@ function enqueue_WP_GPX_Maps_scripts()
wp_enqueue_script( 'googleapis' );
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_deregister_script( 'highcharts' );
@ -129,17 +129,18 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
$startIcon = findValue($attr, "starticon", "wpgpxmaps_map_start_icon", "");
$endIcon = findValue($attr, "endicon", "wpgpxmaps_map_end_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", "");
$ngImages = findValue($attr, "ngimages", "wpgpxmaps_map_ngImages", "");
$download = findValue($attr, "download", "wpgpxmaps_download", "");
$summary = findValue($attr, "summary", "wpgpxmaps_summary", "");
$download = findValue($attr, "download", "wpgpxmaps_download", "");
$summary = findValue($attr, "summary", "wpgpxmaps_summary", "");
$dtoffset = findValue($attr, "dtoffset", "wpgpxmaps_dtoffset", 0);
$r = rand(1,5000000);
$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);
@ -158,6 +159,9 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
$cache_str = file_get_contents($gpxcache);
$cache_obj = unserialize($cache_str);
$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_ele = $cache_obj["points_graph_ele"];
$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"];
} catch (Exception $e) {
$points_maps= '';
$points_maps = '';
$points_x_time = '';
$points_x_lat = '';
$points_x_lon = '';
$points_graph_dist = '';
$points_graph_ele = '';
$points_graph_speed = '';
@ -199,7 +206,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
if ($isGpxUrl == true)
{
$gpx = downloadRemoteFile($gpx);
$gpx = downloadRemoteFile($gpx);
}
else
{
@ -221,6 +228,10 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
$points_graph_hr = '';
$points_graph_cad = '';
$waypoints = '';
$points_x_time = $points->dt;
$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 = '
<div id="wpgpxmaps_'.$r.'" class="wpgpxmaps">
<div id="map_'.$r.'" style="width:'.$w.'; height:'.$mh.'"></div>

View File

@ -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;
}

View File

@ -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;