1
0
forked from MTSR/mapserver

unregister on/remove-layer hook on 'unload'

This commit is contained in:
Thomas Rudin 2019-09-01 11:10:56 +02:00
parent 03757becfd
commit 539e187475

View File

@ -9,6 +9,16 @@ function save(){
localStorage["mapserver-customOverlays"] = JSON.stringify(customOverlays); localStorage["mapserver-customOverlays"] = JSON.stringify(customOverlays);
} }
function onAddLayer(e){
customOverlays[e.name] = true;
save();
}
function onRemoveLayer(e){
customOverlays[e.name] = false;
save();
}
export default function(map, overlays){ export default function(map, overlays){
Object.keys(customOverlays) Object.keys(customOverlays)
@ -27,14 +37,12 @@ export default function(map, overlays){
} }
}); });
map.on('overlayadd', e => { map.on('unload', () => {
customOverlays[e.name] = true; map.off('overlayadd', onAddLayer);
save(); map.off('overlayremove', onRemoveLayer);
}); });
map.on('overlayremove', e => { map.on('overlayadd', onAddLayer);
customOverlays[e.name] = false; map.on('overlayremove', onRemoveLayer);
save();
});
} }