React-mapbox-gl: onMouseEnter only called once when moved over overlapping circles

Created on 26 Sep 2017  路  6Comments  路  Source: alex3165/react-mapbox-gl

I'm currently plotting a lot of points on a map and some of them are overlapping each other. I want to show a popup when I hover over the points. Now I noticed that onMouseEnter is not called when I move the mouse from one circle to another, when the two are overlapping and onMouseLeave is not called in between.

I prepared an example for you. You have to zoom in a little bit until the circles look like for example in the following image. When you move your mouse horizontally over the circles, I would have expected a second console output as soon as the mouse is over an areas that is only covered by the second circle. However it isn't.

screen shot 2017-09-26 at 5 48 53 pm

Am I doing it wrong again or is this really a bug?

Thanks for the great work and your fast responses, that's awesome!

Bug Priority +

Most helpful comment

For this kind of thing, I use a GeoJSONLayer and listen to onMouseMove and onMouseLeave. In your mousemove event handler, you get the hovered feature with event.features[0] (and can access other features that are hovered (if any) with [1], [2], etc...). mouseleave is triggered when no feature is hovered

All 6 comments

Yes this is an issue due to the way we listen onMouseEnter and onMouseLeave in the Layer. React-mapbox-gl use the layer id to listen for those events so as long as your mouse is on one of the feature in the layer no event is being triggered.

A fix would be to remove the layerId being passed to the mouse event listener but I am affraid it would have some performance impacts, I would need to check this and I will prioritise this issue.

Ok, thanks a lot for the update

For this kind of thing, I use a GeoJSONLayer and listen to onMouseMove and onMouseLeave. In your mousemove event handler, you get the hovered feature with event.features[0] (and can access other features that are hovered (if any) with [1], [2], etc...). mouseleave is triggered when no feature is hovered

When #675 will be released, you can solve your problem by adding onMouseEnter and onMouseLeave to the <Layer> component.

It seems this issue still persists with the latest version of the lib (4.2.0). Either with the Layer or the Feature, the onMouseEnter/Leave events do not get triggered when moving the mouse between directly connected features without a gap.

Any plans on addressing this issue?

I am having the same issue, tried both events on the <Layer /> and the <Feature />

Has anyone found a good way to handle this?

Was this page helpful?
0 / 5 - 0 ratings