1
0
forked from MTSR/mapserver

fix layer switch

This commit is contained in:
Thomas Rudin 2019-04-22 17:17:41 +02:00
parent 2fb64772f4
commit d433897a6a
2 changed files with 6 additions and 6 deletions

View File

@ -1,7 +1,7 @@
/* exported LayerManager */ /* exported LayerManager */
/* globals RealtimeTileLayer: true */ /* globals RealtimeTileLayer: true */
function LayerManager(wsChannel, layers, map){ function LayerManager(wsChannel, layers, map, currentLayerId){
this.listeners = []; this.listeners = [];
this.currentLayer = layers[0]; this.currentLayer = layers[0];
this.layers = layers; this.layers = layers;
@ -14,15 +14,16 @@ function LayerManager(wsChannel, layers, map){
layers.forEach(function(layer){ layers.forEach(function(layer){
var tileLayer = new RealtimeTileLayer(wsChannel, layer.id, map); var tileLayer = new RealtimeTileLayer(wsChannel, layer.id, map);
self.layerObjects[layer.name] = tileLayer; self.layerObjects[layer.name] = tileLayer;
if (layer.id == currentLayerId){
tileLayer.addTo(map);
self.currentLayer = layer;
}
}); });
map.on('baselayerchange', function (e) { map.on('baselayerchange', function (e) {
self.setLayerId(e.layer.layerId); self.setLayerId(e.layer.layerId);
}); });
//current layer
var currentLayer = this.getCurrentLayer();
this.layerObjects[currentLayer.name].addTo(map);
} }
LayerManager.prototype.switchLayer = function(layerId){ LayerManager.prototype.switchLayer = function(layerId){

View File

@ -17,8 +17,7 @@ api.getConfig().then(function(cfg){
var overlays = {}; var overlays = {};
window.layerMgr = new LayerManager(wsChannel, cfg.layers, map); window.layerMgr = new LayerManager(wsChannel, cfg.layers, map, Hashroute.getLayerId());
layerMgr.setLayerId( Hashroute.getLayerId() );
//All overlays //All overlays
Overlaysetup(cfg, map, overlays, wsChannel, layerMgr); Overlaysetup(cfg, map, overlays, wsChannel, layerMgr);