| 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 |
|