mapserver/server/static/js/LayerManager.js
Thomas Rudin 8cc9a67215 fix #17
2019-03-13 21:28:14 +01:00

44 lines
913 B
JavaScript

'use strict';
function LayerManager(layers, map){
this.listeners = [];
this.currentLayer = layers[0];
this.layers = layers;
var self = this;
map.on('baselayerchange', function (e) {
console.log("baselayerchange", e.layer);
self.setLayerId(e.layer.layerId);
});
}
LayerManager.prototype.setLayerId = function(layerId){
var self = this;
this.layers.forEach(function(layer){
if (layer.id == layerId){
self.currentLayer = layer;
self.listeners.forEach(function(listener){
listener(layer);
});
return;
}
});
},
LayerManager.prototype.addListener = function(listener){
this.listeners.push(listener);
};
LayerManager.prototype.removeListener = function(listener){
this.listeners = this.listeners.filter(function(el){
return el != listener;
});
};
LayerManager.prototype.getCurrentLayer = function(){
return this.currentLayer;
};