PluginProbe
Leaflet Map / 3.0.5
Leaflet Map v3.0.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 3.0.5, at shortcodes/class.image-shortcode.php

69 lines 1.9 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 * @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.map-shortcode.php';
19
20 /**
21 * Leaflet Image Shortcode Class
22 */
23 class Leaflet_Image_Shortcode extends Leaflet_Map_Shortcode
24 {
25 /**
26 * Get HTML for shortcode
27 *
28 * @param string $atts or Array
29 * @param string $content produced by adding atts to JavaScript
30 *
31 * @return string HTML script
32 */
33 protected function getHTML($atts='', $content=null)
34 {
35 extract($this->getAtts($atts));
36
37 /* only required field for image map (src/source) */
38 $src = empty($src) ? '' : $src;
39 $source = empty($source) ? 'https://picsum.photos/1000/1000/' : $source;
40 $source = empty($src) ? $source : $src;
41
42 ob_start(); ?>/*<script>*/
43 var options = L.Util.extend({}, {
44 attributionControl: false
45 }, <?php echo $map_options; ?>, {
46 crs: L.CRS.Simple
47 });
48 var image_src = '<?php echo htmlspecialchars($source, ENT_QUOTES); ?>';
49 var img = new Image();
50 var zoom = <?php echo $zoom; ?>;
51 var map = window.WPLeafletMapPlugin.createImageMap(options).setView([0, 0], 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;<?php
63
64 $script = ob_get_clean();
65
66 return $this->getDiv($height, $width) . $this->wrap_script($script, 'WPLeafletImageShortcode');
67 }
68 }
69