diff --git a/WP-GPX-Maps.js b/WP-GPX-Maps.js index a492287..9812131 100644 --- a/WP-GPX-Maps.js +++ b/WP-GPX-Maps.js @@ -4,37 +4,71 @@ */ +var t; +var funqueue = []; var infowindow; +var mapLoading = false; +var CustomMarker; - function CustomMarker( map, latlng, src, img_w, img_h) { - this.latlng_ = latlng; +var wrapFunction = function(fn, context, params) { + return function() { + fn.apply(context, params); + }; +} - // Once the LatLng and text are set, add the overlay to the map. This will - // trigger a call to panes_changed which should in turn call draw. - this.setMap(map); - this.src_ = src; - this.img_w_ = img_w; - this.img_h_ = img_h; - } +function wpgpxmaps(params) +{ + funqueue.push( wrapFunction(_wpgpxmaps, this, [params])); + unqueue(); +} - CustomMarker.prototype = new google.maps.OverlayView(); +function unqueue() +{ + if ((google == undefined || google.maps == undefined || Highcharts == undefined)) + { + t = setTimeout("unqueue()",200); + } + else + { + setup(); + while (funqueue.length > 0) { + (funqueue.shift())(); + } + } +} - CustomMarker.prototype.draw = function() { - var me = this; +function setup() +{ - // Check if the el has been created. - var el = this.img_; - if (!el) { + CustomMarker = function( map, latlng, src, img_w, img_h) { + this.latlng_ = latlng; - el = this.img_ = document.createElement('img'); + // Once the LatLng and text are set, add the overlay to the map. This will + // trigger a call to panes_changed which should in turn call draw. + this.setMap(map); + this.src_ = src; + this.img_w_ = img_w; + this.img_h_ = img_h; + } + + CustomMarker.prototype = new google.maps.OverlayView(); + + CustomMarker.prototype.draw = function() { + var me = this; + + // Check if the el has been created. + var el = this.img_; + if (!el) { + + el = this.img_ = document.createElement('img'); el.style.cssText = "border:1px solid #fff;position:absolute;cursor:pointer;margin:0;width:"+(this.img_w_/3)+"px;height:"+(this.img_h_/3)+"px;z-index:1;"; el.setAttribute("lat",this.latlng_.lat()); el.setAttribute("lon",this.latlng_.lng()); el.src=this.src_; - google.maps.event.addDomListener(el, "click", function(event) { - google.maps.event.trigger(me, "click",el); - }); + google.maps.event.addDomListener(el, "click", function(event) { + google.maps.event.trigger(me, "click",el); + }); google.maps.event.addDomListener(el, "mouseover", function(event) { var _t = el.style.top.replace('px',''); @@ -58,30 +92,34 @@ var infowindow; }, 100); }); - // Then add the overlay to the DOM - var panes = this.getPanes(); - panes.overlayImage.appendChild(el); - } + // Then add the overlay to the DOM + var panes = this.getPanes(); + panes.overlayImage.appendChild(el); + } - // Position the overlay - var point = this.getProjection().fromLatLngToDivPixel(this.latlng_); - if (point) { - el.style.left = point.x + 'px'; - el.style.top = point.y + 'px'; + // Position the overlay + var point = this.getProjection().fromLatLngToDivPixel(this.latlng_); + if (point) { + el.style.left = point.x + 'px'; + el.style.top = point.y + 'px'; this.orig_left = point.x; this.orig_top = point.y; - } - }; + } + }; - CustomMarker.prototype.remove = function() { - // Check if the overlay was on the map and needs to be removed. - if (this.img_) { - this.img_.parentNode.removeChild(this.img_); - this.img_ = null; - } - }; + CustomMarker.prototype.remove = function() { + // Check if the overlay was on the map and needs to be removed. + if (this.img_) { + this.img_.parentNode.removeChild(this.img_); + this.img_ = null; + } + }; -function wpgpxmaps(params) +} + + + +function _wpgpxmaps(params) { var targetId = params.targetId; @@ -91,6 +129,7 @@ function wpgpxmaps(params) var graphEle = params.graphEle; var graphSpeed = params.graphSpeed; var graphHr = params.graphHr; + var graphCad = params.graphCad; var waypoints = params.waypoints; var unit = params.unit; var unitspeed = params.unitspeed; @@ -98,6 +137,7 @@ function wpgpxmaps(params) var color2 = params.color2; var color3 = params.color3; var color4 = params.color4; + var color5 = params.color5; var chartFrom1 = params.chartFrom1; var chartTo1 = params.chartTo1; var chartFrom2 = params.chartFrom2; @@ -569,10 +609,49 @@ function wpgpxmaps(params) l_y_arr.push(l_hr); } + + if (graphCad != '') + { + + var l_cad = { suf : "", dec : 0 }; + + var cadData = []; + + for (i=0; i lat) as $i) @@ -224,6 +226,11 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $points_graph_hr .= $points->hr[$i].','; } + if ($showCad == true) + { + $points_graph_cad .= $points->cad[$i].','; + } + } if ($showW == true) @@ -241,6 +248,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_cad = preg_replace($p, "", $points_graph_cad); $waypoints = preg_replace($p, "", $waypoints); @@ -255,6 +263,9 @@ 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 = ""; } @@ -279,6 +290,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_cad" => $points_graph_cad, "waypoints" => $waypoints) ), LOCK_EX); @@ -292,7 +304,6 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') '; return $output; @@ -367,6 +379,7 @@ function WP_GPX_Maps_install() { add_option("wpgpxmaps_graph_line_color", '#3366cc', '', 'yes'); add_option("wpgpxmaps_graph_line_color_speed", '#ff0000', '', 'yes'); add_option("wpgpxmaps_map_line_color", '#3366cc', '', 'yes'); + add_option("wpgpxmaps_graph_line_color_cad", '#beecff', '', 'yes'); add_option("wpgpxmaps_graph_offset_from1", '', '', 'yes'); add_option("wpgpxmaps_graph_offset_to1", '', '', 'yes'); add_option("wpgpxmaps_graph_offset_from2", '', '', 'yes'); @@ -377,6 +390,7 @@ function WP_GPX_Maps_install() { add_option("wpgpxmaps_map_nggallery", '', '', 'yes'); add_option("wpgpxmaps_show_hr", '', '', 'yes'); add_option("wpgpxmaps_graph_line_color_hr", '#ff77bd', '', 'yes'); + add_option('wpgpxmaps_show_cadence','','','yes'); } @@ -404,6 +418,8 @@ function WP_GPX_Maps_remove() { delete_option('wpgpxmaps_map_nggallery'); delete_option('wpgpxmaps_show_hr'); delete_option('wpgpxmaps_graph_line_color_hr'); + delete_option('wpgpxmaps_show_cadence'); + delete_option('wpgpxmaps_graph_line_color_cad'); } ?> diff --git a/wp-gpx-maps_admin.php b/wp-gpx-maps_admin.php index e73ac5b..2be7249 100644 --- a/wp-gpx-maps_admin.php +++ b/wp-gpx-maps_admin.php @@ -97,13 +97,15 @@ function WP_GPX_Maps_html_page() {
  • waypoints: print the gpx waypoints inside the map (default is FALSE)
  • donotreducegpx: print all the point without reduce it (default is FALSE)
  • pointsoffset: skip points closer than XX meters(default is 10)
  • -
  • uom: the unit of measure values are: 0, 1 (0 = meters, 1 = miles/feet)
  • +
  • uom: the unit of measure values are: 0, 1, 2 (0 = meters, 1 = miles/feet, 2 = meters/kilometers)
  • mlinecolor: map line color (default is #3366cc)
  • glinecolor: graph line color (default is #3366cc)
  • -
  • glinecolorhr: heart rate line color (default is #ff77bd)
  • glinecolorspeed: speed line color (default is #ff0000)
  • +
  • glinecolorhr: heart rate line color (default is #ff77bd)
  • +
  • glinecolorcad: cadence line color (default is #beecff)
  • showspeed: show speed inside the chart (default is FALSE)
  • showhr: show heart rate inside the chart (default is FALSE)
  • +
  • showcad: show cadence inside the chart (default is FALSE)
  • uomspeed: the unit of measure of speed are: 0, 1, 2 (0 = m/s, 1 = km/h, 2 = miles/h)
  • chartFrom1: minimun value for altitude chart
  • chartTo1: maxumin value for altitude chart
  • @@ -115,7 +117,7 @@ function WP_GPX_Maps_html_page() {
  • nggalleries: NextGen Gallery id or a list of Galleries id separated by a comma
  • ngimages: NextGen Image id or a list of Images id separated by a comma
  • - +

    Bugs, problems, thanks and anything else here!

    diff --git a/wp-gpx-maps_admin_settings.php b/wp-gpx-maps_admin_settings.php index b891d2d..4c07728 100644 --- a/wp-gpx-maps_admin_settings.php +++ b/wp-gpx-maps_admin_settings.php @@ -11,6 +11,7 @@ $uomSpeed = get_option('wpgpxmaps_unit_of_measure_speed'); $showSpeed = get_option('wpgpxmaps_show_speed'); $showHr = get_option('wpgpxmaps_show_hr'); + $showCad = get_option('wpgpxmaps_show_cadence'); if (!($t)) $t = 'HYBRID'; @@ -182,13 +183,8 @@ (leave empty for auto scale) - - $showHr = get_option('wpgpxmaps_show_hr'); - - - - Show heart rate: + Show Heart Rate (where aviable): onchange="this.value = (this.checked)" />Show heart rate @@ -201,14 +197,24 @@ - - + + Show Cadence (where aviable): + + onchange="this.value = (this.checked)" />Show Cadence + + + + Cadence line color: + + + + + -

    - +

    diff --git a/wp-gpx-maps_Utils.php b/wp-gpx-maps_utils.php similarity index 89% rename from wp-gpx-maps_Utils.php rename to wp-gpx-maps_utils.php index 06242ea..843eb47 100644 --- a/wp-gpx-maps_Utils.php +++ b/wp-gpx-maps_utils.php @@ -106,6 +106,7 @@ unset($points->dist[$i]); unset($points->speed[$i]); unset($points->hr[$i]); + unset($points->cad[$i]); } } } @@ -123,6 +124,7 @@ $points->dist = array(); $points->speed = array(); $points->hr = array(); + $points->cad = array(); $gpx = simplexml_load_file($filePath); @@ -155,17 +157,26 @@ $ele = $trkpt->ele; $time = $trkpt->time; $speed = (float)$trkpt->speed; - $hr=0; + $hr = 0; + $cad = 0; if (isset($trkpt->extensions)) { - $_hr = @$trkpt->extensions->xpath('gpxtpx:TrackPointExtension/gpxtpx:hr/text()'); + $_hr = $trkpt->extensions->xpath('gpxtpx:TrackPointExtension/gpxtpx:hr/text()'); 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; + } + } } if ($lastLat == 0 && $lastLon == 0) @@ -178,6 +189,7 @@ 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; @@ -193,8 +205,6 @@ if ($speed == 0) { $datediff = (float)my_date_diff($lastTime,$time); - //echo "------------$time-------$lastTime-----"; - //echo "------------$datediff------------"; if ($datediff>0) { $speed = $offset / $datediff; @@ -206,7 +216,6 @@ if (((float) $offset + (float) $lastOffset) > $gpxOffset) { //Bigger Offset -> write coordinate - $avgSpeed = 0; foreach($speedBuffer as $s) @@ -225,6 +234,7 @@ 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 @@ -269,6 +279,8 @@ 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; } @@ -285,7 +297,9 @@ array_push($points->lon, (float)$lon ); array_push($points->ele, 0 ); array_push($points->dist, 0 ); - array_push($points->speed, 0 ); + array_push($points->speed, 0 ); + array_push($points->hr, 0 ); + array_push($points->cad, 0 ); } else {