PluginProbe
Leaflet Map / trunk
Leaflet Map vtrunk
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.wms-shortcode.php

class.wms-shortcode.php in Leaflet Map trunk, at shortcodes/class.wms-shortcode.php

93 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Wms Shortcode
4 *
5 * Displays map with [leaflet-wms src="path/to/wms"]
6 *
7 * JavaScript equivalent : L.TileLayer.wms('path/to/wms?', {layer: 'layername', crs: L.CRS.EPSG3857});
8 *
9 * @category Shortcode
10 * @author Janne Jakob Fleischer <janne.fleischer@ils-forschung.de>
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_Wms_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 if (!empty($address)) {
38 include_once LEAFLET_MAP__PLUGIN_DIR . 'class.geocoder.php';
39 $location = new Leaflet_Geocoder($address);
40 $lat = $location->lat;
41 $lng = $location->lng;
42 }
43
44 $lat_set = isset($lat) || isset($y);
45 $lng_set = isset($lng) || isset($x);
46
47 $lat = empty($lat) ? (empty($y) ? '0' : $y) : $lat;
48 $lng = empty($lng) ? (empty($x) ? '0' : $x) : $lng;
49
50 // validate lat/lng
51 $lat = $this->LM->filter_float($lat);
52 $lng = $this->LM->filter_float($lng);
53
54 /* only required field for image map (src/source) */
55 $src = empty($src) ? '' : $src;
56 $source = empty($source)
57 ? 'https://ows.mundialis.de/services/service?'
58 : $source;
59 $source = filter_var(empty($src) ? $source : $src, FILTER_SANITIZE_URL);
60
61 $layer = empty($layer) ? 'TOPO-OSM-WMS' : $layer;
62
63 $crs = str_replace(':', '', empty($crs) ? 'EPSG:3857' : $crs);
64
65 if ($source == 'https://ows.mundialis.de/services/service?' && $layer == 'TOPO-OSM-WMS') {
66 $attribution = empty($attribution) ? '© OpenStreetMap Contributors' : $attribution;
67 }
68 $attribution = empty($attribution) ? '' : $attribution;
69
70 ob_start();
71 ?>/*<script>*/
72 var srcUrl = atob('<?php echo base64_encode( $source ); ?>');
73 var options = L.Util.extend({}, {
74 attributionControl: false
75 }, <?php echo $map_options; ?>);
76 var zoom = <?php echo $zoom; ?>;
77 var map = window.WPLeafletMapPlugin.createMap(options).setView(L.latLng(<?php echo $lat; ?>, <?php echo $lng; ?>), zoom);
78 var wmslayer = L.tileLayer.wms(
79 srcUrl,
80 {
81 layers: '<?php echo esc_js($layer); ?>',
82 crs: L.CRS['<?php echo esc_js($crs); ?>']
83 }
84 ).addTo( map );
85
86 <?php
87 $script = ob_get_clean();
88
89 return $this->getDiv($height, $width) .
90 $this->wrap_script($script, 'WPLeafletWmsShortcode');
91 }
92 }
93