diff --git a/assets/plugin.js b/assets/plugin.js
index 8a395a3..e6ea5b8 100644
--- a/assets/plugin.js
+++ b/assets/plugin.js
@@ -21,7 +21,7 @@
jQuery( function() {
// setup variables
_ui_leaflet_maps = {}; // global object for further access
-
+ _ui_leaflet_maps_position = {};
// grab all maps
@@ -31,9 +31,16 @@ jQuery( function() {
var strMapID = jQuery( this ).attr('id');
var config = jQuery( this ).data('leaflet-config');
+
+
+
//console.log( 'config:', config, ' mapID: ', strMapID );
if( typeof( strMapID ) != 'undefined' && strMapID != '' && typeof( config ) == 'object' ) {
+
+
+
+
// fire custom init event
jQuery( document ).trigger( '_ui_leaflet_map_init', {
'map_id': strMapID,
@@ -70,6 +77,12 @@ jQuery( function() {
+ var strAttribution = 'Map data © OpenStreetMap contributors, CC-BY-SA, ';
+
+ if( typeof( config.osm_attribution ) != 'undefined' ) {
+ strAttribution = config.osm_attribution;
+ }
+
// add tile layer (server)
L.tileLayer( map_layer, {
@@ -77,8 +90,7 @@ jQuery( function() {
minZoom: 0,
zoom: 16,
subdomains: 'abc',
- attribution: 'Map data © OpenStreetMap contributors, ' +
- 'CC-BY-SA, ',
+ attribution: strAttribution,
}).addTo( _ui_leaflet_maps[strMapID] );
if( _use_zoom_control == false ) {
@@ -125,17 +137,18 @@ jQuery( function() {
*/
if( typeof( config.use_locate ) != 'undefined' && config.use_locate != false ) {
- console.info( 'using locate' );
+ //console.info( 'using locate' );
//if( typeof( config.locate_popup ) != 'undefined' ) {
var popup = L.popup();
+
function geolocationErrorOccurred(geolocationSupported, popup, latLng) {
popup.setLatLng(latLng);
popup.setContent(geolocationSupported ?
- 'Error: The Geolocation service failed.' :
+ 'Error: The Geolocation service failed.' :
'Error: This browser doesn\'t support geolocation.');
//popup.openOn(geolocationMap);
@@ -150,6 +163,10 @@ jQuery( function() {
lng: position.coords.longitude
};
+
+ // access in global scope on detected position
+ _ui_leaflet_maps_position[ strMapID ] = position;
+
var strPopupContent = 'This is your current position.';
if( typeof( config.locate_popup ) != 'undefined' ) {
diff --git a/includes/base.class.php b/includes/base.class.php
index 41ad0c7..1f0a549 100644
--- a/includes/base.class.php
+++ b/includes/base.class.php
@@ -11,11 +11,38 @@ class _ui_LeafletBase {
public $pluginPath = '';
public $pluginURL = '';
- public $pluginVersion = '0.7';
+ public $pluginVersion = '0.9.5';
public $debug = false;
public $test = false;
+
+ function get_plugin_prefix() {
+ $return = '';
+
+ if( isset( $this->pluginPrefix ) ) {
+ $return = $this->pluginPrefix;
+ } elseif( defined( '_UI_LEAFLET_MAP_PREFIX' ) ) {
+ $return = _UI_LEAFLET_MAP_PREFIX;
+ }
+
+ return $return;
+ }
+
+ function add_plugin_prefix( $string = '', $divider = '_' ) {
+ $prefix = $this->get_plugin_prefix();
+
+ $return = $prefix . $divider . $string;
+
+ if( !empty( $prefix ) && !empty( $divider) && substr( $prefix, -1, 1 ) == $divider ) {
+ $return = $prefix . $string;
+ }
+
+ return $return;
+ }
+
+
+
function enable_debug() {
$this->debug = true;
}
diff --git a/includes/leaflet-map.class.php b/includes/leaflet-map.class.php
index 03d1f4b..51d67d7 100644
--- a/includes/leaflet-map.class.php
+++ b/includes/leaflet-map.class.php
@@ -2,14 +2,16 @@
/**
* Insert leaflet map plus options into post (or anywhere else)
*
- * @version 0.9.4
+ * @version 0.9.5
*/
class _ui_LeafletIntegration extends _ui_LeafletBase {
public $pluginPrefix = 'ui_leaflet_',
$pluginPath = '',
$pluginURL = '',
- $pluginVersion = '0.9.4';
+ $pluginVersion = '0.9.5';
+
+ protected $bPreloadAssets = false;
public static function init() {
@@ -119,6 +121,21 @@ function preload_assets() {
$this->bPreloadAssets = true;
}
+ /**
+ * Use filter to enforce assets loading
+ * @hook _ui_leaflet_load_assets
+ * @since v0.9.5
+ */
+ $load_assets_hook = apply_filters( $this->add_plugin_prefix ('load_assets' ), false );
+
+ if( !empty( $load_assets_hook ) ) {
+ $this->bPreloadAssets = true;
+ }
+
+ /**
+ * Use constant to enforce assets loading
+ */
+
if( defined( '_UI_LEAFLET_LOAD_ASSETS' ) ) { // enforce assets loading
$this->bPreloadAssets = true;
}
@@ -508,6 +525,7 @@ function shortcode_map( $attr = array(), $content = '' ) {
'zoom_position' => '',
'use_locate' => '',
'locate_marker' => '',
+ 'markers' => '',
), $attr );
@@ -737,6 +755,54 @@ function shortcode_map( $attr = array(), $content = '' ) {
return $return;
}
+
+ /**
+ * Extract markers from shortcode attribute
+ *
+ * @since 0.9.5 (future 0.10)
+ * @param string $data String to parse into markers.
+ * @param boolean $return_json Return markers as JSON data. Defaults to TRUE.
+ * @return mixed $markers Either returns array OR pre-parsed marker JSON, or an empty string, if an error has occured (eg. empty input string or missing second coordinate).
+ */
+
+ function get_markers( $data = '', $return_json = true ) {
+ $return = '';
+
+ if( !empty( $data ) && strpos( $data, ',' ) !== false ) {
+
+ if( strpos( $data, ';' ) !== false ) {
+ $arrMarkerData = explode( ';', $data );
+ } else {
+ $arrMarkerData = array( $data );
+ }
+
+ // extract marker data
+
+ foreach( $arrMarkerData as $strRawMarker ) {
+ $x = explode( ',', trim( $strRawMarker ) );
+
+ // lat, long, text
+ $arrMarkers[] = array(
+ 'lat' => trim( $x[ 0 ] ),
+ 'lng' => trim( $x[ 1 ] ),
+ 'text' => ( !empty( $x2[ 2 ] ) ? trim( $x[ 2 ] ) : '' ),
+ );
+
+ }
+ }
+
+ if( !empty( $arrMarkers ) ) {
+ $return = $arrMarkers;
+
+ if( !empty( $return_json ) ) { // return fully qualified marker json data
+ $return = json_encode( $arrMarkers, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT );
+ }
+ }
+
+
+ return $return;
+ }
+
/**
* NOTE: Preparation for 0.8+
*/
diff --git a/readme.txt b/readme.txt
index cb70924..43d5985 100644
--- a/readme.txt
+++ b/readme.txt
@@ -78,6 +78,10 @@ All available shortcode attributes:
* search_position - where to position the search field control; available options are: 'topleft', 'topright', 'bottomleft', 'bottomright'
* use_locate - Locate user; defaults to false. Set to 'true', '1' or 'yes' to enable it.
* locate_marker - Optional location marker for the locate option. set to 'true', '1' or 'yes' to enable it, or enter some fancy text to be displayed in place of the defaul 'This is your current position' text.
+* marker_icon_class - defaults to 'fa fa-fw fa-marker-map fa-2x' (= FontAwesome 4.x / Fork Awesome 1.x).
+* marker_icon_fa_class - Font/ForkAwesome; if no 'fa-' is given, the plugin automagically adds it
+* marker_icon_far_class - Fort Awesome 5.x; dito
+* marker_icon_html - Custom html source coeefor the icon, eg. an or