| 1 |
<?php |
| 2 |
/** |
| 3 |
* Circle Shortcode |
| 4 |
* |
| 5 |
* Use with [leaflet-circle ...] |
| 6 |
* |
| 7 |
* @category Shortcode |
| 8 |
* @author Peter Uithoven <peter@peteruithoven.nl> |
| 9 |
*/ |
| 10 |
|
| 11 |
// Exit if accessed directly |
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
require_once LEAFLET_MAP__PLUGIN_DIR . 'shortcodes/class.shortcode.php'; |
| 17 |
|
| 18 |
/** |
| 19 |
* Leaflet Line Shortcode Class |
| 20 |
*/ |
| 21 |
class Leaflet_Circle_Shortcode extends Leaflet_Shortcode |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Get Script for Shortcode |
| 25 |
* |
| 26 |
* @param string $atts shortcode attributes |
| 27 |
* @param string $content optional |
| 28 |
* |
| 29 |
* @return string HTML |
| 30 |
*/ |
| 31 |
protected function getHTML($atts='', $content=null) |
| 32 |
{ |
| 33 |
if (!empty($atts)) { |
| 34 |
extract($atts, EXTR_SKIP); |
| 35 |
} |
| 36 |
|
| 37 |
$style_json = $this->LM->get_style_json($atts); |
| 38 |
|
| 39 |
$fitbounds = empty($fitbounds) ? 0 : $fitbounds; |
| 40 |
$fitbounds = filter_var($fitbounds, FILTER_VALIDATE_BOOLEAN); |
| 41 |
|
| 42 |
if (!empty($address)) { |
| 43 |
include_once LEAFLET_MAP__PLUGIN_DIR . 'class.geocoder.php'; |
| 44 |
$location = new Leaflet_Geocoder( $address ); |
| 45 |
$lat = $location->lat; |
| 46 |
$lng = $location->lng; |
| 47 |
} |
| 48 |
|
| 49 |
$lat = empty($lat) ? ( empty($y) ? '0' : $y ) : $lat; |
| 50 |
$lng = empty($lng) ? ( empty($x) ? '0' : $x ) : $lng; |
| 51 |
|
| 52 |
// validate lat/lng |
| 53 |
$lat = $this->LM->filter_float($lat); |
| 54 |
$lng = $this->LM->filter_float($lng); |
| 55 |
|
| 56 |
$radius = empty($radius) ? '1000' : $radius; |
| 57 |
|
| 58 |
$radius = $this->LM->filter_float($radius); |
| 59 |
|
| 60 |
ob_start(); |
| 61 |
?>/*<script>*/ |
| 62 |
var previous_map = window.WPLeafletMapPlugin.getCurrentMap(); |
| 63 |
var group = window.WPLeafletMapPlugin.getCurrentGroup(); |
| 64 |
var fitbounds = <?php echo $fitbounds ? '1' : '0'; ?>; |
| 65 |
var is_image = previous_map.is_image_map; |
| 66 |
var lat = <?php echo $lat; ?>; |
| 67 |
var lng = <?php echo $lng; ?>; |
| 68 |
var radius = <?php echo $radius; ?>; |
| 69 |
// update lat lng to previous map's center |
| 70 |
if (!lat && !lng && !is_image) { |
| 71 |
var map_center = previous_map.getCenter(); |
| 72 |
lat = map_center.lat; |
| 73 |
lng = map_center.lng; |
| 74 |
} |
| 75 |
var circle = L.circle([lat, lng], {radius: radius}); |
| 76 |
circle.setStyle(<?php echo $style_json; ?>); |
| 77 |
circle.addTo( group ); |
| 78 |
window.WPLeafletMapPlugin.circles.push( circle ); |
| 79 |
if (fitbounds) { |
| 80 |
// zoom the map to the polyline |
| 81 |
previous_map.fitBounds( circle.getBounds() ); |
| 82 |
}<?php |
| 83 |
$this->LM->add_popup_to_shape($atts, $content, 'circle'); |
| 84 |
|
| 85 |
$script = ob_get_clean(); |
| 86 |
|
| 87 |
return $this->wrap_script($script, 'WPLeafletCircleShortcode'); |
| 88 |
} |
| 89 |
} |
| 90 |
|