From e15838d7f46586baa68352a07103e042175a5143 Mon Sep 17 00:00:00 2001 From: etj Date: Tue, 4 Oct 2016 13:14:39 +0200 Subject: [PATCH 1/2] [#162] Allow use of WMS layer in extent map --- ckanext/spatial/public/js/common_map.js | 23 ++++++++++++++++++- .../spatial/snippets/map_attribution.html | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ckanext/spatial/public/js/common_map.js b/ckanext/spatial/public/js/common_map.js index 19a2a18..96df3d7 100644 --- a/ckanext/spatial/public/js/common_map.js +++ b/ckanext/spatial/public/js/common_map.js @@ -35,6 +35,8 @@ maxZoom: 18 }); + var baseLayer; + map = new L.Map(container, leafletMapOptions); if (mapConfig.type == 'mapbox') { @@ -48,20 +50,39 @@ leafletBaseLayerOptions.handle = mapConfig['mapbox.map_id']; leafletBaseLayerOptions.subdomains = mapConfig.subdomains || 'abcd'; leafletBaseLayerOptions.attribution = mapConfig.attribution || 'Data: OpenStreetMap, Design: MapBox'; + + baseLayer = new L.TileLayer(baseLayerUrl, leafletBaseLayerOptions); + } else if (mapConfig.type == 'custom') { // Custom XYZ layer baseLayerUrl = mapConfig['custom.url']; if (mapConfig.subdomains) leafletBaseLayerOptions.subdomains = mapConfig.subdomains; if (mapConfig.tms) leafletBaseLayerOptions.tms = mapConfig.tms; leafletBaseLayerOptions.attribution = mapConfig.attribution; + + baseLayer = new L.TileLayer(baseLayerUrl, leafletBaseLayerOptions); + + } else if (mapConfig.type == 'wms') { + + baseLayerUrl = mapConfig['wms.url']; + wmsOptions = {} + wmsOptions['layers'] = mapConfig['wms.layers']; + wmsOptions['styles'] = mapConfig['wms.styles'] || ''; + wmsOptions['format'] = mapConfig['wms.format'] || 'image/png'; + wmsOptions['crs'] = mapConfig['wms.srs'] || mapConfig['wms.crs']; + wmsOptions['version'] = mapConfig['wms.version'] || '1.1.1'; + + baseLayer = new L.TileLayer.WMS(baseLayerUrl, wmsOptions); + } else { // Default to Stamen base map baseLayerUrl = 'https://stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}.png'; leafletBaseLayerOptions.subdomains = mapConfig.subdomains || 'abcd'; leafletBaseLayerOptions.attribution = mapConfig.attribution || 'Map tiles by Stamen Design (CC BY 3.0). Data by OpenStreetMap (CC BY SA)'; + + baseLayer = new L.TileLayer(baseLayerUrl, leafletBaseLayerOptions); } - var baseLayer = new L.TileLayer(baseLayerUrl, leafletBaseLayerOptions); map.addLayer(baseLayer); return map; diff --git a/ckanext/spatial/templates/spatial/snippets/map_attribution.html b/ckanext/spatial/templates/spatial/snippets/map_attribution.html index 0860a90..d4b6c1e 100644 --- a/ckanext/spatial/templates/spatial/snippets/map_attribution.html +++ b/ckanext/spatial/templates/spatial/snippets/map_attribution.html @@ -1,5 +1,7 @@ {% if map_config.type == 'custom' %}
{{ map_config.attribution|safe }}
+{% elif map_config.type == 'wms' %} +
{{ map_config['wms.attribution']|safe }}
{% else %}
Map data © OpenStreetMap contributors
{% if map_config.type == 'mapbox' %} From 3d73bc96420b0b8ffffe17cf696c6638416abb1f Mon Sep 17 00:00:00 2001 From: etj Date: Tue, 4 Oct 2016 16:38:27 +0200 Subject: [PATCH 2/2] [#162] Allow use of WMS layer in extent map --- ckanext/spatial/public/js/common_map.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ckanext/spatial/public/js/common_map.js b/ckanext/spatial/public/js/common_map.js index 96df3d7..dfc0cd0 100644 --- a/ckanext/spatial/public/js/common_map.js +++ b/ckanext/spatial/public/js/common_map.js @@ -69,7 +69,9 @@ wmsOptions['layers'] = mapConfig['wms.layers']; wmsOptions['styles'] = mapConfig['wms.styles'] || ''; wmsOptions['format'] = mapConfig['wms.format'] || 'image/png'; - wmsOptions['crs'] = mapConfig['wms.srs'] || mapConfig['wms.crs']; + if(mapConfig['wms.srs'] || mapConfig['wms.crs']) { + wmsOptions['crs'] = mapConfig['wms.srs'] || mapConfig['wms.crs']; + } wmsOptions['version'] = mapConfig['wms.version'] || '1.1.1'; baseLayer = new L.TileLayer.WMS(baseLayerUrl, wmsOptions);