This commit is contained in:
Thomas Rudin 2019-03-13 21:28:14 +01:00
parent d878501070
commit 8cc9a67215
4 changed files with 13 additions and 5 deletions

View File

@ -12,6 +12,7 @@ var Hashroute = {
map.on('zoomend', updateHash) map.on('zoomend', updateHash)
map.on('moveend', updateHash) map.on('moveend', updateHash)
map.on('baselayerchange', updateHash)
updateHash(); updateHash();
}, },

View File

@ -5,9 +5,11 @@ function LayerManager(layers, map){
this.currentLayer = layers[0]; this.currentLayer = layers[0];
this.layers = layers; this.layers = layers;
var self = this;
map.on('baselayerchange', function (e) { map.on('baselayerchange', function (e) {
console.log("baselayerchange", e.layer); 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){ this.layers.forEach(function(layer){
if (layer.id == layerId){ if (layer.id == layerId){
self.currentLayer = layer; self.currentLayer = layer;
self.listeners.forEach(function(listener){
listener(layer);
});
return;
} }
}); });
}, },

View File

@ -2,7 +2,7 @@
var RealtimeTileLayer = L.TileLayer.extend({ var RealtimeTileLayer = L.TileLayer.extend({
initialize: function(wsChannel, layerId) { initialize: function(wsChannel, layerId, map) {
var self = this; var self = this;
this.layerId = layerId; this.layerId = layerId;
@ -12,7 +12,7 @@ var RealtimeTileLayer = L.TileLayer.extend({
return; return;
} }
if (tc.zoom != self._map.getZoom()){ if (tc.zoom != map.getZoom()){
//ignore other zoom levels //ignore other zoom levels
return; return;
} }

View File

@ -23,12 +23,13 @@ api.getConfig().then(function(cfg){
//All layers //All layers
cfg.layers.forEach(function(layer){ cfg.layers.forEach(function(layer){
var tileLayer = new RealtimeTileLayer(wsChannel, layer.id); var tileLayer = new RealtimeTileLayer(wsChannel, layer.id, map);
layers[layer.name] = tileLayer; layers[layer.name] = tileLayer;
}); });
//current layer //current layer
layerMgr.getCurrentLayer().addTo(map); var currentLayer = layerMgr.getCurrentLayer();
layers[currentLayer.name].addTo(map);
//All overlays //All overlays
Overlaysetup(cfg, map, overlays, wsChannel, layerMgr); Overlaysetup(cfg, map, overlays, wsChannel, layerMgr);