-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathclass.wms-shortcode.php
More file actions
92 lines (78 loc) · 2.57 KB
/
Copy pathclass.wms-shortcode.php
File metadata and controls
92 lines (78 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* Wms Shortcode
*
* Displays map with [leaflet-wms src="path/to/wms"]
*
* JavaScript equivalent : L.TileLayer.wms('path/to/wms?', {layer: 'layername', crs: L.CRS.EPSG3857});
*
* @category Shortcode
* @author Janne Jakob Fleischer <janne.fleischer@ils-forschung.de>
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit();
}
require_once LEAFLET_MAP__PLUGIN_DIR . 'shortcodes/class.map-shortcode.php';
/**
* Leaflet Image Shortcode Class
*/
class Leaflet_Wms_Shortcode extends Leaflet_Map_Shortcode
{
/**
* Get HTML for shortcode
*
* @param string $atts or Array
* @param string $content produced by adding atts to JavaScript
*
* @return string HTML script
*/
protected function getHTML($atts = '', $content = null)
{
extract($this->getAtts($atts));
if (!empty($address)) {
include_once LEAFLET_MAP__PLUGIN_DIR . 'class.geocoder.php';
$location = new Leaflet_Geocoder($address);
$lat = $location->lat;
$lng = $location->lng;
}
$lat_set = isset($lat) || isset($y);
$lng_set = isset($lng) || isset($x);
$lat = empty($lat) ? (empty($y) ? '0' : $y) : $lat;
$lng = empty($lng) ? (empty($x) ? '0' : $x) : $lng;
// validate lat/lng
$lat = $this->LM->filter_float($lat);
$lng = $this->LM->filter_float($lng);
/* only required field for image map (src/source) */
$src = empty($src) ? '' : $src;
$source = empty($source)
? 'https://ows.mundialis.de/services/service?'
: $source;
$source = filter_var(empty($src) ? $source : $src, FILTER_SANITIZE_URL);
$layer = empty($layer) ? 'TOPO-OSM-WMS' : $layer;
$crs = str_replace(':', '', empty($crs) ? 'EPSG:3857' : $crs);
if ($source == 'https://ows.mundialis.de/services/service?' && $layer == 'TOPO-OSM-WMS') {
$attribution = empty($attribution) ? '© OpenStreetMap Contributors' : $attribution;
}
$attribution = empty($attribution) ? '' : $attribution;
ob_start();
?>/*<script>*/
var srcUrl = atob('<?php echo base64_encode( $source ); ?>');
var options = Object.assign({}, {
attributionControl: false
}, <?php echo $map_options; ?>);
var zoom = <?php echo $zoom; ?>;
var map = window.WPLeafletMapPlugin.createMap(options).setView(L.latLng(<?php echo $lat; ?>, <?php echo $lng; ?>), zoom);
var wmslayer = L.tileLayer.wms(
srcUrl,
{
layers: '<?php echo esc_js($layer); ?>',
crs: L.CRS['<?php echo esc_js($crs); ?>']
}
).addTo( map );
<?php
$script = ob_get_clean();
return $this->getDiv($height, $width) .
$this->wrap_script($script, 'WPLeafletWmsShortcode');
}
}