forked from bozdoz/wp-plugin-leaflet-map
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2.19.0 - Adds [leaflet-scale] shortcode; closes bozdoz#57
- Loading branch information
Benjamin DeLong
committed
Jul 15, 2020
1 parent
017db3c
commit 6fa574e
Showing
11 changed files
with
132 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* Scale Shortcode | ||
* | ||
* Use with [leaflet-scale ...] | ||
* | ||
* @category Shortcode | ||
* @author Benjamin J DeLong <[email protected]> | ||
*/ | ||
|
||
// Exit if accessed directly | ||
if (!defined('ABSPATH')) { | ||
exit; | ||
} | ||
|
||
require_once LEAFLET_MAP__PLUGIN_DIR . 'shortcodes/class.shortcode.php'; | ||
|
||
/** | ||
* Leaflet Scale Shortcode Class | ||
*/ | ||
class Leaflet_Scale_Shortcode extends Leaflet_Shortcode | ||
{ | ||
/** | ||
* Get Script for Shortcode | ||
* | ||
* @param string $atts shortcode attributes | ||
* @param string $content optional | ||
* | ||
* @return string HTML | ||
*/ | ||
protected function getHTML($atts='', $content=null) | ||
{ | ||
if (!empty($atts)) { | ||
extract($atts); | ||
} | ||
|
||
/** | ||
* Options: | ||
* https://leafletjs.com/reference.html#control-scale | ||
*/ | ||
|
||
$options = array( | ||
'maxWidth' => isset($maxwidth) ? $maxwidth : null, | ||
'metric' => isset($metric) ? $metric : null, | ||
'imperial' => isset($imperial) ? $imperial : null, | ||
'updateWhenIdle' => isset($updateWhenIdle) ? $updateWhenIdle : null, | ||
'position' => isset($position) ? $position : null, | ||
); | ||
|
||
$filters = array( | ||
'maxWidth' => FILTER_VALIDATE_INT, | ||
'metric' => FILTER_VALIDATE_BOOLEAN, | ||
'imperial' => FILTER_VALIDATE_BOOLEAN, | ||
'updateWhenIdle' => FILTER_VALIDATE_BOOLEAN, | ||
'position' => FILTER_SANITIZE_STRING, | ||
); | ||
|
||
$options = $this->LM->json_sanitize($options, $filters); | ||
|
||
ob_start(); | ||
?> | ||
<script> | ||
// push deferred function | ||
window.WPLeafletMapPlugin = window.WPLeafletMapPlugin || []; | ||
window.WPLeafletMapPlugin.push(function () { | ||
window.WPLeafletMapPlugin.createScale(<?php echo $options; ?>); | ||
}); | ||
</script> | ||
<?php | ||
return ob_get_clean(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters