PluginProbe
Leaflet Map / 3.4.5
Leaflet Map v3.4.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
← All changes | shortcodes/class.image-shortcode.php +28 -71 2.17.23.4.5 View file →
@@ -5,10 +5,8 @@
5 5 * Displays map with [leaflet-image src="path/to/image.jpg"]
6 6 *
7 7 * JavaScript equivalent : L.imageOverlay('path/to/image.jpg');
8 8 *
9 - * PHP Version 5.5
10 - *
11 9 * @category Shortcode
12 10 * @author Benjamin J DeLong <ben@bozdoz.com>
13 11 */
14 12
@@ -35,80 +33,39 @@
35 33 protected function getHTML($atts='', $content=null)
36 34 {
37 35 extract($this->getAtts($atts));
38 36
37 + $x = empty($x) ? 0 : $this->LM->filter_float($x);
38 + $y = empty($y) ? 0 : $this->LM->filter_float($y);
39 +
39 40 /* only required field for image map (src/source) */
40 41 $src = empty($src) ? '' : $src;
41 42 $source = empty($source) ? 'https://picsum.photos/1000/1000/' : $source;
42 43 $source = empty($src) ? $source : $src;
43 44
44 - ob_start();
45 - ?>
46 - <script>
47 - (function () {
48 - // TODO: This could/should be abstracted so we don't duplicate code in map-shortcode
49 - var scriptsSoFar = document.getElementsByTagName('script');
50 - var thisScript = scriptsSoFar[scriptsSoFar.length - 1];
51 - // create map HTMLElement
52 - var mapElement = document.createElement('div');
53 - mapElement.className = 'leaflet-map';
54 - mapElement.style.height = "<?php echo $height; ?>";
55 - mapElement.style.width = "<?php echo $width; ?>";
56 - // insert just before this script
57 - thisScript.parentNode.insertBefore(mapElement, thisScript);
58 - // push deferred map creation function
59 - window.WPLeafletMapPlugin = window.WPLeafletMapPlugin || [];
60 - window.WPLeafletMapPlugin.push(function () {
61 - var map,
62 - options = L.Util.extend({}, {
63 - maxZoom: <?php echo $max_zoom; ?>,
64 - minZoom: <?php echo $min_zoom; ?>,
65 - zoomControl: <?php echo $zoomcontrol; ?>,
66 - scrollWheelZoom: <?php echo $scrollwheel; ?>,
67 - doubleClickZoom: <?php echo $doubleclickzoom; ?>,
68 - attributionControl: false
69 - }, <?php echo $more_options; ?>, {
70 - crs: L.CRS.Simple
71 - }),
72 - image_src = '<?php echo $source; ?>',
73 - img = new Image(),
74 - zoom = <?php echo $zoom; ?>;
75 - img.onload = function() {
76 - var h = img.height,
77 - w = img.width,
78 - projected_zoom = zoom + 1,
79 - southWest = map.unproject([-w, h], projected_zoom),
80 - northEast = map.unproject([w, -h], projected_zoom),
81 - bounds = new L.LatLngBounds(southWest, northEast);
82 - L.imageOverlay( image_src, bounds ).addTo( map );
83 - map.setMaxBounds(bounds);
84 - };
85 - img.src = image_src;
86 - map = L.map(mapElement, options).setView([0, 0], zoom);
87 - // make it known that it is an image map
88 - map.is_image_map = true;
89 - if (<?php echo $fitbounds; ?>) {
90 - map._shouldFitBounds = true;
91 - }
92 - <?php
93 - if ($attribution) {
94 - /* add any attributions, semi-colon-separated */
95 - $attributions = explode(';', $attribution);
96 - ?>
97 - var attControl = L.control.attribution({prefix:false}).addTo(map);
98 - <?php
99 - foreach ($attributions as $a) {
100 - ?>
101 - attControl.addAttribution('<?php echo trim($a); ?>');
102 - <?php
103 - }
104 - }
105 - ?>
106 - window.WPLeafletMapPlugin.maps.push( map );
107 - window.WPLeafletMapPlugin.images.push( img );
108 - }); // end add
109 - })(); // end IIFE
110 - </script>
111 - <?php
112 - return ob_get_clean();
45 + ob_start(); ?>/*<script>*/
46 +var options = L.Util.extend({}, {
47 + attributionControl: false
48 + }, <?php echo $map_options; ?>, {
49 + crs: L.CRS.Simple
50 + });
51 +var image_src = '<?php echo htmlspecialchars($source, ENT_QUOTES); ?>';
52 +var img = new Image();
53 +var zoom = <?php echo $zoom; ?>;
54 +var map = window.WPLeafletMapPlugin.createImageMap(options).setView([<?php echo $x; ?>, <?php echo $y; ?>], zoom);
55 +img.onload = function() {
56 + var h = img.height,
57 + w = img.width,
58 + projected_zoom = zoom + 1,
59 + southWest = map.unproject([-w, h], projected_zoom),
60 + northEast = map.unproject([w, -h], projected_zoom),
61 + bounds = new L.LatLngBounds(southWest, northEast);
62 + L.imageOverlay( image_src, bounds ).addTo( map );
63 + map.setMaxBounds(bounds);
64 +};
65 +img.src = image_src;<?php
66 +
67 + $script = ob_get_clean();
68 +
69 + return $this->getDiv($height, $width) . $this->wrap_script($script, 'WPLeafletImageShortcode');
113 70 }
114 71 }