Skip to content

Error while destroying the map #205

@andrzej-aa

Description

@andrzej-aa

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)
  },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions