PluginProbe
Leaflet Map / trunk
Leaflet Map vtrunk
3.4.7 3.4.6 trunk 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.11.5 2.12.0 2.13.0 2.14.0 2.15.0 2.16.0 2.16.1 2.16.2 2.17.0 2.17.1 2.17.2 2.17.3 2.18.0 2.19.0 2.19.1 All 49 releases
leaflet-map / shortcodes / class.circle-shortcode.php

class.circle-shortcode.php in Leaflet Map trunk, at shortcodes/class.circle-shortcode.php

90 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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