Skip to content

Commit ecbf5a0

Browse files
author
bozdoz
committed
update to 2.9; added gpx shortcode
1 parent 2dc6465 commit ecbf5a0

File tree

8 files changed

+58
-62
lines changed

8 files changed

+58
-62
lines changed

class.leaflet-map.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class Leaflet_Map {
4444
'file' => 'class.kml-shortcode.php',
4545
'class' => 'Leaflet_Kml_Shortcode'
4646
),
47+
'leaflet-gpx' => array(
48+
'file' => 'class.gpx-shortcode.php',
49+
'class' => 'Leaflet_Gpx_Shortcode'
50+
),
4751
'leaflet-line' => array(
4852
'file' => 'class.line-shortcode.php',
4953
'class' => 'Leaflet_Line_Shortcode'
@@ -177,12 +181,10 @@ public static function enqueue_and_register () {
177181
}
178182

179183
// optional ajax geojson plugin
180-
wp_register_script('leaflet_ajax_geojson_js', plugins_url('scripts/leaflet-ajax-geojson.js', __FILE__), Array('leaflet_js',), self::$version, false);
181-
182184
wp_register_script('tmcw_togeojson', 'https://cdn.rawgit.com/mapbox/togeojson/master/togeojson.js', Array('jquery'), self::$version, false);
183185

184-
wp_register_script('leaflet_ajax_kml_js', plugins_url('scripts/leaflet-ajax-kml.js', __FILE__), Array('tmcw_togeojson', 'leaflet_js', 'leaflet_ajax_geojson_js'), self::$version, false);
185-
186+
wp_register_script('leaflet_ajax_geojson_js', plugins_url('scripts/leaflet-ajax-geojson.js', __FILE__), Array('tmcw_togeojson', 'leaflet_js'), self::$version, false);
187+
186188
/* run a construct function in the document head for subsequent functions to use (it is lightweight) */
187189
wp_enqueue_script('leaflet_map_construct', plugins_url('scripts/construct-leaflet-map.js', __FILE__), Array(), self::$version, false);
188190
}

leaflet-map.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Description: A plugin for creating a Leaflet JS map with a shortcode. Boasts two free map tile services and three free geocoders.
66
Author: bozdoz
77
Author URI: https://twitter.com/bozdoz/
8-
Version: 2.8.6
8+
Version: 2.9
99
License: GPL2
1010
1111
Leaflet Map is free software: you can redistribute it and/or modify

readme.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Contributors: bozdoz, Remigr, nielsalstrup, jeromelebleu
66
Donate link: https://www.paypal.me/bozdoz
77
Tags: leaflet, map, mobile, javascript, openstreetmap, mapquest, interactive
88
Requires at least: 3.0.1
9-
Tested up to: 4.8.1
10-
Version: 2.8.6
11-
Stable tag: 2.8.6
9+
Tested up to: 4.9
10+
Version: 2.9
11+
Stable tag: 2.9
1212
License: GPLv2
1313
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1414

@@ -79,9 +79,9 @@ Yes. Update to the newest plugin version, and reset defaults in settings. You c
7979

8080
Yes, just give it a source URL: `[leaflet-geojson src="https://example.com/path/to.geojson"]` It will also support leaflet geojson styles or geojson.io styles. Add a popup message with `[leaflet-geojson popup_text="hello!"]`, or add HTML by adding it to the content of the shortcode: `[leaflet-geojson]<a href="#">Link here</a>[/leaflet-geojson]` or identify a geojson property with `popup_property`, and each shape will use its own popup text if available.
8181

82-
= Can I add kml? =
82+
= Can I add kml/gpx? =
8383

84-
Sure!? Use the same attributes as leaflet-geojson (above), but use the `[leaflet-kml]` shortcode.
84+
Sure!? Use the same attributes as leaflet-geojson (above), but use the `[leaflet-kml]` or `[leaflet-gpx]` shortcode.
8585

8686
= Can I add a message to a marker? =
8787

@@ -120,6 +120,9 @@ Yes: use the keyword `attribution` in your shortcode (semi-colon separated list
120120

121121
== Changelog ==
122122

123+
= 2.8.6 =
124+
* Added [leaflet-gpx] for GPX format
125+
123126
= 2.8.6 =
124127
* Fix image shortcode ratio
125128

@@ -260,6 +263,9 @@ Yes: use the keyword `attribution` in your shortcode (semi-colon separated list
260263

261264
== Upgrade Notice ==
262265

266+
= 2.8.6 =
267+
Added [leaflet-gpx] for GPX format
268+
263269
= 2.8.6 =
264270
Fix image shortcode ratio
265271

scripts/leaflet-ajax-geojson.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
L.AjaxGeoJSON = L.GeoJSON.extend({
2-
options : {},
2+
options : {
3+
type: 'json' // 'json|kml|gpx'
4+
},
35

46
initialize : function (url, options) {
57
L.setOptions(this, options);
@@ -9,6 +11,7 @@ L.AjaxGeoJSON = L.GeoJSON.extend({
911

1012
onAdd : function (map) {
1113
var _this = this,
14+
type = this.options.type,
1215
xhr;
1316

1417
this.map = map;
@@ -22,7 +25,11 @@ L.AjaxGeoJSON = L.GeoJSON.extend({
2225
var data;
2326
if (xhr.readyState === xhr.DONE &&
2427
xhr.status === 200) {
25-
data = JSON.parse( xhr.responseText );
28+
if (type === 'json') {
29+
data = JSON.parse( xhr.responseText );
30+
} else if (['kml', 'gpx'].indexOf(type) !== -1) {
31+
data = window.toGeoJSON[ type ]( xhr.responseXML );
32+
}
2633
_this.json = data;
2734
_this.layer.addData( data );
2835
_this.fire('ready');

scripts/leaflet-ajax-kml.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

shortcodes/class.geojson-shortcode.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,24 @@
1414
include_once(LEAFLET_MAP__PLUGIN_DIR . 'shortcodes/class.shortcode.php');
1515

1616
class Leaflet_Geojson_Shortcode extends Leaflet_Shortcode {
17-
/**
18-
* @var string $wp_script to enqueue
19-
*/
20-
public static $wp_script = 'leaflet_ajax_geojson_js';
21-
/**
22-
* @var string $L_method how leaflet renders the src
23-
*/
24-
public static $L_method = 'ajaxGeoJson';
2517
/**
2618
* @var string $default_src default src
2719
*/
2820
public static $default_src = 'https://rawgit.com/bozdoz/567817310f102d169510d94306e4f464/raw/2fdb48dafafd4c8304ff051f49d9de03afb1718b/map.geojson';
2921

22+
/**
23+
* @var string $type how leaflet renders the src
24+
*/
25+
public static $type = 'json';
26+
3027
protected function getHTML ($atts, $content) {
3128

3229
// need to get the called class to extend above variables
3330
$class = self::getClass();
3431

3532
if ($atts) extract($atts);
3633

37-
wp_enqueue_script( $class::$wp_script );
34+
wp_enqueue_script( 'leaflet_ajax_geojson_js' );
3835

3936
if ($content) {
4037
$content = str_replace(array("\r\n", "\n", "\r"), '<br>', $content);
@@ -75,7 +72,8 @@ protected function getHTML ($atts, $content) {
7572
'stroke-opacity' : 'opacity',
7673
'stroke-width' : 'width',
7774
},
78-
layer = L.<?php echo $class::$L_method; ?>(src, {
75+
layer = L.ajaxGeoJson(src, {
76+
type: '<?php echo $class::$type; ?>',
7977
style : layerStyle,
8078
onEachFeature : onEachFeature
8179
}),

shortcodes/class.gpx-shortcode.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* GPX Shortcode
4+
*
5+
* Use with [leaflet-gpx src="..."]
6+
*
7+
* @param array $atts user-input array
8+
* @return string JavaScript
9+
*/
10+
11+
// Exit if accessed directly
12+
if ( !defined( 'ABSPATH' ) ) exit;
13+
14+
include_once(LEAFLET_MAP__PLUGIN_DIR . 'shortcodes/class.geojson-shortcode.php');
15+
16+
class Leaflet_Gpx_Shortcode extends Leaflet_Geojson_Shortcode {
17+
/**
18+
* @var string $type how leaflet renders the src
19+
*/
20+
public static $type = 'gpx';
21+
}

shortcodes/class.kml-shortcode.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@
1515

1616
class Leaflet_Kml_Shortcode extends Leaflet_Geojson_Shortcode {
1717
/**
18-
* @var string $wp_script to enqueue
18+
* @var string $type how leaflet renders the src
1919
*/
20-
public static $wp_script = 'leaflet_ajax_kml_js';
21-
/**
22-
* @var string $L_method how leaflet renders the src
23-
*/
24-
public static $L_method = 'ajaxKML';
20+
public static $type = 'kml';
2521
/**
2622
* @var string $default_src default src
2723
*/

0 commit comments

Comments
 (0)