Skip to content

Commit

Permalink
Latest changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
fwolf committed Mar 18, 2020
1 parent a458e36 commit 0e79385
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 9 deletions.
27 changes: 22 additions & 5 deletions assets/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
jQuery( function() {
// setup variables
_ui_leaflet_maps = {}; // global object for further access
_ui_leaflet_maps_position = {};

// grab all maps

Expand All @@ -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,
Expand Down Expand Up @@ -70,15 +77,20 @@ jQuery( function() {



var strAttribution = 'Map data &copy; <a href="https://openstreetmap.org">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ';

if( typeof( config.osm_attribution ) != 'undefined' ) {
strAttribution = config.osm_attribution;
}


// add tile layer (server)
L.tileLayer( map_layer, {
maxZoom: 18,
minZoom: 0,
zoom: 16,
subdomains: 'abc',
attribution: 'Map data &copy; <a href="https://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ',
attribution: strAttribution,
}).addTo( _ui_leaflet_maps[strMapID] );

if( _use_zoom_control == false ) {
Expand Down Expand Up @@ -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 ?
'<strong>Error:</strong> The Geolocation service failed.' :
'<strong>Error:</strong> The Geolocation service failed.' :
'<strong>Error:</strong> This browser doesn\'t support geolocation.');
//popup.openOn(geolocationMap);

Expand All @@ -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 = '<strong>This</strong> is your current position.';

if( typeof( config.locate_popup ) != 'undefined' ) {
Expand Down
29 changes: 28 additions & 1 deletion includes/base.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
70 changes: 68 additions & 2 deletions includes/leaflet-map.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -508,6 +525,7 @@ function shortcode_map( $attr = array(), $content = '' ) {
'zoom_position' => '',
'use_locate' => '',
'locate_marker' => '',
'markers' => '',
), $attr );


Expand Down Expand Up @@ -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+
*/
Expand Down
12 changes: 11 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,18 @@ 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 <img src=".." /> or <svg> ..


= Available tile service handles =

* default - uses the OSM mapnik tile server
* osm_bw - OSM mapnik in black and white
* mapquest

* work in progress: proper filter hook + JSON file to read in the tile service handling / tile providers automagically

= Q. Where to place the marker text? =
A. Right inside the shortcode, eg. `[ui_leaflet_map]your <strong>nifty</strong> HTML text :)[/ui_leaflet_map]
Expand Down Expand Up @@ -162,6 +166,12 @@ https://github.com/ginsterbusch/ui-leaflet-integration/issues

== Changelog ==

= 0.9.4 =
* SSL-related bugfixes
* Improved icon classes (use Fork/FontAwesome, Fort Awesome icons, your custom icon library OR replace the complete icon HTML code with your own)
* Default marker is now the map-marker instead of the -pin
* of corpse I forgot to update this readme-file again (not to mention the wiki) xD

= 0.9.3 =

* Bugfixes for the custom extension loader
Expand Down

0 comments on commit 0e79385

Please sign in to comment.