-
Notifications
You must be signed in to change notification settings - Fork 92
Description
I'm using destroy() to clean-up the map before removing it from DOM. I noticed that there's an issue on mobile devices.
setupContainerTouchEvents is using EventHandler to bind events:
EventHandler.on(map.container, 'touchstart', handleTouchEvent)
EventHandler.on(map.container, 'touchmove', handleTouchEvent)Unfortunately, EventHandler is setting handler._uid = uid, therefore handleTouchEvent at first receives _uid = 'jvm:touchstart::14' and then _uid = 'jvm:touchmove::15'. This causes an issue for off() method which uses delete eventRegistry[handler._uid] and because jvm:touchmove::15 is removed as jvm:touchstart::14, EventHandler.off(eventRegistry[event].selector, event, eventRegistry[event].handler) receives undefined and throws an exception Uncaught TypeError: Cannot read properties of undefined (reading 'selector').
I think the most reliable way to fix this would be to rewrite the EventHandler.on method:
on(element, event, handler, options = {}) {
const uid = `jvm:${event}::${eventUid++}`
const eventHandler = (...args) => handler(...args)
eventRegistry[uid] = {
selector: element,
handler: eventHandler,
}
eventHandler._uid = uid
element.addEventListener(event, eventHandler, options)
},