From 8cc9a67215624a071e7057566b3f02873faa9de6 Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Wed, 13 Mar 2019 21:28:14 +0100 Subject: [PATCH] fix #17 --- server/static/js/Hashroute.js | 1 + server/static/js/LayerManager.js | 8 +++++++- server/static/js/RealtimeTileLayer.js | 4 ++-- server/static/js/main.js | 5 +++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/server/static/js/Hashroute.js b/server/static/js/Hashroute.js index 6027be9..18fd2fc 100644 --- a/server/static/js/Hashroute.js +++ b/server/static/js/Hashroute.js @@ -12,6 +12,7 @@ var Hashroute = { map.on('zoomend', updateHash) map.on('moveend', updateHash) + map.on('baselayerchange', updateHash) updateHash(); }, diff --git a/server/static/js/LayerManager.js b/server/static/js/LayerManager.js index b0fb54a..2aad0e9 100644 --- a/server/static/js/LayerManager.js +++ b/server/static/js/LayerManager.js @@ -5,9 +5,11 @@ function LayerManager(layers, map){ this.currentLayer = layers[0]; this.layers = layers; + var self = this; + map.on('baselayerchange', function (e) { console.log("baselayerchange", e.layer); - //TODO + self.setLayerId(e.layer.layerId); }); } @@ -17,6 +19,10 @@ LayerManager.prototype.setLayerId = function(layerId){ this.layers.forEach(function(layer){ if (layer.id == layerId){ self.currentLayer = layer; + self.listeners.forEach(function(listener){ + listener(layer); + }); + return; } }); }, diff --git a/server/static/js/RealtimeTileLayer.js b/server/static/js/RealtimeTileLayer.js index 7592d78..7fb4a21 100644 --- a/server/static/js/RealtimeTileLayer.js +++ b/server/static/js/RealtimeTileLayer.js @@ -2,7 +2,7 @@ var RealtimeTileLayer = L.TileLayer.extend({ - initialize: function(wsChannel, layerId) { + initialize: function(wsChannel, layerId, map) { var self = this; this.layerId = layerId; @@ -12,7 +12,7 @@ var RealtimeTileLayer = L.TileLayer.extend({ return; } - if (tc.zoom != self._map.getZoom()){ + if (tc.zoom != map.getZoom()){ //ignore other zoom levels return; } diff --git a/server/static/js/main.js b/server/static/js/main.js index acb116d..6af4c59 100644 --- a/server/static/js/main.js +++ b/server/static/js/main.js @@ -23,12 +23,13 @@ api.getConfig().then(function(cfg){ //All layers cfg.layers.forEach(function(layer){ - var tileLayer = new RealtimeTileLayer(wsChannel, layer.id); + var tileLayer = new RealtimeTileLayer(wsChannel, layer.id, map); layers[layer.name] = tileLayer; }); //current layer - layerMgr.getCurrentLayer().addTo(map); + var currentLayer = layerMgr.getCurrentLayer(); + layers[currentLayer.name].addTo(map); //All overlays Overlaysetup(cfg, map, overlays, wsChannel, layerMgr);