Merge pull request #163 from geosolutions-it/162_wms_layers

[#162] Allow use of WMS layer in extent map
This commit is contained in:
Adrià Mercader 2016-10-17 11:34:27 +01:00 committed by GitHub
commit d7c08d8cea
2 changed files with 26 additions and 1 deletions

View File

@ -35,6 +35,8 @@
maxZoom: 18
});
var baseLayer;
map = new L.Map(container, leafletMapOptions);
if (mapConfig.type == 'mapbox') {
@ -48,20 +50,41 @@
leafletBaseLayerOptions.handle = mapConfig['mapbox.map_id'];
leafletBaseLayerOptions.subdomains = mapConfig.subdomains || 'abcd';
leafletBaseLayerOptions.attribution = mapConfig.attribution || 'Data: <a href="http://osm.org/copyright" target="_blank">OpenStreetMap</a>, Design: <a href="http://mapbox.com/about/maps" target="_blank">MapBox</a>';
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';
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);
} 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 <a href="http://stamen.com">Stamen Design</a> (<a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>). Data by <a href="http://openstreetmap.org">OpenStreetMap</a> (<a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>)';
baseLayer = new L.TileLayer(baseLayerUrl, leafletBaseLayerOptions);
}
var baseLayer = new L.TileLayer(baseLayerUrl, leafletBaseLayerOptions);
map.addLayer(baseLayer);
return map;

View File

@ -1,5 +1,7 @@
{% if map_config.type == 'custom' %}
<div>{{ map_config.attribution|safe }}</div>
{% elif map_config.type == 'wms' %}
<div>{{ map_config['wms.attribution']|safe }}</div>
{% else %}
<div>Map data &copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors</div>
{% if map_config.type == 'mapbox' %}