forked from MTSR/mapserver
fix layer switch
This commit is contained in:
parent
2fb64772f4
commit
d433897a6a
@ -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){
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user