diff --git a/WP-GPX-Maps.js b/WP-GPX-Maps.js index 7ff028f..987c8c9 100644 --- a/WP-GPX-Maps.js +++ b/WP-GPX-Maps.js @@ -26,9 +26,9 @@ var wrapFunction = function(fn, context, params) { }; } -function wpgpxmaps(targhetId,mapType,mapData,graphData,waypoints) +function wpgpxmaps(targhetId,mapType,mapData,graphData,waypoints,unit,color1,color2) { - funqueue.push( wrapFunction(_wpgpxmaps, this, [targhetId,mapType,mapData,graphData,waypoints])); + funqueue.push( wrapFunction(_wpgpxmaps, this, [targhetId,mapType,mapData,graphData,waypoints,unit,color1,color2])); unqueue(); } @@ -46,7 +46,7 @@ function unqueue() } } -function _wpgpxmaps(targhetId,mapType,mapData,graphData,waypoints) +function _wpgpxmaps(targhetId,mapType,mapData,graphData,waypoints,unit,color1,color2) { var el = document.getElementById("wpgpxmaps_" + targhetId); var el_map = document.getElementById("map_" + targhetId); @@ -96,7 +96,7 @@ function _wpgpxmaps(targhetId,mapType,mapData,graphData,waypoints) } var poly = new google.maps.Polyline({ path: points, - strokeColor: "#3366cc", + strokeColor: color1, strokeOpacity: .7, strokeWeight: 4 }); @@ -126,7 +126,13 @@ function _wpgpxmaps(targhetId,mapType,mapData,graphData,waypoints) marker.setTitle("Current Position"); if ( chart ) { - var ci = getClosestIndex(mapData,event.latLng.Qa,event.latLng.Ra); + var l1 = event.latLng.Qa; + if (!(l1)) + l1 = event.latLng.Oa; + var l2 = event.latLng.Ra; + if (!(l2)) + l2 = event.latLng.Pa; + var ci = getClosestIndex(mapData,l1,l2); var r = chart.setSelection([{'row': parseInt(ci) + 1}]); } } @@ -136,6 +142,16 @@ function _wpgpxmaps(targhetId,mapType,mapData,graphData,waypoints) // Print Graph if (graphData!= '') { + + var numberFormat1 = "#,###m"; + var numberFormat2 = "#,###m"; + + if (unit=="1") + { + var numberFormat1 = "#,##0.#mi"; + var numberFormat2 = "#,###ft"; + } + var data = new google.visualization.DataTable(); data.addColumn('number', loc['length']); data.addColumn('number', loc['altitude']); @@ -143,10 +159,11 @@ function _wpgpxmaps(targhetId,mapType,mapData,graphData,waypoints) 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']}, + hAxis : {format : numberFormat1, title : loc['length']}, + vAxis : {format : numberFormat2, title : loc['altitude']}, legend : {position : 'none'}, - chartArea: {left:70,top:10,width:"100%",height:"75%"} + chartArea: {left:70,top:10,width:"100%",height:"75%"}, + colors:[color2] }; chart.draw(data, options); @@ -163,7 +180,6 @@ function _wpgpxmaps(targhetId,mapType,mapData,graphData,waypoints) //google.visualization.events.addListener(chart, 'onmouseout', function (e) { //chart.setSelection([e]); //}); - } else { diff --git a/readme.txt b/readme.txt index 1d9297e..d11cf11 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.1.3 +Stable tag: 1.1.4 License: GPLv2 or later Draws a gpx track with altitude graph @@ -58,6 +58,12 @@ The attributes are: 1. pointsoffset: Skip points closer than XX meters(default is 10) +1. uom: the unit of measure values are: 0, 1 (0 = meters, 1 = miles/feet) + +1. mlinecolor: map line color (default is #3366cc) + +1. glinecolor: graph line color (default is #3366cc) + 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? = @@ -69,9 +75,15 @@ Yes! == Screenshots == 1. Simple Gpx 1. Gpx with waypoints -2. Admin area +2. Admin area - List of tracks +2. Admin area - Settings == Changelog == += 1.1.4 = +* improved admin area +* added miles/feet unit of measure +* added map line color and graph line color +* minor bug fixes = 1.1.3 = * Allowed gpx files from http url = 1.1.2 = @@ -109,6 +121,7 @@ Yes! * Initial release. == Upgrade Notice == += 1.1.4 = = 1.1.3 = = 1.1.2 = = 1.1.1 = diff --git a/screenshot-1.jpg b/screenshot-1.jpg index feb57d5..b9c5fcd 100644 Binary files a/screenshot-1.jpg and b/screenshot-1.jpg differ diff --git a/screenshot-2.jpg b/screenshot-2.jpg index f6d762f..3ffae8b 100644 Binary files a/screenshot-2.jpg and b/screenshot-2.jpg differ diff --git a/screenshot-3.jpg b/screenshot-3.jpg index b7bd75b..dbf75ae 100644 Binary files a/screenshot-3.jpg and b/screenshot-3.jpg differ diff --git a/screenshot-4.jpg b/screenshot-4.jpg new file mode 100644 index 0000000..f31e125 Binary files /dev/null and b/screenshot-4.jpg differ diff --git a/wp-gpx-maps.php b/wp-gpx-maps.php index bc2e62f..29cf283 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.1.3 +Version: 1.1.4 Author: Bastianon Massimo Author URI: http://www.pedemontanadelgrappa.it/ License: GPL @@ -79,6 +79,9 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $showW = findValue($attr, "waypoints", "wpgpxmaps_show_waypoint", false); $donotreducegpx = findValue($attr, "donotreducegpx", "wpgpxmaps_donotreducegpx", false); $pointsoffset = findValue($attr, "pointsoffset", "wpgpxmaps_pointsoffset", 10); + $uom = findValue($attr, "uom", "wpgpxmaps_unit_of_measure", "0"); + $color_map = findValue($attr, "mlinecolor", "wpgpxmaps_map_line_color", "#3366cc"); + $color_graph = findValue($attr, "glinecolor", "wpgpxmaps_graph_line_color", "#3366cc"); $r = rand(1,5000000); @@ -105,8 +108,17 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') 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 ($uom == '1') + { + // Miles and feet + $points_graph .= '['.((float)$p[3]*0.000621371192).','.((float)$p[2]*3.2808399).'],'; + } + else + { + $points_graph .= '['.(float)$p[3].','.(float)$p[2].'],'; + } + } if ($showW == true) { @@ -135,7 +147,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') var m_'.$r.' = ['.$points_maps.']; var c_'.$r.' = ['.$points_graph.']; var w_'.$r.' = ['.$waypoints.']; - wpgpxmaps("'.$r.'","'.$mt.'",m_'.$r.',c_'.$r.', w_'.$r.'); + wpgpxmaps("'.$r.'","'.$mt.'",m_'.$r.',c_'.$r.', w_'.$r.', "'.$uom.'", "'.$color_map.'", "'.$color_graph.'"); '; return $output; @@ -174,6 +186,9 @@ function WP_GPX_Maps_install() { add_option('wpgpxmaps_show_waypoint','','','yes'); add_option('wpgpxmaps_pointsoffset','10','','yes'); add_option('wpgpxmaps_donotreducegpx','true','','yes'); + add_option("wpgpxmaps_unit_of_measure", 'mt', '', 'yes'); + add_option("wpgpxmaps_graph_line_color", '#3366cc', '', 'yes'); + add_option("wpgpxmaps_map_line_color", '#3366cc', '', 'yes'); } function WP_GPX_Maps_remove() { @@ -184,6 +199,10 @@ function WP_GPX_Maps_remove() { delete_option('wpgpxmaps_show_waypoint'); delete_option('wpgpxmaps_pointsoffset'); delete_option('wpgpxmaps_donotreducegpx'); + delete_option('wpgpxmaps_unit_of_measure'); + delete_option('wpgpxmaps_graph_line_color'); + delete_option('wpgpxmaps_map_line_color'); + } ?> diff --git a/wp-gpx-maps_Utils.php b/wp-gpx-maps_Utils.php index bc646dc..3e86a1f 100644 --- a/wp-gpx-maps_Utils.php +++ b/wp-gpx-maps_Utils.php @@ -93,7 +93,7 @@ if ($lastLat == 0 && $lastLon == 0) { //Base Case - array_push($points, array((float)$lat,(float)$lon,(float)round($ele,1),(float)round($dist,1))); + array_push($points, array((float)$lat,(float)$lon,(float)round($ele,2),(float)round($dist,2))); $lastLat=$lat; $lastLon=$lon; $lastEle=$ele; @@ -101,7 +101,7 @@ else { //Normal Case - $offset = calculateDistance($lat, $lon, $ele,$lastLat, $lastLon, $lastEle); + $offset = calculateDistance((float)$lat, (float)$lon, (float)$ele, (float)$lastLat, (float)$lastLon, (float)$lastEle); $dist = $dist + $offset; if (((float) $offset + (float) $lastOffset) > $gpxOffset) { @@ -213,17 +213,18 @@ function toRadians($degrees) { - return $degrees * 3.1415926535897932385 / 180; + return (float)($degrees * 3.1415926535897932385 / 180); } function calculateDistance($lat1,$lon1,$ele1,$lat2,$lon2,$ele2) { + $alpha = (float)sin((float)toRadians((float) $lat2 - (float) $lat1) / 2); + $beta = (float)sin((float)toRadians((float) $lon2 - (float) $lon1) / 2); //Distance in meters - $dLat = toRadians((float) $lat2 - (float) $lat1); - $dLng = toRadians((float) $lon2 - (float) $lon1); - $a = (float) ( sin($dLat / 2) * sin($dLat / 2)) + (float) ( cos( toRadians($lat1)) * cos( toRadians($lat2)) * sin($dLng / 2) * sin($dLng / 2) ); - $dist = 2 * 3958.75 * atan2(sqrt($a), sqrt(1 - (float) $a)); - return sqrt(pow($dist * 1609.00, 2) + pow((float) $lat1 - (float)$lat2, 2)); + $a = (float) ( (float)$alpha * (float)$alpha) + (float) ( (float)cos( (float)toRadians($lat1)) * (float)cos( (float)toRadians($lat2)) * (float)$beta * (float)$beta ); + $dist = 2 * 6369628.75 * (float)atan2((float)sqrt((float)$a), (float)sqrt(1 - (float) $a)); + $d = (float)sqrt((float)pow((float)$dist, 2) + pow((float) $lat1 - (float)$lat2, 2)); + return sqrt((float)pow((float)$ele1-(float)$ele2,2)+(float)pow((float)$d,2)); } diff --git a/wp-gpx-maps_admin.php b/wp-gpx-maps_admin.php index 6e9ca18..6a4cc45 100644 --- a/wp-gpx-maps_admin.php +++ b/wp-gpx-maps_admin.php @@ -9,18 +9,33 @@ if ( is_admin() ){ } } +function ilc_admin_tabs( $current ) { + $tabs = array( 'tracks' => 'Tracks', 'settings' => 'Settings', 'help' => "help" ); + echo ''; +} + function WP_GPX_Maps_html_page() { $realGpxPath = gpxFolderPath(); $relativeGpxPath = relativeGpxFolderPath(); $relativeGpxPath = str_replace("\\","/", $relativeGpxPath); $gpxRegEx = '/.gpx$/'; -?> - -
-

WP GPX Settings

- - +

+

WP GPX Settings

+'; } } - $po = get_option('wpgpxmaps_pointsoffset'); - $showW = get_option("wpgpxmaps_show_waypoint"); - $donotreducegpx = get_option("wpgpxmaps_donotreducegpx"); - $t = get_option('wpgpxmaps_map_type'); - if (!($t)) - $t = 'HYBRID'; - if (!($po)) - $po = 10; - + + ilc_admin_tabs($tab); + + if ($tab == "tracks") + { + include 'wp-gpx-maps_admin_tracks.php'; + } + else if ($tab == "settings") + { + include 'wp-gpx-maps_admin_settings.php'; + } + else if ($tab == "help") + { ?> -
- The fastest way to use this plugin: upload the file using the uploader below, than put this - shotcode: [sgpx gpx="< gpx file name >"] in the pages/posts. -

- Full set of attributes: [sgpx gpx="< gpx file name >" width=100% mheight=450px gheight=200px mtype=SATELLITE waypoints=true donotreducegpx=false pointsoffset=10] -

-
+
+ The fastest way to use this plugin:
upload the file using the uploader in the first tab, than copy the shortcode from the list and paste it in the pages/posts. +

You can manually set the relative path to your gpx: [sgpx gpx="< gpx file name >"].

+

You can also use gpx from other sites: [sgpx gpx="http://www.someone.com/somewhere/somefile.gpx"]

+
+

+ Full set of attributes: [sgpx + gpx="< gpx file name >" + width=100% + mheight=450px + gheight=200px + mtype=SATELLITE + waypoints=true + donotreducegpx=false + pointsoffset=10 + uom=0 + mlinecolor=#3366cc + glinecolor=#3366cc] -

+
    +
  • gpx: relative path to gpx
  • +
  • width: width in pixels
  • +
  • mheight: map height
  • +
  • gheight: graph height
  • +
  • mtype: map aviable types are: HYBRID, ROADMAP, SATELLITE, TERRAIN
  • +
  • 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)
  • +
  • mlinecolor: map line color (default is #3366cc)
  • +
  • glinecolor: graph line color (default is #3366cc)
  • +
- - - - - - - - - - - - - - - -
Default Options: - Width: , - Maps Height: , - Graph Height: , - onchange="this.value = (this.checked)" />Show Waypoints -
Default Map Type: -
- > HYBRID: transparent layer of major streets on satellite images.
- > ROADMAP: normal street map.
- > SATELLITE: satellite images.
- > TERRAIN: maps with physical features such as terrain and vegetation.
-
Advanced options: -
- Do not edit if you don't know what you are doing!
- Skip points closer than meters. - onchange="this.value = (this.checked)" />Do not reduce gpx. -
- - - - -

- -

- -
- - - -
-
- Choose a file to upload: - ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; - } else{ - echo "There was an error uploading the file, please try again!"; - } - } - else - { - echo "file not supported!"; - } - } - ?> -
-
- - - - - - - - - - - - - - - - - - - - - +

+ Bugs, problems, thanks and anything else here! +

- - - - - - - - - - - -
FileLast modifiedFile size (Byte)
FileLast modifiedFile size (Byte)
- - - - - -
- Delete - | - Download - | - Shortcode: [sgpx gpx=""] -
+

+
- - -
- -
- -
\ No newline at end of file diff --git a/wp-gpx-maps_admin_settings.php b/wp-gpx-maps_admin_settings.php new file mode 100644 index 0000000..3d98dde --- /dev/null +++ b/wp-gpx-maps_admin_settings.php @@ -0,0 +1,89 @@ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Map and Graph size: + Width: , + Map Height: , + Graph Height: +
Waypoints Support: + onchange="this.value = (this.checked)" />Show Waypoints +
Default Map Type: + > HYBRID: transparent layer of major streets on satellite images.
+ > ROADMAP: normal street map.
+ > SATELLITE: satellite images.
+ > TERRAIN: maps with physical features such as terrain and vegetation.
+
Unit of measure: + +
Map line color: + +
Graph line color: + +
Advanced options: +
+ Do not edit if you don't know what you are doing!
+ Skip points closer than meters. + onchange="this.value = (this.checked)" />Do not reduce gpx. +
+ + + + +

+ +

+ +
\ No newline at end of file diff --git a/wp-gpx-maps_admin_tracks.php b/wp-gpx-maps_admin_tracks.php new file mode 100644 index 0000000..f508932 --- /dev/null +++ b/wp-gpx-maps_admin_tracks.php @@ -0,0 +1,126 @@ + + +
+
+ Choose a file to upload: + ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; + } else{ + echo "There was an error uploading the file, please try again!"; + } + } + else + { + echo "file not supported!"; + } + } + ?> +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileLast modifiedFile size (Byte)
FileLast modifiedFile size (Byte)
+ + + + + +
+ Delete + | + Download + | + Shortcode: [sgpx gpx=""] +
+ + + + +
+ +