From 971938507690324c59f93adc3baf74f82a00086f Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sun, 22 May 2016 12:30:31 +0200 Subject: [PATCH] map: dynamically select maxLayerZoom (#27) Fixes clients/names being hidden accidentally (in certain conditions). Also added auto-zoom-out to ensure zoom is in bounds --- lib/map.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/map.js b/lib/map.js index a9aa8f2..aca0097 100644 --- a/lib/map.js +++ b/lib/map.js @@ -290,12 +290,6 @@ define(["map/clientlayer", "map/labelslayer", } }) - var maxLayerZoom = Math.max.apply(Math, config.mapLayers.map( - function(d) { - return (typeof d.config !== "undefined" && typeof d.config.maxZoom !== "undefined") ? d.config.maxZoom : 18 - })) - - layers[0].layer.addTo(map) layers.forEach( function (d) { @@ -334,19 +328,23 @@ define(["map/clientlayer", "map/labelslayer", } } - map.on("baselayerchange", function(e) { - if (localStorageTest()) - localStorage.setItem("map/selectedLayer", JSON.stringify({name: e.name})) - }) - - var clientLayer = new ClientLayer({minZoom: 15, maxZoom: maxLayerZoom}) + var clientLayer = new ClientLayer({minZoom: 15}) clientLayer.addTo(map) clientLayer.setZIndex(5) - var labelsLayer = new LabelsLayer({maxZoom: maxLayerZoom}) + var labelsLayer = new LabelsLayer({}) labelsLayer.addTo(map) labelsLayer.setZIndex(6) + map.on("baselayerchange", function(e) { + map.options.maxZoom = e.layer.options.maxZoom + clientLayer.options.maxZoom = map.options.maxZoom + labelsLayer.options.maxZoom = map.options.maxZoom + if (map.getZoom() > map.options.maxZoom) map.setZoom(map.options.maxZoom) + if (localStorageTest()) + localStorage.setItem("map/selectedLayer", JSON.stringify({name: e.name})) + }) + var nodeDict = {} var linkDict = {} var highlight