React-mapbox-gl: Map.off() doesnt work

Created on 17 Dec 2019  路  6Comments  路  Source: alex3165/react-mapbox-gl

When trying to remove and event handler use Map.off this is not working as expected

Expected behaviour
A click event listener should be removed
/mapContext.off('click',layer_id, function);

All 6 comments

You need to get the map instance using the map context as described in the documentation. That's what you can call this method on.

The context is a React way of providing this instance wherever you need it, without things like render props. The context is NOT the map instance. If the docs are unclear, please open a separate issue.

Adding the event listeners seems to work, I am using the map instance that is provided in the MapContext.Consumer, to add the event listeners to layers, and they work as expected, however removing them doesn't seem to work?

any further help with this would be greatly appreciated

That sounds like an issue with mapbox-gl-js instead of react-mapbox-gl then... This library isn't doing anything to alter the calls to the map instance.

Thanks for the help, I appreciate it.

Any workaround for map.off in React?
The same here, adding event works perfectly but turn if off doenst affect at all, not even errors.

That sounds like an issue with mapbox-gl-js instead of react-mapbox-gl then... This library isn't doing anything to alter the calls to the map instance.

https://github.com/mapbox/mapbox-gl-js/issues/7782

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JoshuaVulcan picture JoshuaVulcan  路  4Comments

appjitsu picture appjitsu  路  3Comments

jonheslop picture jonheslop  路  4Comments

13milliseconds picture 13milliseconds  路  4Comments

cyrilchapon picture cyrilchapon  路  3Comments