From 410253dd4ac4285c007bce59575cbdccf0510f8a Mon Sep 17 00:00:00 2001 From: bastianonm Date: Fri, 14 Mar 2014 13:38:36 +0000 Subject: [PATCH] * Speed improvement * Rewritten js classes * Added Temperature chart * Added HTML5 Gps position (you can now follow the gpx with your mobile phone/tablet/pc) --- WP-GPX-Maps.js | 2134 ++++++++++++++++---------------- readme.txt | 16 +- wp-gpx-maps.php | 128 +- wp-gpx-maps_admin_settings.php | 56 +- wp-gpx-maps_utils.php | 41 +- 5 files changed, 1305 insertions(+), 1070 deletions(-) diff --git a/WP-GPX-Maps.js b/WP-GPX-Maps.js index 8b772f9..a7d5890 100644 --- a/WP-GPX-Maps.js +++ b/WP-GPX-Maps.js @@ -1,44 +1,16 @@ /* - - WP-GPX-Maps - +Plugin Name: WP-GPX-Maps +Plugin URI: http://www.devfarm.it/ +Description: Draws a gpx track with altitude graph +Version: 1.3.0 +Author: Bastianon Massimo +Author URI: http://www.pedemontanadelgrappa.it/ */ -var t; -var funqueue = []; -var infowindow; -var mapLoading = false; -var CustomMarker; +(function ( $ ) { -var wrapFunction = function(fn, context, params) { - return function() { - fn.apply(context, params); - }; -} - -function wpgpxmaps(params) -{ - funqueue.push( wrapFunction(_wpgpxmaps, this, [params])); - unqueue(); -} - -function unqueue() -{ - if (google == undefined || google.maps == undefined || Highcharts == undefined) - { - t = setTimeout("unqueue()",200); - } - else - { - setup(); - while (funqueue.length > 0) { - (funqueue.shift())(); - } - } -} - -function setup() -{ + var infowindow; + var CustomMarker; CustomMarker = function( map, latlng, src, img_w, img_h) { this.latlng_ = latlng; @@ -114,1071 +86,1163 @@ function setup() this.img_ = null; } }; + + $.fn.wpgpxmaps = function( params ) { -} - -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) -{ - - var targetId = params.targetId; - var mapType = params.mapType; - var mapData = params.mapData; - var graphDist = params.graphDist; - var graphEle = params.graphEle; - var graphSpeed = params.graphSpeed; - var graphHr = params.graphHr; - var graphCad = params.graphCad; - var graphGrade = params.graphGrade; - var waypoints = params.waypoints; - var unit = params.unit; - var unitspeed = params.unitspeed; - var color1 = params.color1; - var color2 = params.color2; - var color3 = params.color3; - var color4 = params.color4; - var color5 = params.color5; - var color6 = params.color6; - var chartFrom1 = params.chartFrom1; - var chartTo1 = params.chartTo1; - var chartFrom2 = params.chartFrom2; - var chartTo2 = params.chartTo2; - var startIcon = params.startIcon; - var waypointIcon = params.waypointIcon; - var endIcon = params.endIcon; - var currentIcon = params.currentIcon; - var zoomOnScrollWheel = params.zoomOnScrollWheel; - var lng = params.langs; - var pluginUrl = params.pluginUrl; - - // Unit of measure settings - var l_s; - var l_x; - var l_y; - var l_grade = { suf : "%", dec : 1 }; - var l_hr = { suf : "", dec : 0 }; - var l_cad = { suf : "", dec : 0 }; - - var el = document.getElementById("wpgpxmaps_" + targetId); - var el_map = document.getElementById("map_" + targetId); - var el_chart = document.getElementById("chart_" + targetId); - var el_report = document.getElementById("report_" + targetId); - - var mapWidth = el_map.style.width; - - var mapTypeIds = []; - for(var type in google.maps.MapTypeId) { - mapTypeIds.push(google.maps.MapTypeId[type]); - } - mapTypeIds.push("OSM1"); - mapTypeIds.push("OSM2"); - mapTypeIds.push("OSM3"); - mapTypeIds.push("OSM4"); - mapTypeIds.push("OSM5"); - mapTypeIds.push("OSM6"); - - var ngImageMarkers = []; - - 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;} - case 'OSM1': { mapType = "OSM1"; break;} - case 'OSM2': { mapType = "OSM2"; break;} - case 'OSM3': { mapType = "OSM3"; break;} - case 'OSM4': { mapType = "OSM4"; break;} - case 'OSM5': { mapType = "OSM5"; break;} - case 'OSM6': { mapType = "OSM6"; break;} - default: { mapType = google.maps.MapTypeId.HYBRID; break;} - } - - var map = new google.maps.Map(el_map, { - mapTypeId: mapType, - scrollwheel: (zoomOnScrollWheel == 'true'), - mapTypeControlOptions: { - style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, - mapTypeIds: mapTypeIds + var targetId = params.targetId; + var mapType = params.mapType; + var mapData = params.mapData; + var graphDist = params.graphDist; + var graphEle = params.graphEle; + var graphSpeed = params.graphSpeed; + var graphHr = params.graphHr; + var graphAtemp = params.graphAtemp; + var graphCad = params.graphCad; + var graphGrade = params.graphGrade; + var waypoints = params.waypoints; + var unit = params.unit; + var unitspeed = params.unitspeed; + var color1 = params.color1; + var color2 = params.color2; + var color3 = params.color3; + var color4 = params.color4; + var color5 = params.color5; + var color6 = params.color6; + var color7 = params.color7; + var chartFrom1 = params.chartFrom1; + var chartTo1 = params.chartTo1; + var chartFrom2 = params.chartFrom2; + var chartTo2 = params.chartTo2; + var startIcon = params.startIcon; + var waypointIcon = params.waypointIcon; + var endIcon = params.endIcon; + var currentIcon = params.currentIcon; + var zoomOnScrollWheel = params.zoomOnScrollWheel; + var lng = params.langs; + var pluginUrl = params.pluginUrl; + var usegpsposition = params.usegpsposition; + var currentpositioncon= params.currentpositioncon; + + // Unit of measure settings + var l_s; + var l_x; + var l_y; + var l_grade = { suf : "%", dec : 1 }; + var l_hr = { suf : "", dec : 0 }; + var l_cad = { suf : "", dec : 0 }; + + var el = document.getElementById("wpgpxmaps_" + targetId); + var el_map = document.getElementById("map_" + targetId); + var el_chart = document.getElementById("chart_" + targetId); + var el_report = document.getElementById("report_" + targetId); + + var mapWidth = el_map.style.width; + + var mapTypeIds = []; + for(var type in google.maps.MapTypeId) { + mapTypeIds.push(google.maps.MapTypeId[type]); } - }); - - map.mapTypes.set("OSM1", new google.maps.ImageMapType({ - getTileUrl: function(coord, zoom) { - return "http://tile.openstreetmap.org/" + zoom + "/" + coord.x + "/" + coord.y + ".png"; - }, - tileSize: new google.maps.Size(256, 256), - name: "OSM", - alt : "Open Street Map", - maxZoom: 18 - })); - - map.mapTypes.set("OSM2", new google.maps.ImageMapType({ - getTileUrl: function(coord, zoom) { - return "http://a.tile.opencyclemap.org/cycle/" + zoom + "/" + coord.x + "/" + coord.y + ".png"; - }, - tileSize: new google.maps.Size(256, 256), - name: "OCM", - alt : "Open Cycle Map", - maxZoom: 18 - })); - - map.mapTypes.set("OSM4", new google.maps.ImageMapType({ - getTileUrl: function(coord, zoom) { - return "http://a.tile2.opencyclemap.org/transport/" + zoom + "/" + coord.x + "/" + coord.y + ".png"; - }, - tileSize: new google.maps.Size(256, 256), - name: "OCM-Tran", - alt : "Open Cycle Map - Transport", - maxZoom: 18 - })); - - map.mapTypes.set("OSM5", new google.maps.ImageMapType({ - getTileUrl: function(coord, zoom) { - return "http://a.tile3.opencyclemap.org/landscape/" + zoom + "/" + coord.x + "/" + coord.y + ".png"; - }, - tileSize: new google.maps.Size(256, 256), - name: "OCM-Land", - alt : "Open Cycle Map - Landscape", - maxZoom: 18 - })); - - map.mapTypes.set("OSM6", new google.maps.ImageMapType({ - getTileUrl: function(coord, zoom) { - return "http://tile2.maptoolkit.net/terrain/" + zoom + "/" + coord.x + "/" + coord.y + ".png"; - }, - tileSize: new google.maps.Size(256, 256), - name: "MTK-Terr", - alt : "MapToolKit - Terrain", - maxZoom: 18 - })); - - - // FULL SCREEN BUTTON - var controlDiv = document.createElement('div'); - controlDiv.style.padding = '5px'; - - // Set CSS for the control border - var controlUI = document.createElement('img'); - controlUI.src = pluginUrl + "/wp-gpx-maps/img/goFullScreen.png"; - controlUI.style.cursor = 'pointer'; - controlUI.title = lng.goFullScreen; - controlDiv.appendChild(controlUI); - - // Setup the click event listeners - google.maps.event.addDomListener(controlUI, 'click', function(event) { - var isFullScreen = (controlUI.isfullscreen == true); - var fullScreenCss = "position: absolute;left:0;top:0;"; - var mapDiv = map.getDiv(); - var center = map.getCenter(); + mapTypeIds.push("OSM1"); + mapTypeIds.push("OSM2"); + mapTypeIds.push("OSM3"); + mapTypeIds.push("OSM4"); + mapTypeIds.push("OSM5"); + mapTypeIds.push("OSM6"); - if (isFullScreen) + var ngImageMarkers = []; + + switch (mapType) { - map.setOptions( { scrollwheel : (zoomOnScrollWheel == 'true') } ); - jQuery(mapDiv).css("position", 'relative'). - css('top', 0). - css("width", controlUI.googleMapWidth). - css("height", controlUI.googleMapHeight). - css("z-index", ''); - google.maps.event.trigger(map, 'resize'); - map.setCenter(center); - controlUI.src = pluginUrl + "/wp-gpx-maps/img/goFullScreen.png"; - controlUI.title = lng.gofullscreen; + case 'TERRAIN': { mapType = google.maps.MapTypeId.TERRAIN; break;} + case 'SATELLITE': { mapType = google.maps.MapTypeId.SATELLITE; break;} + case 'ROADMAP': { mapType = google.maps.MapTypeId.ROADMAP; break;} + case 'OSM1': { mapType = "OSM1"; break;} + case 'OSM2': { mapType = "OSM2"; break;} + case 'OSM3': { mapType = "OSM3"; break;} + case 'OSM4': { mapType = "OSM4"; break;} + case 'OSM5': { mapType = "OSM5"; break;} + case 'OSM6': { mapType = "OSM6"; break;} + default: { mapType = google.maps.MapTypeId.HYBRID; break;} } - else - { - map.setOptions( { scrollwheel : true } ); - controlUI.googleMapWidth = jQuery(mapDiv).css('width'); - controlUI.googleMapHeight = jQuery(mapDiv).css('height'); - jQuery(mapDiv).css("position", 'fixed'). - css('top', 0). - css('left', 0). - css("width", '100%'). - css("height", '100%'). - css("z-index", '100'); - jQuery("#wpadminbar").each(function(){ - jQuery(mapDiv).css('top', jQuery(this).height()); - }); - google.maps.event.trigger(map, 'resize'); - map.setCenter(center); - controlUI.src = pluginUrl + "/wp-gpx-maps/img/exitFullFcreen.png"; - controlUI.title = lng.exitFullFcreen; - } - controlUI.isfullscreen = !isFullScreen; - return false; - }); - - controlDiv.index = 1; - map.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlDiv); - - var bounds = new google.maps.LatLngBounds(); - - // Print WayPoints - if (waypoints != '') - { - var image = new google.maps.MarkerImage('http://maps.google.com/mapfiles/ms/micons/flag.png', - new google.maps.Size(32, 32), - new google.maps.Point(0,0), - new google.maps.Point(16, 32) - ); - var shadow = new google.maps.MarkerImage('http://maps.google.com/mapfiles/ms/micons/flag.shadow.png', - new google.maps.Size(59, 32), - new google.maps.Point(0,0), - new google.maps.Point(16, 32) - ); - - if (waypointIcon!='') - { - image = new google.maps.MarkerImage(waypointIcon); - shadow = ''; - } - - for (i=0; i < waypoints.length; i++) - { - var lat= waypoints[i][0]; - var lon= waypoints[i][1]; - addWayPoint(map, image, shadow, lat, lon, waypoints[i][2], waypoints[i][3]); - bounds.extend(new google.maps.LatLng(lat, lon)); - } - } - - // Print Images - - jQuery("#ngimages_" + targetId).attr("style","display:block;position:absolute;left:-50000px"); - jQuery("#ngimages_" + targetId + " span").each(function(){ - - var imageLat = jQuery(this).attr("lat"); - var imageLon = jQuery(this).attr("lon"); - - 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(); - - imageLat = imageLat.replace(",", "."); - imageLon = imageLon.replace(",", "."); - - var p = new google.maps.LatLng(imageLat, imageLon); - bounds.extend(p); - - var mc = new CustomMarker(map, p, imageUrl, img_w, img_h ); - - ngImageMarkers.push(mc); - - 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"); + var map = new google.maps.Map(el_map, { + mapTypeId: mapType, + scrollwheel: (zoomOnScrollWheel == 'true'), + mapTypeControlOptions: { + style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, + mapTypeIds: mapTypeIds } + }); + + map.mapTypes.set("OSM1", new google.maps.ImageMapType({ + getTileUrl: function(coord, zoom) { + return "http://tile.openstreetmap.org/" + zoom + "/" + coord.x + "/" + coord.y + ".png"; + }, + tileSize: new google.maps.Size(256, 256), + name: "OSM", + alt : "Open Street Map", + maxZoom: 18 + })); + + map.mapTypes.set("OSM2", new google.maps.ImageMapType({ + getTileUrl: function(coord, zoom) { + return "http://a.tile.opencyclemap.org/cycle/" + zoom + "/" + coord.x + "/" + coord.y + ".png"; + }, + tileSize: new google.maps.Size(256, 256), + name: "OCM", + alt : "Open Cycle Map", + maxZoom: 18 + })); + + map.mapTypes.set("OSM4", new google.maps.ImageMapType({ + getTileUrl: function(coord, zoom) { + return "http://a.tile2.opencyclemap.org/transport/" + zoom + "/" + coord.x + "/" + coord.y + ".png"; + }, + tileSize: new google.maps.Size(256, 256), + name: "OCM-Tran", + alt : "Open Cycle Map - Transport", + maxZoom: 18 + })); + + map.mapTypes.set("OSM5", new google.maps.ImageMapType({ + getTileUrl: function(coord, zoom) { + return "http://a.tile3.opencyclemap.org/landscape/" + zoom + "/" + coord.x + "/" + coord.y + ".png"; + }, + tileSize: new google.maps.Size(256, 256), + name: "OCM-Land", + alt : "Open Cycle Map - Landscape", + maxZoom: 18 + })); + + map.mapTypes.set("OSM6", new google.maps.ImageMapType({ + getTileUrl: function(coord, zoom) { + return "http://tile2.maptoolkit.net/terrain/" + zoom + "/" + coord.x + "/" + coord.y + ".png"; + }, + tileSize: new google.maps.Size(256, 256), + name: "MTK-Terr", + alt : "MapToolKit - Terrain", + maxZoom: 18 + })); + + + // FULL SCREEN BUTTON + var controlDiv = document.createElement('div'); + controlDiv.style.padding = '5px'; - }); - - }); - - /* - - // Nextgen Pro Lightbox FIX - var _xx = jQuery("#ngimages_" + targetId + " .nextgen_pro_lightbox"); - if (_xx.length > 0) - { - - var rnd1 = Math.random().toString(36).substring(7); - var rnd2 = Math.random().toString(36).substring(7); - - //get first gallery without images - for (var _temp in galleries) { - var _gal = galleries[_temp]; - - if (_gal.source == "random_images" && _gal.wpgpxmaps != true ) - { - - _gal.source == "galleries"; - _gal.wpgpxmaps = true; - _transient_id = _temp.replace("gallery_","") - _gal["entity_ids"] = []; - _gal["image_ids"] = []; - _gal["gallery_ids"] = [96]; - for (var i=0;i<_xx.length;i++) - { - var __xx = jQuery(_xx[i]); - __xx.attr("data-nplmodal-gallery-id", _transient_id); - _gal["image_ids"].push(__xx.attr("data-image-id")); - } - break; - } - } - } - */ - - if ( jQuery("#ngimages_" + targetId + " span").length > 0 ) - { - // Set CSS for the control border - var controlUIhi = document.createElement('img'); - controlUIhi.src = pluginUrl + "/wp-gpx-maps/img/hideImages.png"; - controlUIhi.style.cursor = 'pointer'; - controlUIhi.title = lng.hideImages; - controlDiv.appendChild(controlUIhi); + var controlUI = document.createElement('img'); + controlUI.src = pluginUrl + "/wp-gpx-maps/img/goFullScreen.png"; + controlUI.style.cursor = 'pointer'; + controlUI.title = lng.goFullScreen; + controlDiv.appendChild(controlUI); // Setup the click event listeners - google.maps.event.addDomListener(controlUIhi, 'click', function(event) { - var isImagesHidden = (controlUIhi.isImagesHidden == true); + google.maps.event.addDomListener(controlUI, 'click', function(event) { + var isFullScreen = (controlUI.isfullscreen == true); var fullScreenCss = "position: absolute;left:0;top:0;"; var mapDiv = map.getDiv(); var center = map.getCenter(); - if (isImagesHidden) + if (isFullScreen) { - for (var i=0; i 0) + { + jQuery(this).trigger("load"); + } + + }); + + }); + + /* + + // Nextgen Pro Lightbox FIX + var _xx = jQuery("#ngimages_" + targetId + " .nextgen_pro_lightbox"); + if (_xx.length > 0) + { + + var rnd1 = Math.random().toString(36).substring(7); + var rnd2 = Math.random().toString(36).substring(7); + + //get first gallery without images + for (var _temp in galleries) { + var _gal = galleries[_temp]; + + if (_gal.source == "random_images" && _gal.wpgpxmaps != true ) + { + + _gal.source == "galleries"; + _gal.wpgpxmaps = true; + _transient_id = _temp.replace("gallery_","") + _gal["entity_ids"] = []; + _gal["image_ids"] = []; + _gal["gallery_ids"] = [96]; + for (var i=0;i<_xx.length;i++) + { + var __xx = jQuery(_xx[i]); + __xx.attr("data-nplmodal-gallery-id", _transient_id); + _gal["image_ids"].push(__xx.attr("data-image-id")); + } + break; + } + } + } + */ + + if ( jQuery("#ngimages_" + targetId + " span").length > 0 ) + { + + // Set CSS for the control border + var controlUIhi = document.createElement('img'); + controlUIhi.src = pluginUrl + "/wp-gpx-maps/img/hideImages.png"; + controlUIhi.style.cursor = 'pointer'; + controlUIhi.title = lng.hideImages; + controlDiv.appendChild(controlUIhi); + + // Setup the click event listeners + google.maps.event.addDomListener(controlUIhi, 'click', function(event) { + var isImagesHidden = (controlUIhi.isImagesHidden == true); + var fullScreenCss = "position: absolute;left:0;top:0;"; + var mapDiv = map.getDiv(); + var center = map.getCenter(); + + if (isImagesHidden) + { + for (var i=0; i 0) - tooltip.refresh(items); - } - } - }); - } - } - - map.setCenter(bounds.getCenter()); - map.fitBounds(bounds); - - var controlUIcenter = null; - var idFirstCenterChanged = true; - - google.maps.event.addListener(map, 'center_changed', function() { - - if (idFirstCenterChanged == true) - { - idFirstCenterChanged = false; - return; - } - - if (controlUIcenter == null) - { - // Set CSS for the control border - controlUIcenter = document.createElement('img'); - controlUIcenter.src = pluginUrl + "/wp-gpx-maps/img/backToCenter.png"; - controlUIcenter.style.cursor = 'pointer'; - controlUIcenter.title = lng.backToCenter; - controlDiv.appendChild(controlUIcenter); - - // Setup the click event listeners - google.maps.event.addDomListener(controlUIcenter, 'click', function(event) { - map.setCenter(bounds.getCenter()); - map.fitBounds(bounds); - controlDiv.removeChild(controlUIcenter); - controlUIcenter = null; - return false; - }); - } - - }); - - var graphh = jQuery('#hchart_' + params.targetId).css("height"); - - if (graphDist != '' && (graphEle != '' || graphSpeed != '' || graphHr != '' || graphCad != '') && graphh != "0px") - { - - var valLen = graphDist.length; - - var l_y_arr = []; - - if (unit=="1") - { - l_x = { suf : "mi", dec : 1 }; - l_y = { suf : "ft", dec : 0 }; - } - else if (unit=="2") - { - l_x = { suf : "km", dec : 1 }; - l_y = { suf : "m", dec : 0 }; - } - else if (unit=="3") - { - l_x = { suf : "NM", dec : 1 }; - l_y = { suf : "m", dec : 0 }; - } - else if (unit=="4") - { - l_x = { suf : "mi", dec : 1 }; - l_y = { suf : "m", dec : 0 }; - } - else - { - l_x = { suf : "m", dec : 0 }; - l_y = { suf : "m", dec : 0 }; - } - - var nn = 1111.1; - var _nn = nn.toLocaleString(); - var _nnLen = _nn.length; - var decPoint = _nn.substring(_nnLen - 2, _nnLen - 1); - var thousandsSep = _nn.substring(1, 2); - - if (decPoint == "1") - decPoint = "."; - if (thousandsSep == "1") - thousandsSep = ""; - - // define the options - var hoptions = { - chart: { - renderTo: 'hchart_' + params.targetId, - type: 'area', - events: { - selection: function(event) { + for (i=0; i < polylinenes.length; i++) + { - if (event.xAxis) { - - el_report.innerHTML = 'Zoom: '+ (event.xAxis[0].min).toFixed(l_x.dec) + ' ' + l_x.suf + ' -> '+ (event.xAxis[0].max).toFixed(decPoint) + ' ' + l_x.suf + '
'; - - var seriesLength = event.currentTarget.series.length; - - for (var i = 0; i < seriesLength; i++) { - - var dataX = {value: 0, count: 0}; - - var serie = event.currentTarget.series[i]; - var points = serie.points; - var min = event.xAxis[0].min, max = event.xAxis[0].max; - - for (var j = 0; j < points.length; j++) { - if (points[j].x >= min && points[j].x <= max) { - dataX.value += points[j].y; - dataX.count +=1; - } - } - - var name = serie.name; - - if (name == lng.altitude) { - el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_y.dec) + " " + l_y.suf + "
"; - } else if (name == lng.speed) { - el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_s.dec) + " " + l_s.suf + "
"; - } else if (name == lng.grade) { - el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_grade.dec) + " " + l_grade.suf + "
"; - } else if (name == lng.cadence) { - el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_cad.dec) + " " + l_cad.suf + "
"; - } else if (name == lng.heartRate) { - el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_hr.dec) + " " + l_hr.suf + "
"; - } else - { - el_report.innerHTML += serie.name + ' avg: ' + dataX.value / dataX.count + "
"; - } - - } - - el_report.innerHTML += "
" - - } else { - el_report.innerHTML = ''; - } - } - }, - zoomType: 'x' - }, - title: { - text: null - }, - xAxis: { - type: 'integer', - //gridLineWidth: 1, - //tickInterval: 1000, - labels: { - formatter: function() { - return Highcharts.numberFormat(this.value, l_x.dec,decPoint,thousandsSep) + l_x.suf; - } - } - }, - yAxis: [], - legend: { - align: 'center', - verticalAlign: 'top', - y: -5, - floating: true, - borderWidth: 0 - }, - tooltip: { - shared: true, - crosshairs: true, - formatter: function() { + google.maps.event.addListener(polylinenes[i],'mouseover',function(event){ if (marker) { - var hchart_xserie = hchart.xAxis[0].series[0].data; - for(var i=0; i
"; - for (i=0; i < this.points.length; i++) - { - tooltip += this.points[i].series.name + ": " + Highcharts.numberFormat(this.points[i].y, l_y_arr[i].dec,decPoint,thousandsSep) + l_y_arr[i].suf + "
"; - } - return tooltip; - } - }, - plotOptions: { - area: { - fillOpacity: 0.1, - connectNulls : true, - marker: { - enabled: false, - symbol: 'circle', - radius: 2, - states: { - hover: { - enabled: true + items.push(hchart.series[i].data[ci]); } + if (items.length > 0) + tooltip.refresh(items); } - } - } - }, - credits: { - enabled: false - }, - series: [] - }; - - if (graphEle != '') - { - - var eleData = []; - var myelemin = 99999; - var myelemax = -99999; - - for (i=0; i myelemax) - myelemax = _graphEle; - if (_graphEle < myelemin) - myelemin = _graphEle; - } - } - - var yaxe = { - title: { text: null }, - labels: { - align: 'left', - formatter: function() { - return Highcharts.numberFormat(this.value, l_y.dec,decPoint,thousandsSep) + l_y.suf; } - } + }); } - - if ( chartFrom1 != '' ) - { - yaxe.min = chartFrom1; - yaxe.startOnTick = false; - } - else { - yaxe.min = myelemin; - } - - if ( chartTo1 != '' ) - { - yaxe.max = chartTo1; - yaxe.endOnTick = false; - } - else { - yaxe.max = myelemax; - } - - hoptions.yAxis.push(yaxe); - hoptions.series.push({ - name: lng.altitude, - lineWidth: 1, - marker: { radius: 0 }, - data : eleData, - color: color2, - yAxis: hoptions.series.length - }); - - l_y_arr.push(l_y); } - if (graphSpeed != '') + map.setCenter(bounds.getCenter()); + map.fitBounds(bounds); + + var controlUIcenter = null; + var idFirstCenterChanged = true; + + google.maps.event.addListener(map, 'center_changed', function() { + + if (idFirstCenterChanged == true) + { + idFirstCenterChanged = false; + return; + } + + if (controlUIcenter == null) + { + // Set CSS for the control border + controlUIcenter = document.createElement('img'); + controlUIcenter.src = pluginUrl + "/wp-gpx-maps/img/backToCenter.png"; + controlUIcenter.style.cursor = 'pointer'; + controlUIcenter.title = lng.backToCenter; + controlDiv.appendChild(controlUIcenter); + + // Setup the click event listeners + google.maps.event.addDomListener(controlUIcenter, 'click', function(event) { + map.setCenter(bounds.getCenter()); + map.fitBounds(bounds); + controlDiv.removeChild(controlUIcenter); + controlUIcenter = null; + return false; + }); + } + + }); + + var graphh = jQuery('#hchart_' + params.targetId).css("height"); + + if (graphDist != '' && (graphEle != '' || graphSpeed != '' || graphHr != '' || graphAtemp != '' || graphCad != '') && graphh != "0px") { + + var valLen = graphDist.length; + + var l_y_arr = []; - if (unitspeed == '5') // knots + if (unit=="1") { - l_s = { suf : "knots", dec : 2 }; - } - else if (unitspeed == '4') // min/miles + l_x = { suf : "mi", dec : 1 }; + l_y = { suf : "ft", dec : 0 }; + } + else if (unit=="2") { - l_s = { suf : "min/mi", dec : 2 }; - } - else if (unitspeed == '3') // min/km + l_x = { suf : "km", dec : 1 }; + l_y = { suf : "m", dec : 0 }; + } + else if (unit=="3") { - l_s = { suf : "min/km", dec : 2 }; - } - else if (unitspeed == '2') // miles/h + l_x = { suf : "NM", dec : 1 }; + l_y = { suf : "m", dec : 0 }; + } + else if (unit=="4") { - l_s = { suf : "mi/h", dec : 0 }; - } - else if (unitspeed == '1') // km/h - { - l_s = { suf : "km/h", dec : 0 }; - } + l_x = { suf : "mi", dec : 1 }; + l_y = { suf : "m", dec : 0 }; + } else { - l_s = { suf : "m/s", dec : 0 }; + l_x = { suf : "m", dec : 0 }; + l_y = { suf : "m", dec : 0 }; } - var speedData = []; - - for (i=0; i '+ (event.xAxis[0].max).toFixed(decPoint) + ' ' + l_x.suf + '
'; + + var seriesLength = event.currentTarget.series.length; + + for (var i = 0; i < seriesLength; i++) { + + var dataX = {value: 0, count: 0}; + + var serie = event.currentTarget.series[i]; + var points = serie.points; + var min = event.xAxis[0].min, max = event.xAxis[0].max; + + for (var j = 0; j < points.length; j++) { + if (points[j].x >= min && points[j].x <= max) { + dataX.value += points[j].y; + dataX.count +=1; + } + } + + var name = serie.name; + + if (name == lng.altitude) { + el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_y.dec) + " " + l_y.suf + "
"; + } else if (name == lng.speed) { + el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_s.dec) + " " + l_s.suf + "
"; + } else if (name == lng.grade) { + el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_grade.dec) + " " + l_grade.suf + "
"; + } else if (name == lng.cadence) { + el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_cad.dec) + " " + l_cad.suf + "
"; + } else if (name == lng.heartRate) { + el_report.innerHTML += name + ' avg: ' + (dataX.value / dataX.count).toFixed(l_hr.dec) + " " + l_hr.suf + "
"; + } else + { + el_report.innerHTML += serie.name + ' avg: ' + dataX.value / dataX.count + "
"; + } + + } + + el_report.innerHTML += "
" + + } else { + el_report.innerHTML = ''; + } + } + }, + zoomType: 'x' + }, + title: { + text: null + }, + xAxis: { + type: 'integer', + //gridLineWidth: 1, + //tickInterval: 1000, + labels: { + formatter: function() { + return Highcharts.numberFormat(this.value, l_x.dec,decPoint,thousandsSep) + l_x.suf; + } } }, - opposite: true + yAxis: [], + legend: { + align: 'center', + verticalAlign: 'top', + y: -5, + floating: true, + borderWidth: 0 + }, + tooltip: { + shared: true, + crosshairs: true, + formatter: function() { + if (marker) + { + var hchart_xserie = hchart.xAxis[0].series[0].data; + for(var i=0; i
"; + for (i=0; i < this.points.length; i++) + { + tooltip += this.points[i].series.name + ": " + Highcharts.numberFormat(this.points[i].y, l_y_arr[i].dec,decPoint,thousandsSep) + l_y_arr[i].suf + "
"; + } + return tooltip; + } + }, + plotOptions: { + area: { + fillOpacity: 0.1, + connectNulls : true, + marker: { + enabled: false, + symbol: 'circle', + radius: 2, + states: { + hover: { + enabled: true + } + } + } + } + }, + credits: { + enabled: false + }, + series: [] + }; + + if (graphEle != '') + { + + var eleData = []; + var myelemin = 99999; + var myelemax = -99999; + + for (i=0; i myelemax) + myelemax = _graphEle; + if (_graphEle < myelemin) + myelemin = _graphEle; + } + } + + var yaxe = { + title: { text: null }, + labels: { + align: 'left', + formatter: function() { + return Highcharts.numberFormat(this.value, l_y.dec,decPoint,thousandsSep) + l_y.suf; + } + } + } + + if ( chartFrom1 != '' ) + { + yaxe.min = chartFrom1; + yaxe.startOnTick = false; + } + else { + yaxe.min = myelemin; + } + + if ( chartTo1 != '' ) + { + yaxe.max = chartTo1; + yaxe.endOnTick = false; + } + else { + yaxe.max = myelemax; + } + + hoptions.yAxis.push(yaxe); + hoptions.series.push({ + name: lng.altitude, + lineWidth: 1, + marker: { radius: 0 }, + data : eleData, + color: color2, + yAxis: hoptions.series.length + }); + + l_y_arr.push(l_y); } + + if (graphSpeed != '') + { + + if (unitspeed == '5') // knots + { + l_s = { suf : "knots", dec : 2 }; + } + else if (unitspeed == '4') // min/miles + { + l_s = { suf : "min/mi", dec : 2 }; + } + else if (unitspeed == '3') // min/km + { + l_s = { suf : "min/km", dec : 2 }; + } + else if (unitspeed == '2') // miles/h + { + l_s = { suf : "mi/h", dec : 0 }; + } + else if (unitspeed == '1') // km/h + { + l_s = { suf : "km/h", dec : 0 }; + } + else + { + l_s = { suf : "m/s", dec : 0 }; + } + + var speedData = []; + + for (i=0; i"; + } + else + { + cnt = "
" + title + "
" + unescape(descr) + "
"; + } + infowindow = new google.maps.InfoWindow({ content: cnt}); + infowindow.open(map,m); + }); + } + + function getItemFromArray(arr,index) + { + try + { + return arr[index]; + } + catch(e) + { + return [0,0]; + } + } + + + function getClosestIndex(points,lat,lon) + { + var dd=10000; + var ii=0; + for (i=0; i < points.length; i++) + { + if (points[i]==null) + continue; + + var d = dist(points[i][0], points[i][1], lat, lon); + if ( d < dd ) + { + ii = i; + dd = d; + } + } + return ii; + } + + function getClosestImage(lat,lon,targetId) + { + var dd=10000; + var img; + var divImages = document.getElementById("ngimages_"+targetId); + var img_spans = divImages.getElementsByTagName("span"); + for (var i = 0; i < img_spans.length; i++) { + var imageLat = img_spans[i].getAttribute("lat"); + var imageLon = img_spans[i].getAttribute("lon"); - if ( chartFrom2 != '' ) - { - yaxe.min = chartFrom2; - yaxe.startOnTick = false; - } + imageLat = imageLat.replace(",", "."); + imageLon = imageLon.replace(",", "."); - if ( chartTo2 != '' ) + var d = dist(imageLat, imageLon, lat, lon); + if ( d < dd ) { - yaxe.max = chartTo2; - yaxe.endOnTick = false; - } - - hoptions.yAxis.push(yaxe); - hoptions.series.push({ - name: lng.speed, - lineWidth: 1, - marker: { radius: 0 }, - data : speedData, - color: color3, - yAxis: hoptions.series.length - }); - - l_y_arr.push(l_s); + img = img_spans[i]; + dd = d; + } } - - if (graphHr != '') - { - - var hrData = []; - - for (i=0; i"; - } - else - { - cnt = "
" + title + "
" + unescape(descr) + "
"; - } - infowindow = new google.maps.InfoWindow({ content: cnt}); - infowindow.open(map,m); - }); -} - -function getItemFromArray(arr,index) -{ - try - { - return arr[index]; - } - catch(e) - { - return [0,0]; - } -} - - -function getClosestIndex(points,lat,lon) -{ - var dd=10000; - var ii=0; - for (i=0; i < points.length; i++) - { - if (points[i]==null) - continue; - - var d = dist(points[i][0], points[i][1], lat, lon); - if ( d < dd ) - { - ii = i; - dd = d; - } - } - return ii; -} - -function getClosestImage(lat,lon,targetId) -{ - var dd=10000; - var img; - var divImages = document.getElementById("ngimages_"+targetId); - var img_spans = divImages.getElementsByTagName("span"); - for (var i = 0; i < img_spans.length; i++) { - var imageLat = img_spans[i].getAttribute("lat"); - var imageLon = img_spans[i].getAttribute("lon"); - - imageLat = imageLat.replace(",", "."); - imageLon = imageLon.replace(",", "."); - - var d = dist(imageLat, imageLon, lat, lon); - if ( d < dd ) - { - img = img_spans[i]; - dd = d; - } - } - return img; -} - -function isNumeric(input){ - var RE = /^-{0,1}\d*\.{0,1}\d+$/; - return (RE.test(input)); -} - -function dist(lat1,lon1,lat2,lon2) -{ - // mathematically not correct but fast - var dLat = (lat2-lat1); - var dLon = (lon2-lon1); - return Math.sqrt(dLat * dLat + dLon * dLon); -} \ No newline at end of file +}( jQuery )); \ No newline at end of file diff --git a/readme.txt b/readme.txt index 65dac20..54d6669 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i Tags: maps, gpx, gps, graph, chart, google maps, 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.8 -Stable tag: 1.2.6 +Stable tag: 1.3.0 Draws a gpx track with altitude graph. You can also display your nextgen gallery images in the map. @@ -14,11 +14,18 @@ Draws a gpx track with altitude graph. You can also display your nextgen gallery This plugin has, as input, the GPX file with the track you've made and as output it shows the map of the track and an interactive altitude graph (where available). Fully configurable: - - Custom colors - Custom icons - Multiple language support +Supported charts: +- Altitude +- Speed +- Heart Rate +- Temperature +- Cadence +- Grade + NextGen Gallery Integration: Display your NextGen Gallery images inside the map! @@ -180,6 +187,11 @@ Yes! 1. Altitude & Speed & Hearth rate == Changelog == += 1.3.0 = +* Speed improvement +* Rewritten js classes +* Added Temperature chart +* Added HTML5 Gps position (you can now follow the gpx with your mobile phone/tablet/pc) = 1.2.6 = * Speed improvement = 1.2.5 = diff --git a/wp-gpx-maps.php b/wp-gpx-maps.php index 6e83002..6100852 100644 --- a/wp-gpx-maps.php +++ b/wp-gpx-maps.php @@ -3,7 +3,7 @@ Plugin Name: WP-GPX-Maps Plugin URI: http://www.devfarm.it/ Description: Draws a gpx track with altitude graph -Version: 1.2.6 +Version: 1.3.0 Author: Bastianon Massimo Author URI: http://www.pedemontanadelgrappa.it/ */ @@ -14,6 +14,7 @@ include 'wp-gpx-maps_utils.php'; include 'wp-gpx-maps_admin.php'; add_shortcode('sgpx','handle_WP_GPX_Maps_Shortcodes'); +add_shortcode('sgpxf','handle_WP_GPX_Maps_folder_Shortcodes'); register_activation_hook(__FILE__,'WP_GPX_Maps_install'); register_deactivation_hook( __FILE__, 'WP_GPX_Maps_remove'); add_filter('plugin_action_links', 'WP_GPX_Maps_action_links', 10, 2); @@ -59,7 +60,7 @@ function enqueue_WP_GPX_Maps_scripts() wp_enqueue_script( 'highcharts' ); wp_deregister_script( 'WP-GPX-Maps' ); - wp_register_script( 'WP-GPX-Maps', plugins_url('/WP-GPX-Maps.js', __FILE__), array('jquery','googlemaps','highcharts'), "1.2.3"); + wp_register_script( 'WP-GPX-Maps', plugins_url('/WP-GPX-Maps.js', __FILE__), array('jquery','googlemaps','highcharts'), "1.3.0"); wp_enqueue_script( 'WP-GPX-Maps' ); } @@ -100,6 +101,84 @@ function findValue($attr, $attributeName, $optionName, $defaultValue) return $val; } +function handle_WP_GPX_Maps_folder_Shortcodes($attr, $content=''){ + + $folder = findValue($attr, "folder", "", ""); + $pointsoffset = findValue($attr, "pointsoffset", "wpgpxmaps_pointsoffset", 10); + $distanceType = findValue($attr, "distanceType", "wpgpxmaps_distance_type", 0); + $donotreducegpx = findValue($attr, "donotreducegpx", "wpgpxmaps_donotreducegpx", false); + $uom = findValue($attr, "uom", "wpgpxmaps_unit_of_measure", "0"); + + // fix folder path + $sitePath = sitePath(); + $folder = trim($folder); + $folder = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $folder); + $folder = $sitePath . $folder; + + $files = scandir($folder); + + foreach($files as $file) { + + if (substr($file, - 4) == ".gpx" ) { + + $gpx = $folder . DIRECTORY_SEPARATOR . $file; + $points = getPoints($gpx, $pointsoffset, $donotreducegpx, $distanceType); + + $points_maps = ''; + $points_graph_dist = ''; + $points_graph_ele = ''; + + if (is_array ($points_x_lat)) + foreach(array_keys($points_x_lat) as $i) { + + $_lat = (float)$points_x_lat[$i]; + $_lon = (float)$points_x_lon[$i]; + + if ( $_lat == 0 && $_lon == 0 ) + { + $points_maps .= 'null,'; + $points_graph_dist .= 'null,'; + $points_graph_ele .= 'null,'; + + } + else { + $points_maps .= '['.number_format((float)$points_x_lat[$i], 7 , '.' , '' ).','.number_format((float)$points_x_lon[$i], 7 , '.' , '' ).'],'; + + $_ele = (float)$points->ele[$i]; + $_dist = (float)$points->dist[$i]; + + if ($uom == '1') + { + // Miles and feet + $_dist *= 0.000621371192; + $_ele *= 3.2808399; + } else if ($uom == '2') + { + // meters / kilometers + $_dist = (float)($_dist / 1000); + } else if ($uom == '3') + { + // meters / kilometers / nautical miles + $_dist = (float)($_dist / 1000 / 1.852); + } else if ($uom == '4') + { + // meters / miles + $_dist *= 0.000621371192; + } + + $points_graph_dist .= number_format ( $_dist , 2 , '.' , '' ).','; + $points_graph_ele .= number_format ( $_ele , 2 , '.' , '' ).','; + + } + } + + print_r($points); + + } + } +} + + function handle_WP_GPX_Maps_Shortcodes($attr, $content='') { @@ -112,6 +191,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $gh = findValue($attr, "gheight", "wpgpxmaps_graph_height", "200px"); $showCad = findValue($attr, "showcad", "wpgpxmaps_show_cadence", false); $showHr = findValue($attr, "showhr", "wpgpxmaps_show_hr", false); + $showAtemp = findValue($attr, "showatemp", "wpgpxmaps_show_atemp", false); $showW = findValue($attr, "waypoints", "wpgpxmaps_show_waypoint", false); $showEle = findValue($attr, "showele", "wpgpxmaps_show_elevation", "true"); $showSpeed = findValue($attr, "showspeed", "wpgpxmaps_show_speed", false); @@ -125,8 +205,9 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $color_graph = findValue($attr, "glinecolor", "wpgpxmaps_graph_line_color", "#3366cc"); $color_graph_speed = findValue($attr, "glinecolorspeed", "wpgpxmaps_graph_line_color_speed", "#ff0000"); $color_graph_hr = findValue($attr, "glinecolorhr", "wpgpxmaps_graph_line_color_hr", "#ff77bd"); + $color_graph_atemp = findValue($attr, "glinecoloratemp", "wpgpxmaps_graph_line_color_atemp", "#ff77bd"); $color_graph_cad = findValue($attr, "glinecolorcad", "wpgpxmaps_graph_line_color_cad", "#beecff"); - $color_graph_grade = findValue($attr, "glinecolorgrade", "wpgpxmaps_graph_line_color_grade", "#beecff"); + $color_graph_grade = findValue($attr, "glinecolorgrade", "wpgpxmaps_graph_line_color_grade", "#beecff"); $chartFrom1 = findValue($attr, "chartfrom1", "wpgpxmaps_graph_offset_from1", ""); $chartTo1 = findValue($attr, "chartto1", "wpgpxmaps_graph_offset_to1", ""); @@ -140,7 +221,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $ngImages = findValue($attr, "ngimages", "wpgpxmaps_map_ngImages", ""); $download = findValue($attr, "download", "wpgpxmaps_download", ""); $dtoffset = findValue($attr, "dtoffset", "wpgpxmaps_dtoffset", 0); - $distanceType = findValue($attr, "distanceType", "wpgpxmaps_distance_type", 0); + $distanceType = findValue($attr, "distanceType", "wpgpxmaps_distance_type", 0); $skipcache = findValue($attr, "skipcache", "wpgpxmaps_skipcache", ""); @@ -153,12 +234,15 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $p_avg_speed = findValue($attr, "summaryavgspeed", "wpgpxmaps_summary_avg_speed", false); $p_total_time = findValue($attr, "summarytotaltime", "wpgpxmaps_summary_total_time", false); + $usegpsposition = findValue($attr, "usegpsposition", "wpgpxmaps_usegpsposition", false); + $currentpositioncon = findValue($attr, "currentpositioncon", "wpgpxmaps_currentpositioncon", ""); + $colors_map = "\"".implode("\",\"",(explode(" ",$color_map)))."\""; $gpxurl = $gpx; - $cacheFileName = "$gpx,$w,$mh,$mt,$gh,$showEle,$showW,$showHr,$showCad,$donotreducegpx,$pointsoffset,$showSpeed,$showGrade,$uomspeed,$uom,$distanceType,v1.1.38"; + $cacheFileName = "$gpx,$w,$mh,$mt,$gh,$showEle,$showW,$showHr,$showAtemp,$showCad,$donotreducegpx,$pointsoffset,$showSpeed,$showGrade,$uomspeed,$uom,$distanceType,v1.2.7"; $cacheFileName = md5($cacheFileName); @@ -183,6 +267,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $points_graph_ele = $cache_obj["points_graph_ele"]; $points_graph_speed = $cache_obj["points_graph_speed"]; $points_graph_hr = $cache_obj["points_graph_hr"]; + $points_graph_atemp = $cache_obj["points_graph_atemp"]; $points_graph_cad = $cache_obj["points_graph_cad"]; $points_graph_grade = $cache_obj["points_graph_grade"]; $waypoints = $cache_obj["waypoints"]; @@ -204,6 +289,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $points_graph_ele = ''; $points_graph_speed = ''; $points_graph_hr = ''; + $points_graph_atemp = ''; $points_graph_cad = ''; $points_graph_grade = ''; $waypoints= ''; @@ -246,6 +332,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $points_graph_ele = ''; $points_graph_speed = ''; $points_graph_hr = ''; + $points_graph_atemp = ''; $points_graph_cad = ''; $points_graph_grade = ''; $waypoints = ''; @@ -281,6 +368,9 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') if ($showHr == true) $points_graph_hr .= 'null,'; + if ($showAtemp == true) + $points_graph_atemp .= 'null,'; + if ($showCad == true) $points_graph_cad .= 'null,'; @@ -327,6 +417,10 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $points_graph_hr .= number_format ( $points->hr[$i] , 2 , '.' , '' ).','; } + if ($showAtemp == true) { + $points_graph_atemp .= number_format ( $points->atemp[$i] , 1 , '.' , '' ).','; + } + if ($showCad == true) { $points_graph_cad .= number_format ( $points->cad[$i] , 2 , '.' , '' ).','; } @@ -401,6 +495,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $points_graph_ele = preg_replace($p, "", $points_graph_ele); $points_graph_speed = preg_replace($p, "", $points_graph_speed); $points_graph_hr = preg_replace($p, "", $points_graph_hr); + $points_graph_atemp = preg_replace($p, "", $points_graph_atemp); $points_graph_cad = preg_replace($p, "", $points_graph_cad); $points_graph_grade = preg_replace($p, "", $points_graph_grade); @@ -418,8 +513,11 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') if (preg_match("/^(0,?)+$/", $points_graph_hr)) $points_graph_hr = ""; - if (preg_match("/^(0,?)+$/", $points_graph_cad)) - $points_graph_cad = ""; + if (preg_match("/^(0,?)+$/", $points_graph_hr)) + $points_graph_hr = ""; + + if (preg_match("/^(0,?)+$/", $points_graph_atemp)) + $points_graph_atemp = ""; if (preg_match("/^(0,?)+$/", $points_graph_grade)) $points_graph_grade = ""; @@ -451,6 +549,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') "points_graph_ele" => $points_graph_ele, "points_graph_speed" => $points_graph_speed, "points_graph_hr" => $points_graph_hr, + "points_graph_atemp" => $points_graph_atemp, "points_graph_cad" => $points_graph_cad, "points_graph_grade" => $points_graph_grade, "waypoints" => $waypoints, @@ -474,7 +573,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $r = $post->ID."_".rand(1,5000000); $output = ' -
+
@@ -482,14 +581,14 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
'. $error .' '; // print summary @@ -686,7 +788,9 @@ function WP_GPX_Maps_install() { add_option("wpgpxmaps_map_waypoint_icon", '', '', 'yes'); add_option("wpgpxmaps_map_nggallery", '', '', 'yes'); add_option("wpgpxmaps_show_hr", '', '', 'yes'); + add_option("wpgpxmaps_show_atemp", '', '', 'yes'); add_option("wpgpxmaps_graph_line_color_hr", '#ff77bd', '', 'yes'); + add_option("wpgpxmaps_graph_line_color_atemp", '#ff77bd', '', 'yes'); add_option('wpgpxmaps_show_cadence','','','yes'); add_option('wpgpxmaps_zoomonscrollwheel','','','yes'); add_option('wpgpxmaps_download','','','yes'); @@ -718,7 +822,9 @@ function WP_GPX_Maps_remove() { delete_option('wpgpxmaps_map_waypoint_icon'); delete_option('wpgpxmaps_map_nggallery'); delete_option('wpgpxmaps_show_hr'); + delete_option('wpgpxmaps_show_atemp'); delete_option('wpgpxmaps_graph_line_color_hr'); + delete_option('wpgpxmaps_graph_line_color_atemp'); delete_option('wpgpxmaps_show_cadence'); delete_option('wpgpxmaps_graph_line_color_cad'); delete_option('wpgpxmaps_zoomonscrollwheel'); diff --git a/wp-gpx-maps_admin_settings.php b/wp-gpx-maps_admin_settings.php index 6ecec85..90e7b35 100644 --- a/wp-gpx-maps_admin_settings.php +++ b/wp-gpx-maps_admin_settings.php @@ -18,6 +18,8 @@ $showEle = get_option("wpgpxmaps_show_elevation"); $showSpeed = get_option('wpgpxmaps_show_speed'); $showHr = get_option('wpgpxmaps_show_hr'); + $showAtemp = get_option('wpgpxmaps_show_atemp'); + $showCad = get_option('wpgpxmaps_show_cadence'); $showGrade = get_option('wpgpxmaps_show_grade'); $zoomonscrollwheel = get_option("wpgpxmaps_zoomonscrollwheel"); @@ -33,6 +35,8 @@ $avg_speed = get_option("wpgpxmaps_summary_avg_speed"); $total_time = get_option("wpgpxmaps_summary_total_time"); + $usegpsposition = get_option("wpgpxmaps_usegpsposition"); + $distanceType = get_option("wpgpxmaps_distance_type"); if (empty($showEle)) @@ -92,12 +96,19 @@ onchange="this.value = (this.checked)" /> Allow users to download your GPX file - + + + Use browser GPS position: + + onchange="this.value = (this.checked)" /> Allow users to use browser GPS in order to display their current position on map + + +

- + " />

@@ -235,6 +246,13 @@ + + Current GPS Position Icon: + + (Url to image) Leave empty for default + + + Custom Waypoint Icon: @@ -246,7 +264,7 @@

- + " />

@@ -259,6 +277,13 @@

Chart

+ + + + @@ -287,14 +312,6 @@ (leave empty for auto scale) - - - - - + + + + + + + + + + +
Show altitude: + onchange="wpgpxmaps_show_elevation.value = this.checked" onload="wpgpxmaps_show_elevation.value = this.checked" /> Show Altitude + +
Altitude line color:
Show elevation: - onchange="wpgpxmaps_show_elevation.value = this.checked" onload="wpgpxmaps_show_elevation.value = this.checked" /> Show elevation - -
Show speed: @@ -342,6 +359,21 @@
Show Temperature (where aviable): + onchange="this.value = (this.checked)" /> Show Temperature +
Temperature line color: + +
Show Cadence (where aviable): @@ -375,7 +407,7 @@

- + " />

diff --git a/wp-gpx-maps_utils.php b/wp-gpx-maps_utils.php index 69c7aaa..509bc89 100644 --- a/wp-gpx-maps_utils.php +++ b/wp-gpx-maps_utils.php @@ -117,6 +117,7 @@ unset($points->dist[$i]); unset($points->speed[$i]); unset($points->hr[$i]); + unset($points->atemp[$i]); unset($points->cad[$i]); unset($points->grade[$i]); } @@ -137,6 +138,7 @@ $points->dist = array(); $points->speed = array(); $points->hr = array(); + $points->atemp = array(); $points->cad = array(); $points->grade = array(); @@ -195,6 +197,7 @@ $time = $trkpt->time; $speed = (float)$trkpt->speed; $hr = 0; + $atemp = 0; $cad = 0; $grade = 0; @@ -211,6 +214,14 @@ } } + $_atemp = @$trkpt->xpath('extensions/gpxtpx:TrackPointExtension/gpxtpx:atemp/text() | extensions/TrackPointExtension/atemp/text()'); + if ($_atemp) + { + foreach ($_atemp as $node) { + $atemp = (float)$node; + } + } + $_cad = @$trkpt->xpath('extensions/gpxtpx:TrackPointExtension/gpxtpx:cad/text() | extensions/TrackPointExtension/cad/text()'); if ($_cad) { @@ -224,15 +235,16 @@ { //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); - array_push($points->grade, $grade); + 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->atemp, $atemp); + array_push($points->cad, $cad); + array_push($points->grade, $grade); $lastLat=$lat; $lastLon=$lon; @@ -297,7 +309,10 @@ 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->hr, $hr); + array_push($points->atemp, $atemp); + + array_push($points->cad, $cad); array_push($points->grade, (float)round($grade, 2) ); @@ -322,6 +337,7 @@ array_push($points->dist, null); array_push($points->speed, null); array_push($points->hr, null); + array_push($points->atemp, null); array_push($points->cad, null); array_push($points->grade, null); @@ -340,6 +356,7 @@ array_pop($points->dist, null); array_pop($points->speed, null); array_pop($points->hr, null); + array_pop($points->atemp, null); array_pop($points->cad, null); array_pop($points->grade, null); @@ -389,6 +406,7 @@ array_push($points->dist, 0 ); array_push($points->speed, 0 ); array_push($points->hr, 0 ); + array_push($points->atemp, 0 ); array_push($points->cad, 0 ); array_push($points->grade, 0 ); $lastLat=$lat; @@ -409,6 +427,7 @@ array_push($points->dist, 0 ); array_push($points->speed, 0 ); array_push($points->hr, 0 ); + array_push($points->atemp, 0 ); array_push($points->cad, 0 ); array_push($points->grade, 0 ); } @@ -454,6 +473,7 @@ array_push($points->dist, 0 ); array_push($points->speed, 0 ); array_push($points->hr, 0 ); + array_push($points->atemp, 0 ); array_push($points->cad, 0 ); array_push($points->grade, 0 ); $lastLat=$lat; @@ -474,6 +494,7 @@ array_push($points->dist, 0 ); array_push($points->speed, 0 ); array_push($points->hr, 0 ); + array_push($points->atemp, 0 ); array_push($points->cad, 0 ); array_push($points->grade, 0 ); }