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