layer mgr impl

This commit is contained in:
NatureFreshMilk 2019-02-01 13:28:26 +01:00
parent 8a5194a9f8
commit e8a0c378f5
2 changed files with 23 additions and 1 deletions

View File

@ -1,15 +1,26 @@
'use strict';
function LayerManager(layers, map){
this.listeners = [];
this.currentLayer = layers[0];
map.on('baselayerchange', function (e) {
console.log("baselayerchange", e.layer);
//TODO
});
}
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;
};

View File

@ -10,10 +10,19 @@ var TravelnetIcon = L.icon({
var TravelnetOverlay = L.LayerGroup.extend({
initialize: function(wsChannel, layerMgr) {
this.layerMgr = layerMgr;
this.wsChannel = wsChannel;
this.onLayerChange = this.onLayerChange.bind(this);
},
onLayerChange: function(layer){
//TODO
},
onAdd: function(map) {
this.layerMgr.addListener(this.onLayerChange);
console.log("TravelnetOverlay.onAdd", map);
map.on('baselayerchange', function (e) {
@ -27,6 +36,8 @@ var TravelnetOverlay = L.LayerGroup.extend({
},
onRemove: function(map) {
this.layerMgr.removeListener(this.onLayerChange);
console.log("TravelnetOverlay.onRemove");
}
});