PluginProbe
Leaflet Map / 2.10.0
Leaflet Map v2.10.0
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.10.0, at shortcodes/class.image-shortcode.php

91 lines 3.2 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 */
10
11 // Exit if accessed directly
12 if ( !defined( 'ABSPATH' ) ) exit;
13
14 include_once(LEAFLET_MAP__PLUGIN_DIR . 'shortcodes/class.map-shortcode.php');
15
16 class Leaflet_Image_Shortcode extends Leaflet_Map_Shortcode {
17 /**
18 * Get HTML for shortcode
19 * @param array $atts
20 * @return string $content produced by adding atts to JavaScript
21 */
22 protected function getHTML ($atts='', $content=null) {
23 extract($this->getAtts($atts));
24
25 /* only required field for image map (src/source) */
26 $src = empty($src) ? '' : $src;
27 $source = empty($source) ? 'https://lorempixel.com/1000/1000/' : $source;
28 $source = empty($src) ? $source : $src;
29
30 ob_start();
31 ?>
32 <div
33 id="leaflet-map-image-<?php echo $this->map_id; ?>"
34 class="leaflet-map"
35 style="height:<?php echo $height; ?>; width:<?php echo $width; ?>;"></div>
36 <script>
37 WPLeafletMapPlugin.add(function () {
38 var map,
39 options = L.Util.extend({}, {
40 maxZoom: <?php echo $max_zoom; ?>,
41 minZoom: <?php echo $min_zoom; ?>,
42 zoomControl: <?php echo $zoomcontrol; ?>,
43 scrollWheelZoom: <?php echo $scrollwheel; ?>,
44 doubleClickZoom: <?php echo $doubleclickzoom; ?>,
45 attributionControl: false
46 }, <?php echo $more_options; ?>, {
47 crs: L.CRS.Simple
48 }),
49 image_src = '<?php echo $source; ?>',
50 img = new Image(),
51 zoom = <?php echo $zoom; ?>;
52 img.onload = function() {
53 var h = img.height,
54 w = img.width,
55 projected_zoom = zoom + 1,
56 southWest = map.unproject([-w, h], projected_zoom),
57 northEast = map.unproject([w, -h], projected_zoom),
58 bounds = new L.LatLngBounds(southWest, northEast);
59 L.imageOverlay( image_src, bounds ).addTo( map );
60 map.setMaxBounds(bounds);
61 };
62 img.src = image_src;
63 map = L.map('leaflet-map-image-<?php echo $this->map_id; ?>', options).setView([0, 0], zoom);
64 // make it known that it is an image map
65 map.is_image_map = true;
66 if (<?php echo $fit_markers; ?>) {
67 map.fit_markers = true;
68 }
69 <?php
70 if ($attribution) {
71 /* add any attributions, semi-colon-separated */
72 $attributions = explode(';', $attribution);
73 ?>
74 var attControl = L.control.attribution({prefix:false}).addTo(map);
75 <?php
76 foreach ($attributions as $a) {
77 ?>
78 attControl.addAttribution('<?php echo trim($a); ?>');
79 <?php
80 }
81 }
82 ?>
83 WPLeafletMapPlugin.maps.push( map );
84 WPLeafletMapPlugin.images.push( img );
85 }); // end add
86 </script>
87 <?php
88 return ob_get_clean();
89 }
90 }
91