1
0
forked from MTSR/mapserver
mapserver/server/static/js/LayerManager.js

44 lines
913 B
JavaScript
Raw Normal View History

2019-02-01 14:58:26 +03:00
'use strict';
2019-01-29 23:07:29 +03:00
2019-02-01 15:20:50 +03:00
function LayerManager(layers, map){
2019-02-01 15:28:26 +03:00
this.listeners = [];
this.currentLayer = layers[0];
2019-02-15 19:33:49 +03:00
this.layers = layers;
2019-02-01 15:20:50 +03:00
2019-03-13 23:28:14 +03:00
var self = this;
2019-02-01 15:20:50 +03:00
map.on('baselayerchange', function (e) {
console.log("baselayerchange", e.layer);
2019-03-13 23:28:14 +03:00
self.setLayerId(e.layer.layerId);
2019-02-01 15:20:50 +03:00
});
2019-02-01 15:28:26 +03:00
2019-02-01 14:58:26 +03:00
}
2019-01-29 23:07:29 +03:00
2019-02-15 17:51:11 +03:00
LayerManager.prototype.setLayerId = function(layerId){
var self = this;
this.layers.forEach(function(layer){
if (layer.id == layerId){
self.currentLayer = layer;
2019-03-13 23:28:14 +03:00
self.listeners.forEach(function(listener){
listener(layer);
});
return;
2019-02-15 17:51:11 +03:00
}
});
},
2019-02-01 14:58:26 +03:00
LayerManager.prototype.addListener = function(listener){
2019-02-01 15:28:26 +03:00
this.listeners.push(listener);
};
LayerManager.prototype.removeListener = function(listener){
this.listeners = this.listeners.filter(function(el){
return el != listener;
});
2019-02-01 14:58:26 +03:00
};
2019-01-29 23:07:29 +03:00
2019-02-01 14:58:26 +03:00
LayerManager.prototype.getCurrentLayer = function(){
2019-02-01 15:28:26 +03:00
return this.currentLayer;
2019-02-01 14:46:38 +03:00
};