From f571854caa31a6531107e49a64d7284539ff0565 Mon Sep 17 00:00:00 2001 From: Harald von Waldow Date: Mon, 4 Jan 2016 18:40:36 +0100 Subject: [PATCH 1/5] WIP multilayer --- ckanext/spatial/public/js/common_map.js | 53 ++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/ckanext/spatial/public/js/common_map.js b/ckanext/spatial/public/js/common_map.js index 3bd8f263..b5352dd7 100644 --- a/ckanext/spatial/public/js/common_map.js +++ b/ckanext/spatial/public/js/common_map.js @@ -33,26 +33,64 @@ var leafletMapOptions = leafletMapOptions || {}; var leafletBaseLayerOptions = jQuery.extend(leafletBaseLayerOptions, { maxZoom: 18 - }); + }); + var leafletMultiLayerOptions = []; map = new L.Map(container, leafletMapOptions); if (mapConfig.type == 'mapbox') { // MapBox base map if (!mapConfig['mapbox.map_id'] || !mapConfig['mapbox.access_token']) { - throw '[CKAN Map Widgets] You need to provide a map ID ([account].[handle]) and an access token when using a MapBox layer. ' + + throw '[CKAN Map Widgets] You need to provide a map ID ' + + '([account].[handle]) and an access token when using a MapBox layer. ' + 'See http://www.mapbox.com/developers/api-overview/ for details'; } - baseLayerUrl = '//{s}.tiles.mapbox.com/v4/' + mapConfig['mapbox.map_id'] + '/{z}/{x}/{y}.png?access_token=' + mapConfig['mapbox.access_token']; + baseLayerUrl = '//{s}.tiles.mapbox.com/v4/' + mapConfig['mapbox.map_id'] + + '/{z}/{x}/{y}.png?access_token=' + mapConfig['mapbox.access_token']; leafletBaseLayerOptions.handle = mapConfig['mapbox.map_id']; leafletBaseLayerOptions.subdomains = mapConfig.subdomains || 'abcd'; - leafletBaseLayerOptions.attribution = mapConfig.attribution || 'Data: OpenStreetMap, Design: MapBox'; + leafletBaseLayerOptions.attribution = mapConfig.attribution || + 'Data: ' + + 'OpenStreetMap, Design: MapBox'; } else if (mapConfig.type == 'custom') { // Custom XYZ layer baseLayerUrl = mapConfig['custom.url']; if (mapConfig.subdomains) leafletBaseLayerOptions.subdomains = mapConfig.subdomains; leafletBaseLayerOptions.attribution = mapConfig.attribution; + } else if (mapConfig.type == 'multilayer') { + // Custom multi-layer map + console.log(mapConfig); + // parse layer-specific mapConfig properties into array of layers + function layerprops(mc) { + var match = []; + for (mprop in mc) { + if ((ma = /^(layer_\d+)\.(.+)$/.exec(mprop))) { + match.push(ma); + } + } + return(match); + }; + + mapconf = (function (){ + var mc = JSON.parse(JSON.stringify(mapConfig)); + for (lp in layerprops(mapConfig)) { + delete mc[lp[0]]; + mc[lp[1]] = mc[lp[1]] || {}; + + + + + + console.log(layerprops); + // layernames = (function (mapconf) { + // var layernames = Object.getOwnPropertyNames(mapconf).filter(function (key) { + // return (/^layer_(\d+)\..+$/.test(key)); + // }); + // return(layernames); + // }(mapConfig)) + } else { // MapQuest OpenStreetMap base map if (isHttps) { @@ -61,9 +99,12 @@ baseLayerUrl = '//otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'; } leafletBaseLayerOptions.subdomains = mapConfig.subdomains || '1234'; - leafletBaseLayerOptions.attribution = mapConfig.attribution || 'Map data © OpenStreetMap contributors, Tiles Courtesy of MapQuest '; + leafletBaseLayerOptions.attribution = mapConfig.attribution || + 'Map data © OpenStreetMap contributors, Tiles Courtesy of ' + + 'MapQuest ' + + ''; } - + var baseLayer = new L.TileLayer(baseLayerUrl, leafletBaseLayerOptions); map.addLayer(baseLayer); From 7f5a53c10db2d7b214d181e7c6dc46300cbebf01 Mon Sep 17 00:00:00 2001 From: Harald von Waldow Date: Tue, 5 Jan 2016 17:25:07 +0100 Subject: [PATCH 2/5] map overly working --- ckanext/spatial/public/js/common_map.js | 132 +++++++++++++++--------- 1 file changed, 82 insertions(+), 50 deletions(-) diff --git a/ckanext/spatial/public/js/common_map.js b/ckanext/spatial/public/js/common_map.js index b5352dd7..ef12999b 100644 --- a/ckanext/spatial/public/js/common_map.js +++ b/ckanext/spatial/public/js/common_map.js @@ -1,12 +1,11 @@ (function (ckan, jQuery) { - - /* Returns a Leaflet map to use on the different spatial widgets - * - * All Leaflet based maps should use this constructor to provide consistent - * look and feel and avoid duplication. - * - * container - HTML element or id of the map container - * mapConfig - (Optional) CKAN config related to the base map. + /* Returns a Leaflet map to use on the different spatial widgets + * + * All Leaflet based maps should use this constructor to provide consistent + * look and feel and avoid duplication. + * + * container - HTML element or id of the map container + * mapConfig - (Optional) CKAN config related to the base map. * These are defined in the config ini file (eg * map type, API keys if necessary, etc). * leafletMapOptions - (Optional) Options to pass to the Leaflet Map constructor @@ -23,8 +22,8 @@ * * Returns a Leaflet map object. */ - ckan.commonLeafletMap = function (container, - mapConfig, + ckan.commonLeafletMap = function (container, + mapConfig, leafletMapOptions, leafletBaseLayerOptions) { @@ -32,9 +31,8 @@ var mapConfig = mapConfig || {type: 'mapquest'}; var leafletMapOptions = leafletMapOptions || {}; var leafletBaseLayerOptions = jQuery.extend(leafletBaseLayerOptions, { - maxZoom: 18 + maxZoom: 18 }); - var leafletMultiLayerOptions = []; map = new L.Map(container, leafletMapOptions); @@ -59,39 +57,62 @@ baseLayerUrl = mapConfig['custom.url']; if (mapConfig.subdomains) leafletBaseLayerOptions.subdomains = mapConfig.subdomains; leafletBaseLayerOptions.attribution = mapConfig.attribution; - } else if (mapConfig.type == 'multilayer') { - // Custom multi-layer map - console.log(mapConfig); + } else if (mapConfig.type === 'multilayer') { // Custom multi-layer map // parse layer-specific mapConfig properties into array of layers - function layerprops(mc) { - var match = []; - for (mprop in mc) { - if ((ma = /^(layer_\d+)\.(.+)$/.exec(mprop))) { - match.push(ma); - } + mapConfig.layerprops = + (function (mc) { + var match = [], + ma; + for (var mprop in mc) { + if ((ma = /^(layer_)(\d+)\.(.+)$/.exec(mprop))) { + match.push(ma); + } } return(match); - }; - - mapconf = (function (){ - var mc = JSON.parse(JSON.stringify(mapConfig)); - for (lp in layerprops(mapConfig)) { - delete mc[lp[0]]; - mc[lp[1]] = mc[lp[1]] || {}; - - - - - - console.log(layerprops); - // layernames = (function (mapconf) { - // var layernames = Object.getOwnPropertyNames(mapconf).filter(function (key) { - // return (/^layer_(\d+)\..+$/.test(key)); - // }); - // return(layernames); - // }(mapConfig)) - - } else { + })(mapConfig); + // construct a sorted list of layernames + mapConfig.layerlist = + (function (mc) { + var ll = [], + layername, + anum, + bnum; + // get layer-number from layername + var tonum = function (s) { + return(parseInt(/^layer_(\d+)$/i.exec(s)[1])); + }; + // build list of layernames + for (var i = 0; i < mc.layerprops.length; i++) { + layername = mc.layerprops[i][1] + mc.layerprops[i][2]; + if (ll.indexOf(layername) === -1) { + ll.push(layername); + } + } + // sort layerlist + ll = ll.sort(function (a, b) { + return(tonum(a) - tonum(b)); + }); + return(ll); + })(mapConfig); + console.log("Layerlist:"); + console.log(mapConfig.layerlist); + // update mapConfig to contain structred layer-properties + mapConfig = + (function (mc) { + var l, newkey; + for (var i = 0; i < mc.layerprops.length; i++) { + l = mc.layerprops[i]; + newkey = l[1] + l[2]; + mc[newkey] = mc[newkey] || {}; + mc[newkey][l[3]] = mc[l[0]]; + delete mc[l[0]]; + } + delete mc.layerprops; + return(mc); + })(mapConfig); + console.log("modified mapConfig"); + console.log(mapConfig); + } else { // MapQuest OpenStreetMap base map if (isHttps) { baseLayerUrl = '//otile{s}-s.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'; @@ -104,12 +125,23 @@ 'MapQuest ' + ''; } - - var baseLayer = new L.TileLayer(baseLayerUrl, leafletBaseLayerOptions); - map.addLayer(baseLayer); - - return map; - - } - + if (mapConfig.type === 'multilayer') { + mapConfig.layerlist.forEach(function (lname) { + var url = mapConfig[lname].url; + var options = {}; + // extract layeroptions + delete mapConfig[lname].url; + for (var prop in mapConfig[lname]) { + if (mapConfig[lname].hasOwnProperty(prop)) { + options[prop] = mapConfig[lname][prop]; + } + } + map.addLayer(new L.TileLayer(url, options)); + }); + } else { + var baseLayer = new L.TileLayer(baseLayerUrl, leafletBaseLayerOptions); + map.addLayer(baseLayer); + } + return map; + }; })(this.ckan, this.jQuery); From b93a6e2ccce609eba23e05c007ec10ec4d6f68d6 Mon Sep 17 00:00:00 2001 From: Harald von Waldow Date: Wed, 6 Jan 2016 15:28:39 +0100 Subject: [PATCH 3/5] removed debug-messages --- ckanext/spatial/public/js/common_map.js | 244 ++++++++++++------------ 1 file changed, 122 insertions(+), 122 deletions(-) diff --git a/ckanext/spatial/public/js/common_map.js b/ckanext/spatial/public/js/common_map.js index ef12999b..dc61e7ba 100644 --- a/ckanext/spatial/public/js/common_map.js +++ b/ckanext/spatial/public/js/common_map.js @@ -1,11 +1,11 @@ (function (ckan, jQuery) { - /* Returns a Leaflet map to use on the different spatial widgets - * - * All Leaflet based maps should use this constructor to provide consistent - * look and feel and avoid duplication. - * - * container - HTML element or id of the map container - * mapConfig - (Optional) CKAN config related to the base map. + /* Returns a Leaflet map to use on the different spatial widgets + * + * All Leaflet based maps should use this constructor to provide consistent + * look and feel and avoid duplication. + * + * container - HTML element or id of the map container + * mapConfig - (Optional) CKAN config related to the base map. * These are defined in the config ini file (eg * map type, API keys if necessary, etc). * leafletMapOptions - (Optional) Options to pass to the Leaflet Map constructor @@ -22,126 +22,126 @@ * * Returns a Leaflet map object. */ - ckan.commonLeafletMap = function (container, - mapConfig, + ckan.commonLeafletMap = function (container, + mapConfig, leafletMapOptions, leafletBaseLayerOptions) { + var isHttps = window.location.href.substring(0, 5).toLowerCase() === 'https'; + var mapConfig = mapConfig || {type: 'mapquest'}; + var leafletMapOptions = leafletMapOptions || {}; + var leafletBaseLayerOptions = jQuery.extend(leafletBaseLayerOptions, { + maxZoom: 18 + }); + + map = new L.Map(container, leafletMapOptions); + + if (mapConfig.type == 'mapbox') { + // MapBox base map + if (!mapConfig['mapbox.map_id'] || !mapConfig['mapbox.access_token']) { + throw '[CKAN Map Widgets] You need to provide a map ID ' + + '([account].[handle]) and an access token when using a MapBox layer. ' + + 'See http://www.mapbox.com/developers/api-overview/ for details'; + } - var isHttps = window.location.href.substring(0, 5).toLowerCase() === 'https'; - var mapConfig = mapConfig || {type: 'mapquest'}; - var leafletMapOptions = leafletMapOptions || {}; - var leafletBaseLayerOptions = jQuery.extend(leafletBaseLayerOptions, { - maxZoom: 18 - }); - - map = new L.Map(container, leafletMapOptions); - - if (mapConfig.type == 'mapbox') { - // MapBox base map - if (!mapConfig['mapbox.map_id'] || !mapConfig['mapbox.access_token']) { - throw '[CKAN Map Widgets] You need to provide a map ID ' + - '([account].[handle]) and an access token when using a MapBox layer. ' + - 'See http://www.mapbox.com/developers/api-overview/ for details'; - } - - baseLayerUrl = '//{s}.tiles.mapbox.com/v4/' + mapConfig['mapbox.map_id'] + - '/{z}/{x}/{y}.png?access_token=' + mapConfig['mapbox.access_token']; - leafletBaseLayerOptions.handle = mapConfig['mapbox.map_id']; - leafletBaseLayerOptions.subdomains = mapConfig.subdomains || 'abcd'; - leafletBaseLayerOptions.attribution = mapConfig.attribution || - 'Data: ' + - 'OpenStreetMap, Design: MapBox'; - } else if (mapConfig.type == 'custom') { - // Custom XYZ layer - baseLayerUrl = mapConfig['custom.url']; - if (mapConfig.subdomains) leafletBaseLayerOptions.subdomains = mapConfig.subdomains; - leafletBaseLayerOptions.attribution = mapConfig.attribution; - } else if (mapConfig.type === 'multilayer') { // Custom multi-layer map - // parse layer-specific mapConfig properties into array of layers - mapConfig.layerprops = - (function (mc) { - var match = [], - ma; - for (var mprop in mc) { - if ((ma = /^(layer_)(\d+)\.(.+)$/.exec(mprop))) { - match.push(ma); - } - } - return(match); - })(mapConfig); - // construct a sorted list of layernames - mapConfig.layerlist = - (function (mc) { - var ll = [], - layername, - anum, - bnum; - // get layer-number from layername - var tonum = function (s) { - return(parseInt(/^layer_(\d+)$/i.exec(s)[1])); - }; - // build list of layernames - for (var i = 0; i < mc.layerprops.length; i++) { - layername = mc.layerprops[i][1] + mc.layerprops[i][2]; - if (ll.indexOf(layername) === -1) { - ll.push(layername); - } + baseLayerUrl = '//{s}.tiles.mapbox.com/v4/' + mapConfig['mapbox.map_id'] + + '/{z}/{x}/{y}.png?access_token=' + mapConfig['mapbox.access_token']; + leafletBaseLayerOptions.handle = mapConfig['mapbox.map_id']; + leafletBaseLayerOptions.subdomains = mapConfig.subdomains || 'abcd'; + leafletBaseLayerOptions.attribution = mapConfig.attribution || + 'Data: ' + + 'OpenStreetMap, Design: MapBox'; + + } else if (mapConfig.type == 'custom') { + // Custom XYZ layer + baseLayerUrl = mapConfig['custom.url']; + if (mapConfig.subdomains) { + leafletBaseLayerOptions.subdomains = mapConfig.subdomains; + } + leafletBaseLayerOptions.attribution = mapConfig.attribution; + + // Custom multi-layer map + } else if (mapConfig.type === 'multilayer') { + // parse layer-specific mapConfig properties into array of layers + mapConfig.layerprops = (function (mc) { + var match = []; + var ma; + for (var mprop in mc) { + if ((ma = /^(layer_)(\d+)\.(.+)$/.exec(mprop))) { + match.push(ma); } - // sort layerlist - ll = ll.sort(function (a, b) { - return(tonum(a) - tonum(b)); - }); - return(ll); - })(mapConfig); - console.log("Layerlist:"); - console.log(mapConfig.layerlist); - // update mapConfig to contain structred layer-properties - mapConfig = - (function (mc) { - var l, newkey; - for (var i = 0; i < mc.layerprops.length; i++) { - l = mc.layerprops[i]; - newkey = l[1] + l[2]; - mc[newkey] = mc[newkey] || {}; - mc[newkey][l[3]] = mc[l[0]]; - delete mc[l[0]]; - } - delete mc.layerprops; - return(mc); - })(mapConfig); - console.log("modified mapConfig"); - console.log(mapConfig); - } else { - // MapQuest OpenStreetMap base map - if (isHttps) { - baseLayerUrl = '//otile{s}-s.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'; - } else { - baseLayerUrl = '//otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'; - } - leafletBaseLayerOptions.subdomains = mapConfig.subdomains || '1234'; - leafletBaseLayerOptions.attribution = mapConfig.attribution || - 'Map data © OpenStreetMap contributors, Tiles Courtesy of ' + - 'MapQuest ' + - ''; - } - if (mapConfig.type === 'multilayer') { - mapConfig.layerlist.forEach(function (lname) { - var url = mapConfig[lname].url; - var options = {}; - // extract layeroptions - delete mapConfig[lname].url; - for (var prop in mapConfig[lname]) { - if (mapConfig[lname].hasOwnProperty(prop)) { - options[prop] = mapConfig[lname][prop]; + } + return(match); + })(mapConfig); + // construct a sorted list of layernames + mapConfig.layerlist = (function (mc) { + var ll = []; + var layername; + var anum; + var bnum; + // get layer-number from layername + function tonum(s) { + return(parseInt(/^layer_(\d+)$/i.exec(s)[1])); + }; + // build list of layernames + for (var i = 0; i < mc.layerprops.length; i++) { + layername = mc.layerprops[i][1] + mc.layerprops[i][2]; + if (ll.indexOf(layername) === -1) { + ll.push(layername); } } - map.addLayer(new L.TileLayer(url, options)); - }); - } else { - var baseLayer = new L.TileLayer(baseLayerUrl, leafletBaseLayerOptions); - map.addLayer(baseLayer); - } + // sort layerlist + ll = ll.sort(function (a, b) { + return(tonum(a) - tonum(b)); + }); + return(ll); + })(mapConfig); + // update mapConfig to contain strucutred layer-properties + mapConfig = (function (mc) { + var l; + var newkey; + for (var i = 0; i < mc.layerprops.length; i++) { + l = mc.layerprops[i]; + newkey = l[1] + l[2]; + mc[newkey] = mc[newkey] || {}; + mc[newkey][l[3]] = mc[l[0]]; + delete mc[l[0]]; + } + delete mc.layerprops; + return(mc); + })(mapConfig); + + } else { + // MapQuest OpenStreetMap base map + if (isHttps) { + baseLayerUrl = '//otile{s}-s.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'; + } else { + baseLayerUrl = '//otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'; + } + leafletBaseLayerOptions.subdomains = mapConfig.subdomains || '1234'; + leafletBaseLayerOptions.attribution = mapConfig.attribution || + 'Map data © OpenStreetMap contributors, Tiles Courtesy of ' + + 'MapQuest ' + + ''; + } + + if (mapConfig.type === 'multilayer') { + mapConfig.layerlist.forEach(function (lname) { + var url = mapConfig[lname].url; + var options = {}; + // extract layeroptions + delete mapConfig[lname].url; + for (var prop in mapConfig[lname]) { + if (mapConfig[lname].hasOwnProperty(prop)) { + options[prop] = mapConfig[lname][prop]; + } + } + map.addLayer(new L.TileLayer(url, options)); + }); + } else { + var baseLayer = new L.TileLayer(baseLayerUrl, leafletBaseLayerOptions); + map.addLayer(baseLayer); + } return map; - }; + }; })(this.ckan, this.jQuery); From 9a0dbeddc157fb3b684ab713d2c4522bfd2c4984 Mon Sep 17 00:00:00 2001 From: Harald von Waldow Date: Wed, 6 Jan 2016 17:15:50 +0100 Subject: [PATCH 4/5] fixed attribution --- ckanext/spatial/templates/spatial/snippets/map_attribution.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/spatial/templates/spatial/snippets/map_attribution.html b/ckanext/spatial/templates/spatial/snippets/map_attribution.html index 2287ea2f..b961ba02 100644 --- a/ckanext/spatial/templates/spatial/snippets/map_attribution.html +++ b/ckanext/spatial/templates/spatial/snippets/map_attribution.html @@ -1,4 +1,4 @@ -{% if map_config.type == 'custom' %} +{% if map_config.type == 'custom' or map_config.type == 'multilayer' %}
{{ map_config.attribution|safe }}
{% else %}
Map data © OpenStreetMap contributors
From b519e19175b56f5801e7f52561cbfb1e6ea52d25 Mon Sep 17 00:00:00 2001 From: Harald von Waldow Date: Wed, 6 Jan 2016 17:43:40 +0100 Subject: [PATCH 5/5] fixed indentation --- ckanext/spatial/public/js/common_map.js | 87 +++++++++++-------------- 1 file changed, 38 insertions(+), 49 deletions(-) diff --git a/ckanext/spatial/public/js/common_map.js b/ckanext/spatial/public/js/common_map.js index dc61e7ba..030ac403 100644 --- a/ckanext/spatial/public/js/common_map.js +++ b/ckanext/spatial/public/js/common_map.js @@ -1,4 +1,5 @@ (function (ckan, jQuery) { + /* Returns a Leaflet map to use on the different spatial widgets * * All Leaflet based maps should use this constructor to provide consistent @@ -23,43 +24,35 @@ * Returns a Leaflet map object. */ ckan.commonLeafletMap = function (container, - mapConfig, + mapConfig, leafletMapOptions, leafletBaseLayerOptions) { - var isHttps = window.location.href.substring(0, 5).toLowerCase() === 'https'; - var mapConfig = mapConfig || {type: 'mapquest'}; - var leafletMapOptions = leafletMapOptions || {}; - var leafletBaseLayerOptions = jQuery.extend(leafletBaseLayerOptions, { - maxZoom: 18 - }); - - map = new L.Map(container, leafletMapOptions); - - if (mapConfig.type == 'mapbox') { - // MapBox base map - if (!mapConfig['mapbox.map_id'] || !mapConfig['mapbox.access_token']) { - throw '[CKAN Map Widgets] You need to provide a map ID ' + - '([account].[handle]) and an access token when using a MapBox layer. ' + - 'See http://www.mapbox.com/developers/api-overview/ for details'; - } - baseLayerUrl = '//{s}.tiles.mapbox.com/v4/' + mapConfig['mapbox.map_id'] + - '/{z}/{x}/{y}.png?access_token=' + mapConfig['mapbox.access_token']; - leafletBaseLayerOptions.handle = mapConfig['mapbox.map_id']; - leafletBaseLayerOptions.subdomains = mapConfig.subdomains || 'abcd'; - leafletBaseLayerOptions.attribution = mapConfig.attribution || - 'Data: ' + - 'OpenStreetMap, Design: MapBox'; - - } else if (mapConfig.type == 'custom') { - // Custom XYZ layer - baseLayerUrl = mapConfig['custom.url']; - if (mapConfig.subdomains) { - leafletBaseLayerOptions.subdomains = mapConfig.subdomains; - } - leafletBaseLayerOptions.attribution = mapConfig.attribution; - + var isHttps = window.location.href.substring(0, 5).toLowerCase() === 'https'; + var mapConfig = mapConfig || {type: 'mapquest'}; + var leafletMapOptions = leafletMapOptions || {}; + var leafletBaseLayerOptions = jQuery.extend(leafletBaseLayerOptions, { + maxZoom: 18 + }); + + map = new L.Map(container, leafletMapOptions); + + if (mapConfig.type == 'mapbox') { + // MapBox base map + if (!mapConfig['mapbox.map_id'] || !mapConfig['mapbox.access_token']) { + throw '[CKAN Map Widgets] You need to provide a map ID ([account].[handle]) and an access token when using a MapBox layer. ' + + 'See http://www.mapbox.com/developers/api-overview/ for details'; + } + + baseLayerUrl = '//{s}.tiles.mapbox.com/v4/' + mapConfig['mapbox.map_id'] + '/{z}/{x}/{y}.png?access_token=' + mapConfig['mapbox.access_token']; + leafletBaseLayerOptions.handle = mapConfig['mapbox.map_id']; + leafletBaseLayerOptions.subdomains = mapConfig.subdomains || 'abcd'; + leafletBaseLayerOptions.attribution = mapConfig.attribution || 'Data: OpenStreetMap, Design: MapBox'; + } else if (mapConfig.type == 'custom') { + // Custom XYZ layer + baseLayerUrl = mapConfig['custom.url']; + if (mapConfig.subdomains) leafletBaseLayerOptions.subdomains = mapConfig.subdomains; + leafletBaseLayerOptions.attribution = mapConfig.attribution; // Custom multi-layer map } else if (mapConfig.type === 'multilayer') { // parse layer-specific mapConfig properties into array of layers @@ -110,21 +103,17 @@ delete mc.layerprops; return(mc); })(mapConfig); - - } else { - // MapQuest OpenStreetMap base map - if (isHttps) { - baseLayerUrl = '//otile{s}-s.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'; - } else { - baseLayerUrl = '//otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'; - } - leafletBaseLayerOptions.subdomains = mapConfig.subdomains || '1234'; - leafletBaseLayerOptions.attribution = mapConfig.attribution || - 'Map data © OpenStreetMap contributors, Tiles Courtesy of ' + - 'MapQuest ' + - ''; - } - + } else { + // MapQuest OpenStreetMap base map + if (isHttps) { + baseLayerUrl = '//otile{s}-s.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'; + } else { + baseLayerUrl = '//otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'; + } + leafletBaseLayerOptions.subdomains = mapConfig.subdomains || '1234'; + leafletBaseLayerOptions.attribution = mapConfig.attribution || 'Map data © OpenStreetMap contributors, Tiles Courtesy of MapQuest '; + } + if (mapConfig.type === 'multilayer') { mapConfig.layerlist.forEach(function (lname) { var url = mapConfig[lname].url;