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.image-shortcode.php

class.image-shortcode.php in Leaflet Map 2.11.5, at shortcodes/class.image-shortcode.php

110 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Image Shortcode
4 *
5 * Displays map with [leaflet-image src="path/to/image.jpg"]
6 *
7 * JavaScript equivalent : L.imageOverlay('path/to/image.jpg');
8 *
9 * PHP Version 5.5
10 *
11 * @category Shortcode
12 * @author Benjamin J DeLong <ben@bozdoz.com>
13 */
14
15 // Exit if accessed directly
16 if (!defined('ABSPATH')) {
17 exit;
18 }
19
20 require_once LEAFLET_MAP__PLUGIN_DIR . 'shortcodes/class.map-shortcode.php';
21
22 /**
23 * Leaflet Image Shortcode Class
24 */
25 class Leaflet_Image_Shortcode extends Leaflet_Map_Shortcode
26 {
27 /**
28 * Get HTML for shortcode
29 *
30 * @param string $atts or Array
31 * @param string $content produced by adding atts to JavaScript
32 *
33 * @return string HTML script
34 */
35 protected function getHTML($atts='', $content=null)
36 {
37 extract($this->getAtts($atts));
38
39 /* only required field for image map (src/source) */
40 $src = empty($src) ? '' : $src;
41 $source = empty($source) ? 'https://picsum.photos/1000/1000/' : $source;
42 $source = empty($src) ? $source : $src;
43
44 ob_start();
45 ?>
46 <div
47 id="leaflet-map-image-<?php echo $this->map_id; ?>"
48 class="leaflet-map"
49 style="height:<?php
50 echo $height;
51 ?>; width:<?php
52 echo $width;
53 ?>;"></div>
54 <script>
55 window.WPLeafletMapPlugin = window.WPLeafletMapPlugin || [];
56 window.WPLeafletMapPlugin.push(function () {
57 var map,
58 options = L.Util.extend({}, {
59 maxZoom: <?php echo $max_zoom; ?>,
60 minZoom: <?php echo $min_zoom; ?>,
61 zoomControl: <?php echo $zoomcontrol; ?>,
62 scrollWheelZoom: <?php echo $scrollwheel; ?>,
63 doubleClickZoom: <?php echo $doubleclickzoom; ?>,
64 attributionControl: false
65 }, <?php echo $more_options; ?>, {
66 crs: L.CRS.Simple
67 }),
68 image_src = '<?php echo $source; ?>',
69 img = new Image(),
70 zoom = <?php echo $zoom; ?>;
71 img.onload = function() {
72 var h = img.height,
73 w = img.width,
74 projected_zoom = zoom + 1,
75 southWest = map.unproject([-w, h], projected_zoom),
76 northEast = map.unproject([w, -h], projected_zoom),
77 bounds = new L.LatLngBounds(southWest, northEast);
78 L.imageOverlay( image_src, bounds ).addTo( map );
79 map.setMaxBounds(bounds);
80 };
81 img.src = image_src;
82 map = L.map('leaflet-map-image-<?php echo $this->map_id; ?>', options).setView([0, 0], zoom);
83 // make it known that it is an image map
84 map.is_image_map = true;
85 if (<?php echo $fit_markers; ?>) {
86 map.fit_markers = true;
87 }
88 <?php
89 if ($attribution) {
90 /* add any attributions, semi-colon-separated */
91 $attributions = explode(';', $attribution);
92 ?>
93 var attControl = L.control.attribution({prefix:false}).addTo(map);
94 <?php
95 foreach ($attributions as $a) {
96 ?>
97 attControl.addAttribution('<?php echo trim($a); ?>');
98 <?php
99 }
100 }
101 ?>
102 window.WPLeafletMapPlugin.maps.push( map );
103 window.WPLeafletMapPlugin.images.push( img );
104 }); // end add
105 </script>
106 <?php
107 return ob_get_clean();
108 }
109 }
110