From 539e187475911c3b585ff82ca0d6cc60f7e25724 Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Sun, 1 Sep 2019 11:10:56 +0200 Subject: [PATCH] unregister on/remove-layer hook on 'unload' --- static/js/map/CustomOverlay.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/static/js/map/CustomOverlay.js b/static/js/map/CustomOverlay.js index dfe96f9..494b577 100644 --- a/static/js/map/CustomOverlay.js +++ b/static/js/map/CustomOverlay.js @@ -9,6 +9,16 @@ function save(){ 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){ Object.keys(customOverlays) @@ -27,14 +37,12 @@ export default function(map, overlays){ } }); - map.on('overlayadd', e => { - customOverlays[e.name] = true; - save(); + map.on('unload', () => { + map.off('overlayadd', onAddLayer); + map.off('overlayremove', onRemoveLayer); }); - map.on('overlayremove', e => { - customOverlays[e.name] = false; - save(); - }); + map.on('overlayadd', onAddLayer); + map.on('overlayremove', onRemoveLayer); }