PluginProbe
Leaflet Map / 2.11.5
Leaflet Map v2.11.5
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 2.11.5, at shortcodes/class.circle-shortcode.php

88 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 * 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