Skip to content

Commit

Permalink
update to 2.9; added gpx shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
bozdoz committed Nov 20, 2017
1 parent 2dc6465 commit ecbf5a0
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 62 deletions.
10 changes: 6 additions & 4 deletions class.leaflet-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class Leaflet_Map {
'file' => 'class.kml-shortcode.php',
'class' => 'Leaflet_Kml_Shortcode'
),
'leaflet-gpx' => array(
'file' => 'class.gpx-shortcode.php',
'class' => 'Leaflet_Gpx_Shortcode'
),
'leaflet-line' => array(
'file' => 'class.line-shortcode.php',
'class' => 'Leaflet_Line_Shortcode'
Expand Down Expand Up @@ -177,12 +181,10 @@ public static function enqueue_and_register () {
}

// optional ajax geojson plugin
wp_register_script('leaflet_ajax_geojson_js', plugins_url('scripts/leaflet-ajax-geojson.js', __FILE__), Array('leaflet_js',), self::$version, false);

wp_register_script('tmcw_togeojson', 'https://cdn.rawgit.com/mapbox/togeojson/master/togeojson.js', Array('jquery'), self::$version, false);

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);

wp_register_script('leaflet_ajax_geojson_js', plugins_url('scripts/leaflet-ajax-geojson.js', __FILE__), Array('tmcw_togeojson', 'leaflet_js'), self::$version, false);
/* run a construct function in the document head for subsequent functions to use (it is lightweight) */
wp_enqueue_script('leaflet_map_construct', plugins_url('scripts/construct-leaflet-map.js', __FILE__), Array(), self::$version, false);
}
Expand Down
2 changes: 1 addition & 1 deletion leaflet-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Description: A plugin for creating a Leaflet JS map with a shortcode. Boasts two free map tile services and three free geocoders.
Author: bozdoz
Author URI: https://twitter.com/bozdoz/
Version: 2.8.6
Version: 2.9
License: GPL2
Leaflet Map is free software: you can redistribute it and/or modify
Expand Down
16 changes: 11 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Contributors: bozdoz, Remigr, nielsalstrup, jeromelebleu
Donate link: https://www.paypal.me/bozdoz
Tags: leaflet, map, mobile, javascript, openstreetmap, mapquest, interactive
Requires at least: 3.0.1
Tested up to: 4.8.1
Version: 2.8.6
Stable tag: 2.8.6
Tested up to: 4.9
Version: 2.9
Stable tag: 2.9
License: GPLv2
License URI: https://www.gnu.org/licenses/gpl-2.0.html

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

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.

= Can I add kml? =
= Can I add kml/gpx? =

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

= Can I add a message to a marker? =

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

== Changelog ==

= 2.8.6 =
* Added [leaflet-gpx] for GPX format

= 2.8.6 =
* Fix image shortcode ratio

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

== Upgrade Notice ==

= 2.8.6 =
Added [leaflet-gpx] for GPX format

= 2.8.6 =
Fix image shortcode ratio

Expand Down
11 changes: 9 additions & 2 deletions scripts/leaflet-ajax-geojson.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
L.AjaxGeoJSON = L.GeoJSON.extend({
options : {},
options : {
type: 'json' // 'json|kml|gpx'
},

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

onAdd : function (map) {
var _this = this,
type = this.options.type,
xhr;

this.map = map;
Expand All @@ -22,7 +25,11 @@ L.AjaxGeoJSON = L.GeoJSON.extend({
var data;
if (xhr.readyState === xhr.DONE &&
xhr.status === 200) {
data = JSON.parse( xhr.responseText );
if (type === 'json') {
data = JSON.parse( xhr.responseText );
} else if (['kml', 'gpx'].indexOf(type) !== -1) {
data = window.toGeoJSON[ type ]( xhr.responseXML );
}
_this.json = data;
_this.layer.addData( data );
_this.fire('ready');
Expand Down
34 changes: 0 additions & 34 deletions scripts/leaflet-ajax-kml.js

This file was deleted.

18 changes: 8 additions & 10 deletions shortcodes/class.geojson-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,24 @@
include_once(LEAFLET_MAP__PLUGIN_DIR . 'shortcodes/class.shortcode.php');

class Leaflet_Geojson_Shortcode extends Leaflet_Shortcode {
/**
* @var string $wp_script to enqueue
*/
public static $wp_script = 'leaflet_ajax_geojson_js';
/**
* @var string $L_method how leaflet renders the src
*/
public static $L_method = 'ajaxGeoJson';
/**
* @var string $default_src default src
*/
public static $default_src = 'https://rawgit.com/bozdoz/567817310f102d169510d94306e4f464/raw/2fdb48dafafd4c8304ff051f49d9de03afb1718b/map.geojson';

/**
* @var string $type how leaflet renders the src
*/
public static $type = 'json';

protected function getHTML ($atts, $content) {

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

if ($atts) extract($atts);

wp_enqueue_script( $class::$wp_script );
wp_enqueue_script( 'leaflet_ajax_geojson_js' );

if ($content) {
$content = str_replace(array("\r\n", "\n", "\r"), '<br>', $content);
Expand Down Expand Up @@ -75,7 +72,8 @@ protected function getHTML ($atts, $content) {
'stroke-opacity' : 'opacity',
'stroke-width' : 'width',
},
layer = L.<?php echo $class::$L_method; ?>(src, {
layer = L.ajaxGeoJson(src, {
type: '<?php echo $class::$type; ?>',
style : layerStyle,
onEachFeature : onEachFeature
}),
Expand Down
21 changes: 21 additions & 0 deletions shortcodes/class.gpx-shortcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* GPX Shortcode
*
* Use with [leaflet-gpx src="..."]
*
* @param array $atts user-input array
* @return string JavaScript
*/

// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

include_once(LEAFLET_MAP__PLUGIN_DIR . 'shortcodes/class.geojson-shortcode.php');

class Leaflet_Gpx_Shortcode extends Leaflet_Geojson_Shortcode {
/**
* @var string $type how leaflet renders the src
*/
public static $type = 'gpx';
}
8 changes: 2 additions & 6 deletions shortcodes/class.kml-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@

class Leaflet_Kml_Shortcode extends Leaflet_Geojson_Shortcode {
/**
* @var string $wp_script to enqueue
* @var string $type how leaflet renders the src
*/
public static $wp_script = 'leaflet_ajax_kml_js';
/**
* @var string $L_method how leaflet renders the src
*/
public static $L_method = 'ajaxKML';
public static $type = 'kml';
/**
* @var string $default_src default src
*/
Expand Down

0 comments on commit ecbf5a0

Please sign in to comment.