From 38ff37c48e67129d196a75f909ef0cb277da975a Mon Sep 17 00:00:00 2001 From: bastianonm Date: Mon, 19 Dec 2011 13:27:22 +0000 Subject: [PATCH] --- WP-GPX-Maps.js | 4 - readme.txt | 53 ++++----- wp-gpx-maps.php | 269 +++++++++--------------------------------- wp-gpx-maps_Utils.php | 186 ++++++++++++++--------------- wp-gpx-maps_admin.php | 47 +++++--- 5 files changed, 202 insertions(+), 357 deletions(-) diff --git a/WP-GPX-Maps.js b/WP-GPX-Maps.js index 5ee2544..e97bd02 100644 --- a/WP-GPX-Maps.js +++ b/WP-GPX-Maps.js @@ -3,18 +3,14 @@ var loc_en = "length" : "Length", "altitude": "Altitude" }; - var loc_it = { "length" : "Lunghezza", "altitude": "Altitudine" }; - var loc = loc_en; - function wpgpxmaps(targhetId,mapType,mapData,graphData) { - var el = document.getElementById("wpgpxmaps_" + targhetId); var el_map = document.getElementById("map_" + targhetId); var el_chart = document.getElementById("chart_" + targhetId); diff --git a/readme.txt b/readme.txt index c17a371..ea05a48 100644 --- a/readme.txt +++ b/readme.txt @@ -1,64 +1,59 @@ === WP-GPX-Maps === Contributors: bastianonm -Donate link: http://www.darwinner.it/ -Tags: maps, gpx, graph, google maps, google chart +Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=bastianonm@hotmail.com&item_name=WP-GRX-Maps&item_number=WP-GRX-Maps&amount=5¤cy_code=EUR +Tags: maps, gpx, gps, graph, google maps, google chart Requires at least: 2.0.0 Tested up to: 3.3 -Stable tag: 1.0.2 +Stable tag: 1.0.3 License: GPLv2 or later -Add a gpx track with altitude graph +Draws a gpx track with altitude graph == Description == - This plugin has, as input, the GPX file with the track you've made. As output it shows the map of the track, fixed with an altitude graph. - -- Also working on iphone/ipad/ipod - +- iphone/ipad/ipod Compatible Try this plugin on http://www.pedemontanadelgrappa.it/category/mappe/ - Thanks to: www.securcube.net, www.darwinner.it, www.pedemontanadelgrappa.it, - Bugs, problems, thanks and anything else here! - == Installation == - 1. Use the classic wordpress plugin installer or copy the plugins folder to the `/wp-content/plugins/` directory 1. Activate the plugin through the 'Plugins' menu in WordPress 1. Add the shortcode [sgpx gpx=">relative path to your gpx<"] == Frequently Asked Questions == += what are all available shortcode attributes? = +The attributes are: +1. gpx: relative path to gpx +1. width: width in pixels +1. mheight: map height +1. gheight: graph height +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] = What happening if I've a very large gpx? = - This plugin will print a small amout of points to to speedup javascript and pageload. - = Is it free? = - Yes! == Screenshots == - 1. Screenshot Sample 2. Screenshot Admin area == Changelog == - += 1.0.3 = +* Added Settings link on plugins list +* Added attributes width, mheight, gheight, mtype on shortcode. += 1.0.2 = +* You can manage your gpx files in the admin area. += 1.0.1 = +* Small changes on javascript localization. = 1.0.0 = * Initial release. -= 1.0.1 = -* Small changes on javascript localization. - -= 1.0.2 = -* You can manage your gpx files in the admin area. - == Upgrade Notice == - -= 1.0.0 = -Initial release. - -= 1.0.1 = - += 1.0.3 = = 1.0.2 = += 1.0.1 = += 1.0.0 = +Initial release. \ No newline at end of file diff --git a/wp-gpx-maps.php b/wp-gpx-maps.php index b9048b8..e4b7592 100644 --- a/wp-gpx-maps.php +++ b/wp-gpx-maps.php @@ -2,16 +2,39 @@ /* Plugin Name: WP-GPX-Maps Plugin URI: http://www.darwinner.it/ -Description: Add a gpx track with altitude graph -Version: 1.0.2 +Description: Draws a gpx track with altitude graph +Version: 1.0.3 Author: Bastianon Massimo Author URI: http://www.pedemontanadelgrappa.it/ License: GPL */ include 'wp-gpx-maps_Utils.php'; +include 'wp-gpx-maps_admin.php'; add_action( 'wp_print_scripts', 'enqueue_WP_GPX_Maps_scripts' ); +add_shortcode('sgpx','handle_WP_GPX_Maps_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); + +function WP_GPX_Maps_action_links($links, $file) { + static $this_plugin; + + if (!$this_plugin) { + $this_plugin = plugin_basename(__FILE__); + } + + // check to make sure we are on the correct plugin + if ($file == $this_plugin) { + // the anchor tag and href to the URL we want. For a "Settings" link, this needs to be the url of your settings page + $settings_link = 'Settings'; + // add the link to the list + array_unshift($links, $settings_link); + } + + return $links; +} function enqueue_WP_GPX_Maps_scripts() { @@ -25,15 +48,38 @@ function enqueue_WP_GPX_Maps_scripts() -
-
+
+
'; } -register_activation_hook(__FILE__,'WP_GPX_Maps_install'); -register_deactivation_hook( __FILE__, 'WP_GPX_Maps_remove'); - function WP_GPX_Maps_install() { add_option("wpgpxmaps_width", '100%', '', 'yes'); + add_option("wpgpxmaps_graph_height", '200px', '', 'yes'); add_option("wpgpxmaps_height", '450px', '', 'yes'); add_option('wpgpxmaps_map_type','HYBRID','','yes'); } function WP_GPX_Maps_remove() { delete_option('wpgpxmaps_width'); + delete_option('wpgpxmaps_graph_height'); delete_option('wpgpxmaps_height'); delete_option('wpgpxmaps_map_type'); } -if ( is_admin() ){ - - add_action('admin_menu', 'wpgpxmaps_admin_menu'); - - function wpgpxmaps_admin_menu() { - add_options_page('WP GPX Maps', 'WP GPX Maps', 'administrator', 'WP-GPX-Maps', 'WP_GPX_Maps_html_page'); - } -} - -function WP_GPX_Maps_html_page() { - - $realGpxPath = substr (__FILE__, 0, strrpos(__FILE__,'/wp-content/'))."/wp-content/uploads/gpx"; - $gpxRegEx = '/.gpx$/'; - ?> - -
-

WP GPX Settings

- - - Can\'t create '.$realGpxPath.' folder. Please create it and make it writable!
- If not, you will must update the file manually! -
'; - } - } - -?> - -
- The fastest way to use this plugin: upload the file using the uploader below, than put this - shotcode: [sgpx gpx="/wp-content/uploads/gpx/< gpx file name >"] in the pages/posts. -
- -
- - - - - - - - - - - - - - - - -
Maps Width: - -
Maps Height: - -
Default Map Type: - - > This map type displays a transparent layer of major streets on satellite images.
- > This map type displays a normal street map.
- > This map type displays satellite images.
- > This map type displays maps with physical features such as terrain and vegetation.
-
- - - - -

- -

- -
- - - -
-
- - Choose a file to upload: - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FileLast modifiedFile size (Byte)
FileLast modifiedFile size (Byte)
- -
- Delete - | - Download -
-
-
-

-
-
-
-

-
-
- - - - - -
- -
- \ No newline at end of file diff --git a/wp-gpx-maps_Utils.php b/wp-gpx-maps_Utils.php index 00d9fc4..9d78dd8 100644 --- a/wp-gpx-maps_Utils.php +++ b/wp-gpx-maps_Utils.php @@ -1,96 +1,92 @@ - 0)) - { - $gpxOffset = 10; - } - - $realGpxPath = substr (__FILE__, 0, strrpos(__FILE__,'/wp-content/')).$gpxPath; - - if (file_exists($realGpxPath)) - { - - $gpx = simplexml_load_file($realGpxPath); - $gpx->registerXPathNamespace('10', 'http://www.topografix.com/GPX/1/0'); - $gpx->registerXPathNamespace('11', 'http://www.topografix.com/GPX/1/1'); - - foreach($gpx->xpath('//trkpt | //10:trkpt | //11:trkpt') as $trkpt){ - $lat = $trkpt['lat']; - $lon = $trkpt['lon']; - $ele = $trkpt->ele; - if ($lastLat == 0 && $lastLon == 0) - { - //Base Case - array_push($points, array((float)$lat,(float)$lon,(float)round($ele,1),(float)round($dist,1))); - $lastLat=$lat; - $lastLon=$lon; - $lastEle=$ele; - } - else - { - //Normal Case - $offset = calculateDistance($lat, $lon, $ele,$lastLat, $lastLon, $lastEle); - $dist = $dist + $offset; - if (((float) $offset + (float) $lastOffset) > $gpxOffset) - { - //Bigger Offset -> write coordinate - $lastOffset=0; - array_push($points, array((float)$lat,(float)$lon,(float)round($ele,1),(float)round($dist,1))); - } - else - { - //Smoller Offset -> continue.. - $lastOffset= (float) $lastOffset + (float) $offset ; - } - } - $lastLat=$lat; - $lastLon=$lon; - $lastEle=$ele; - } - } - else - { - array_push($points, array((float)0,(float)0,(float)0,(float)0)); - } - - // riduco l'array a circa 200 punti per non appensantire la pagina(mappa e grafico)! - $count=sizeof($points); - if ($count>200) - { - $f = round($count/200); - if ($f>1) - for($i=$count;$i>0;$i--) - if ($i % $f != 0) - unset($points[$i]); - } - return $points; - } - - function toRadians($degrees) - { - return $degrees * 3.1415926535897932385 / 180; - } - - function calculateDistance($lat1,$lon1,$ele1,$lat2,$lon2,$ele2) - { - //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)); - } - + 0)) + { + $gpxOffset = 10; + } + + $realGpxPath = substr (__FILE__, 0, strrpos(__FILE__,'/wp-content/')).$gpxPath; + + if (file_exists($realGpxPath)) + { + + $gpx = simplexml_load_file($realGpxPath); + $gpx->registerXPathNamespace('10', 'http://www.topografix.com/GPX/1/0'); + $gpx->registerXPathNamespace('11', 'http://www.topografix.com/GPX/1/1'); + + foreach($gpx->xpath('//trkpt | //10:trkpt | //11:trkpt') as $trkpt){ + $lat = $trkpt['lat']; + $lon = $trkpt['lon']; + $ele = $trkpt->ele; + if ($lastLat == 0 && $lastLon == 0) + { + //Base Case + array_push($points, array((float)$lat,(float)$lon,(float)round($ele,1),(float)round($dist,1))); + $lastLat=$lat; + $lastLon=$lon; + $lastEle=$ele; + } + else + { + //Normal Case + $offset = calculateDistance($lat, $lon, $ele,$lastLat, $lastLon, $lastEle); + $dist = $dist + $offset; + if (((float) $offset + (float) $lastOffset) > $gpxOffset) + { + //Bigger Offset -> write coordinate + $lastOffset=0; + array_push($points, array((float)$lat,(float)$lon,(float)round($ele,1),(float)round($dist,1))); + } + else + { + //Smoller Offset -> continue.. + $lastOffset= (float) $lastOffset + (float) $offset ; + } + } + $lastLat=$lat; + $lastLon=$lon; + $lastEle=$ele; + } + } + else + { + array_push($points, array((float)0,(float)0,(float)0,(float)0)); + } + // riduco l'array a circa 200 punti per non appensantire la pagina(mappa e grafico)! + $count=sizeof($points); + if ($count>200) + { + $f = round($count/200); + if ($f>1) + for($i=$count;$i>0;$i--) + if ($i % $f != 0) + unset($points[$i]); + } + return $points; + } + + function toRadians($degrees) + { + return $degrees * 3.1415926535897932385 / 180; + } + + function calculateDistance($lat1,$lon1,$ele1,$lat2,$lon2,$ele2) + { + //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)); + } ?> \ No newline at end of file diff --git a/wp-gpx-maps_admin.php b/wp-gpx-maps_admin.php index 2da04f3..12b4a9c 100644 --- a/wp-gpx-maps_admin.php +++ b/wp-gpx-maps_admin.php @@ -1,4 +1,13 @@ - -
+
The fastest way to use this plugin: upload the file using the uploader below, than put this shotcode: [sgpx gpx="/wp-content/uploads/gpx/< gpx file name >"] in the pages/posts. +

+ Full set of attributes: [sgpx gpx="/wp-content/uploads/gpx/< gpx file name >" width=100% mheight=450px gheight=200px mtype=SATELLITE] +

- + - - + + - - - - - +
Maps Width:
Default Options: - -
Maps Height: - + Width: , + Maps Height: , + Graph Height:
Default Map Type:Default Map Type: - > This map type displays a transparent layer of major streets on satellite images.
- > This map type displays a normal street map.
- > This map type displays satellite images.
- > This map type displays maps with physical features such as terrain and vegetation.
+ > 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.
- +

@@ -86,7 +94,8 @@ function WP_GPX_Maps_html_page() { } } - if ( is_readable ( $realGpxPath ) && $handle = opendir($realGpxPath)) { ?> + if ( is_readable ( $realGpxPath ) && $handle = opendir($realGpxPath)) { +?>