map: define layers in config.js
This commit is contained in:
parent
9ea5d67bf2
commit
3954ec5eaf
3 changed files with 42 additions and 11 deletions
30
lib/map.js
30
lib/map.js
|
@ -129,6 +129,7 @@ define(["map/clientlayer", "map/labelslayer",
|
|||
var map, userLocation
|
||||
var layerControl
|
||||
var customLayers = new Set()
|
||||
var baseLayers = {}
|
||||
|
||||
var locateUserButton = new LocateButton(function (d) {
|
||||
if (d)
|
||||
|
@ -186,6 +187,9 @@ define(["map/clientlayer", "map/labelslayer",
|
|||
}
|
||||
|
||||
function addLayer(layerName) {
|
||||
if (layerName in baseLayers)
|
||||
return
|
||||
|
||||
if (customLayers.has(layerName))
|
||||
return
|
||||
|
||||
|
@ -212,12 +216,18 @@ define(["map/clientlayer", "map/labelslayer",
|
|||
|
||||
map = L.map(el, options)
|
||||
|
||||
var baseLayer = L.tileLayer("https://otile{s}-s.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg", {
|
||||
subdomains: "1234",
|
||||
type: "osm",
|
||||
attribution: "Tiles © <a href=\"https://www.mapquest.com/\" target=\"_blank\">MapQuest</a>, Data CC-BY-SA OpenStreetMap",
|
||||
maxZoom: 18
|
||||
}).addTo(map)
|
||||
var layers = config.mapLayers.map( function (d) {
|
||||
return {
|
||||
"name": d.name,
|
||||
"layer": "url" in d ? L.tileLayer(d.url, d.config) : L.tileLayer.provider(d.name)
|
||||
}
|
||||
})
|
||||
|
||||
layers[0].layer.addTo(map)
|
||||
|
||||
layers.forEach( function (d) {
|
||||
baseLayers[d.name] = d.layer
|
||||
})
|
||||
|
||||
map.on("locationfound", locationFound)
|
||||
map.on("locationerror", locationError)
|
||||
|
@ -231,13 +241,13 @@ define(["map/clientlayer", "map/labelslayer",
|
|||
addLayer(layerName)
|
||||
}))
|
||||
|
||||
layerControl = L.control.layers({"MapQuest": baseLayer}, [], {position: "bottomright"})
|
||||
layerControl = L.control.layers(baseLayers, [], {position: "bottomright"})
|
||||
|
||||
if (localStorageTest()) {
|
||||
var layers = JSON.parse(localStorage.getItem("map/customLayers"))
|
||||
var d = JSON.parse(localStorage.getItem("map/customLayers"))
|
||||
|
||||
if (layers)
|
||||
layers.forEach(addLayer)
|
||||
if (d)
|
||||
d.forEach(addLayer)
|
||||
}
|
||||
|
||||
var clientLayer = new ClientLayer({minZoom: 15})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue