diff --git a/WP-GPX-Maps.js b/WP-GPX-Maps.js index 3c34db2..12a3dd2 100644 --- a/WP-GPX-Maps.js +++ b/WP-GPX-Maps.js @@ -1,3 +1,8 @@ +/* + + WP-GPX-Maps + +*/ var loc_en = { "length" : "Length", @@ -8,19 +13,21 @@ var loc_it = "length" : "Lunghezza", "altitude": "Altitudine" }; -var loc = loc_en; +var loc = loc_en; var t; var funqueue = []; +var infowindow + var wrapFunction = function(fn, context, params) { return function() { fn.apply(context, params); }; } -function wpgpxmaps(targhetId,mapType,mapData,graphData) +function wpgpxmaps(targhetId,mapType,mapData,graphData,waypoints) { - funqueue.push( wrapFunction(_wpgpxmaps, this, [targhetId,mapType,mapData,graphData])); + funqueue.push( wrapFunction(_wpgpxmaps, this, [targhetId,mapType,mapData,graphData,waypoints])); unqueue(); } @@ -38,7 +45,7 @@ function unqueue() } } -function _wpgpxmaps(targhetId,mapType,mapData,graphData) +function _wpgpxmaps(targhetId,mapType,mapData,graphData,waypoints) { var el = document.getElementById("wpgpxmaps_" + targhetId); var el_map = document.getElementById("map_" + targhetId); @@ -55,42 +62,29 @@ function _wpgpxmaps(targhetId,mapType,mapData,graphData) mapTypeId: mapType }; var map = new google.maps.Map(el_map, mapOptions); - if (graphData!= '') + + // 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) + ); + for(var i in waypoints) + { + addWayPoint(map, image, shadow, waypoints[i][0], waypoints[i][1], waypoints[i][2], waypoints[i][3]); + } + } + + // Print Track + if (mapData != '') { - var data = new google.visualization.DataTable(); - data.addColumn('number', loc['length']); - data.addColumn('number', loc['altitude']); - data.addRows(graphData); - var chart = new google.visualization.AreaChart(el_chart); - var options = { curveType: "function", - strictFirstColumnType: true, - hAxis : {format : '#,###m', title : loc['length']}, - vAxis : {format : '#,###m', title : loc['altitude']}, - legend : {position : 'none'}, - chartArea: {left:70,top:10,width:"100%",height:"75%"} - }; - chart.draw(data, options); - google.visualization.events.addListener(chart, 'onmouseover', function (e) { - var r = e['row']; - if (marker) - { - var point = getItemFromArray(mapData,r) - marker.setPosition(new google.maps.LatLng(point[0],point[1])); marker.setTitle("Current Position"); - } - }); - google.visualization.events.addListener(chart, 'onmouseout', function (e) { - if (marker) - { - if (chart.getSelection() != '') - { - var r = chart.getSelection()[0]['row']; - var point = getItemFromArray(mapData,r) - marker.setPosition(new google.maps.LatLng(point[0], point[1])); marker.setTitle("Graph Selection"); - } - } - }); - } else { el_chart.style.display='none'; } - if (mapData != '') { var points = []; var bounds = new google.maps.LatLngBounds(); for(var i in mapData) @@ -109,13 +103,102 @@ function _wpgpxmaps(targhetId,mapType,mapData,graphData) map.setCenter(bounds.getCenter()); map.fitBounds(bounds); var first = getItemFromArray(mapData,0) + var marker = new google.maps.Marker({ position: new google.maps.LatLng(first[0], first[1]), - title:"Start" + title:"Start", + icon: "/wp-content/plugins/wp-gpx-maps/img/map_start.png", + map: map, + zIndex: 10 }); - marker.setMap(map); + } + + // Print Graph + if (graphData!= '') + { + var data = new google.visualization.DataTable(); + data.addColumn('number', loc['length']); + data.addColumn('number', loc['altitude']); + data.addRows(graphData); + var chart = new google.visualization.AreaChart(el_chart); + var options = { curveType: "function", + strictFirstColumnType: true, + hAxis : {format : '#,###m', title : loc['length']}, + vAxis : {format : '#,###m', title : loc['altitude']}, + legend : {position : 'none'}, + chartArea: {left:70,top:10,width:"100%",height:"75%"} + }; + chart.draw(data, options); + + var current = new google.maps.MarkerImage('/wp-content/plugins/wp-gpx-maps/img/map_current.png', + new google.maps.Size(32, 32), + new google.maps.Point(0,0), + new google.maps.Point(8, 0) + ); + + google.visualization.events.addListener(chart, 'onmouseover', function (e) { + var r = e['row']; + if (marker) + { + var point = getItemFromArray(mapData,r) + marker.setPosition(new google.maps.LatLng(point[0],point[1])); + marker.setIcon(current); + marker.setTitle("Current Position"); + } + }); + google.visualization.events.addListener(chart, 'onmouseout', function (e) { + if (marker) + { + if (chart.getSelection() != '') + { + var r = chart.getSelection()[0]['row']; + var point = getItemFromArray(mapData,r) + marker.setPosition(new google.maps.LatLng(point[0], point[1])); + marker.setIcon(current); + marker.setTitle("Graph Selection"); + } + else + { + var point = getItemFromArray(mapData,0) + marker.setPosition(new google.maps.LatLng(point[0], point[1])); + marker.setIcon("/wp-content/plugins/wp-gpx-maps/img/map_start.png"); + marker.setTitle("Graph Selection"); + } + } + }); + } + else + { + el_chart.style.display='none'; } } + +function addWayPoint(map, image, shadow, lat, lon, title, descr) +{ + var p = new google.maps.LatLng(lat, lon); + var m = new google.maps.Marker({ + position: p, + map: map, + title: title, + animation: google.maps.Animation.DROP, + shadow: shadow, + icon: image, + zIndex: 5 + }); + google.maps.event.addListener(m, 'mouseover', function() { + + if (infowindow) + { + infowindow.close(); + } + + infowindow = new google.maps.InfoWindow({ + content: "" + title + "" + descr + }); + infowindow.open(map,m); + }); +} + function getItemFromArray(arr,index) { try diff --git a/img/map_current.png b/img/map_current.png new file mode 100644 index 0000000..645c328 Binary files /dev/null and b/img/map_current.png differ diff --git a/img/map_start.png b/img/map_start.png new file mode 100644 index 0000000..fb57e50 Binary files /dev/null and b/img/map_start.png differ diff --git a/readme.txt b/readme.txt index 189c608..7c23bc9 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=basti Tags: maps, gpx, gps, graph, google maps, google chart, track, garmin Requires at least: 2.0.0 Tested up to: 3.3 -Stable tag: 1.0.6 +Stable tag: 1.0.7 License: GPLv2 or later Draws a gpx track with altitude graph @@ -52,7 +52,9 @@ The attributes are: 1. mtype: map aviable types are: HYBRID, ROADMAP, SATELLITE, TERRAIN -shortcode with all the attributes : [sgpx gpx=">relative path to your gpx<" width=100% mheight=300px gheight=200px mtype=SATELLITE] +1. waypoints: print the gpx waypoints inside the map (default is FALSE) + +shortcode with all the attributes : [sgpx gpx=">relative path to your gpx<" width=100% mheight=300px gheight=200px mtype=SATELLITE waypoints=true] = What happening if I've a very large gpx? = This plugin will print a small amout of points to to speedup javascript and pageload. @@ -61,10 +63,14 @@ This plugin will print a small amout of points to to speedup javascript and page Yes! == Screenshots == -1. Screenshot Sample -2. Screenshot Admin area +1. Simple Gpx +1. Gpx with waypoints +2. Admin area == Changelog == += 1.0.7 = +* Added waypoints support +* New icons = 1.0.6 = * Minor bug fix = 1.0.5 = @@ -83,6 +89,8 @@ Yes! * Initial release. == Upgrade Notice == += 1.0.7 = +* Added waypoints support. To enable this feature please check the plugin settings = 1.0.6 = = 1.0.5 = = 1.0.4 = diff --git a/screenshot-1.jpg b/screenshot-1.jpg index f435eca..feb57d5 100644 Binary files a/screenshot-1.jpg and b/screenshot-1.jpg differ diff --git a/screenshot-2.jpg b/screenshot-2.jpg index b8c9103..f6d762f 100644 Binary files a/screenshot-2.jpg and b/screenshot-2.jpg differ diff --git a/screenshot-3.jpg b/screenshot-3.jpg new file mode 100644 index 0000000..b7bd75b Binary files /dev/null and b/screenshot-3.jpg differ diff --git a/wp-gpx-maps.php b/wp-gpx-maps.php index 314b00f..1ea16c0 100644 --- a/wp-gpx-maps.php +++ b/wp-gpx-maps.php @@ -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.0.6 +Version: 1.0.7 Author: Bastianon Massimo Author URI: http://www.pedemontanadelgrappa.it/ License: GPL @@ -57,6 +57,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $mh = $attr["mheight"]; $mt = $attr["mtype"]; $gh = $attr["gheight"]; + $showW = $attr['waypoints']; if ($w == '') { @@ -82,33 +83,63 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') { $gh = "200px"; } - + + if ($showW == '') + { + $showW = get_option("wpgpxmaps_show_waypoint"); + } + $r = rand(1,5000000); $points = getPoints($gpx); $points_maps = ''; $points_graph = ''; + $waypoints = ''; foreach ($points as $p) { $points_maps .= "[".(float)$p[0].",".(float)$p[1]."],"; $points_graph .= "[".(float)$p[3].",".(float)$p[2]."],"; } //all the points are [0,0] $points_graph = preg_replace("/^(\[0,0\],)+$/", "", $points_graph); + + if ($showW == true) + { + $wpoints = getWayPoints($gpx); + foreach ($wpoints as $p) { + $waypoints .= "[".(float)$p[0].",".(float)$p[1].",'".unescape($p[4])."','".unescape($p[5])."','".unescape($p[7])."'],"; + } + } + $p="/,$/"; $points_maps = preg_replace($p, "", $points_maps); - $points_graph = preg_replace($p, "", $points_graph); if (preg_match("/^(\[0,0\],?)+$/", $points_graph)) { $points_graph = ""; } - return ' + $points_graph = preg_replace($p, "", $points_graph); + $waypoints = preg_replace($p, "", $waypoints); + + if (preg_match("/^(\[0,0\],?)+$/", $points_graph)) + { + $points_graph = ""; + } + + $output = '
- Full set of attributes: [sgpx gpx="/wp-content/uploads/gpx/< gpx file name >" width=100% mheight=450px gheight=200px mtype=SATELLITE] + Full set of attributes: [sgpx gpx="/wp-content/uploads/gpx/< gpx file name >" width=100% mheight=450px gheight=200px mtype=SATELLITE waypoints=true]