Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple layers #138

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 69 additions & 7 deletions ckanext/spatial/public/js/common_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,56 @@
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);
}
}
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);
}
}
// 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) {
Expand All @@ -64,11 +114,23 @@
leafletBaseLayerOptions.attribution = mapConfig.attribution || 'Map data &copy; OpenStreetMap contributors, Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="//developer.mapquest.com/content/osm/mq_logo.png">';
}

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);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% if map_config.type == 'custom' %}
{% if map_config.type == 'custom' or map_config.type == 'multilayer' %}
<div>{{ map_config.attribution|safe }}</div>
{% else %}
<div>Map data &copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors</div>
Expand Down