PluginProbe
Leaflet Map / 2.16.2
Leaflet Map v2.16.2
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.line-shortcode.php

class.line-shortcode.php in Leaflet Map 2.16.2, at shortcodes/class.line-shortcode.php

120 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Line Shortcode
4 *
5 * Use with [leaflet-line ...]
6 *
7 * PHP Version 5.5
8 *
9 * @category Shortcode
10 * @author Benjamin J DeLong <ben@bozdoz.com>
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_Line_Shortcode extends Leaflet_Shortcode
24 {
25 /**
26 * How leaflet renders the shape
27 *
28 * @var string $type
29 */
30 public static $type = 'line';
31
32 /**
33 * Get Script for Shortcode
34 *
35 * @param string $atts shortcode attributes
36 * @param string $content optional
37 *
38 * @return string HTML
39 */
40 protected function getHTML($atts='', $content=null)
41 {
42 if (!empty($atts)) {
43 extract($atts);
44 }
45
46 $style_json = $this->LM->get_style_json($atts);
47
48 $fitbounds = empty($fitbounds) ? 0 : $fitbounds;
49
50 // backwards compatible `fitline`
51 if (!empty($fitline)) {
52 $fitbounds = $fitline;
53 }
54
55 $locations = Array();
56
57 if (!empty($addresses)) {
58 include_once LEAFLET_MAP__PLUGIN_DIR . 'class.geocoder.php';
59 $addresses = preg_split('/\s?[;|\/]\s?/', $addresses);
60 foreach ($addresses as $address) {
61 if (trim($address)) {
62 $location = new Leaflet_Geocoder($address);
63 $locations[] = Array($location->lat, $location->lng);
64 }
65 }
66 } else if (!empty($latlngs)) {
67 $latlngs = preg_split('/\s?[;|\/]\s?/', $latlngs);
68 foreach ($latlngs as $latlng) {
69 if (trim($latlng)) {
70 $locations[] = array_map('floatval', preg_split('/\s?,\s?/', $latlng));
71 }
72 }
73 } else if (!empty($coordinates)) {
74 $coordinates = preg_split('/\s?[;|\/]\s?/', $coordinates);
75 foreach ($coordinates as $xy) {
76 if (trim($xy)) {
77 $locations[] = array_map('floatval', preg_split('/\s?,\s?/', $xy));
78 }
79 }
80 }
81
82 $location_json = json_encode($locations);
83
84 $class = self::getClass();
85
86 $type = $class::$type;
87
88 $js_factory = 'L.polyline';
89 $collection = 'lines';
90
91 if ($type == 'polygon') {
92 $js_factory = 'L.polygon';
93 $locations = "[$location_json]";
94 $collection = 'polygons';
95 }
96
97 ob_start();
98 ?>
99 <script>
100 window.WPLeafletMapPlugin = window.WPLeafletMapPlugin || [];
101 window.WPLeafletMapPlugin.push(function () {
102 var previous_map = window.WPLeafletMapPlugin.getCurrentMap(),
103 shape = <?php echo $js_factory; ?>(<?php echo $location_json; ?>, <?php echo $style_json; ?>),
104 fitbounds = <?php echo $fitbounds; ?>,
105 group = window.WPLeafletMapPlugin.getCurrentGroup();
106 shape.addTo( group );
107 if (fitbounds) {
108 // zoom the map to the shape
109 previous_map.fitBounds( shape.getBounds() );
110 }
111 <?php
112 $this->LM->add_popup_to_shape($atts, $content, 'shape');
113 ?>
114 window.WPLeafletMapPlugin.<?php echo $collection; ?>.push( shape );
115 });
116 </script>
117 <?php
118 return ob_get_clean();
119 }
120 }