Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse events do not trigger correctly on LineStrings that are offset with line-offset #9419

Open
elementalhub opened this issue Mar 12, 2020 · 11 comments
Labels

Comments

@elementalhub
Copy link

elementalhub commented Mar 12, 2020

mapbox-gl-js version: 1.8.1

browser: Chrome 80

Steps to Trigger Behavior

  1. Draw a LineString and offset it with line-offset by any amount (e.g. line-offset: 25)
  2. Add a map click event and use map.queryRenderedFeatures() to query the features under the mouse pointer.
  3. The mouse event will trigger inconsistently along the line. It seems at one end of the line the mouse event is in sync with the painted line and while moving along the line towards the other end it seems the line-offset is not respected any longer.

Link to Demonstration

In the image below the dark green line is the LineString with a line-offset as drawn by mapbox. The yellow line (added via photoshop) represents where the mouse pointer needs to be to trigger a click or hover event on that green line.

linestring-with-offset

Expected Behavior

I expect that the mouse event triggers precisely when the mouse pointer is over the offset line. In my example image above I would expect both lines (the green and the yellow) to match up.

Actual Behavior

The mouse event triggers inconsistently along the line.

It seems the features that get returned from queryRenderedFeatures are not the same features that are painted on a layer.

I also found these issues about text-offset and icon-offset, maybe this related?
#6624
#6075
#4798

Also something to note: if I use line-translate instead of line-offset the mouse events trigger correctly.

Any help or advice is greatly appreciated. Thanks!

@josh-p-thompson
Copy link

josh-p-thompson commented Apr 8, 2021

I'm encountering this bug as well. Any updates on this? line-translate is an onerous work-around.

@jack9ye
Copy link

jack9ye commented Apr 9, 2021

Just come up with a primitive fix:
jack9ye@ad2df2d

@vahagnsarg
Copy link

I am experiencing this problem at the moment. When offsetting either direction, the mouse hover seems to only trigger from the “original” location of the the LineString.

So when zooming in, the offset becomes larger but the hover section stays in the same place.

@karen1au
Copy link

karen1au commented Aug 3, 2021

I'm getting the same behaviour on icon-translate for symbol layers. Visually the icon is in a new place but the event is still attached to the original coordinates.

@vahagnsarg
Copy link

vahagnsarg commented Aug 3, 2021

I have come up with a work around that works quite well.

Instead of using the offset feature from LineString options I offset the feature JSON via turf utilities using the lineOffset util.

https://turfjs.org/docs/#lineOffset

It offsets the coordinates rather than the LineString graphic so the mouse events also gets offset.

Example:
lineOffset(featureJson, -4, { units: 'meters' })

@sreejithvelath
Copy link

sreejithvelath commented Mar 15, 2022

I am also facing the same issue. The mouse clicks are still pointing to the original line instead of new line-offset. In my case I cannot use line-translate because line-translate doesn't work with expressions - (#6480).
ANY UPDATE on this line-offset and mouse events issue would really help.

@vahagnsarg
Copy link

I am also facing the same issue. The mouse clicks are still pointing to the original line instead of new line-offset. In my case I cannot use line-translate because line-translate doesn't work with expressions - (#6480).

ANY UPDATE on this line-offset and mouse events issue would really help.

Have you looked at the work around provided above? It works quite well if you know the offset distance in meters/kilometres.

@sreejithvelath
Copy link

sreejithvelath commented Mar 15, 2022

Hi @vahagnsarg I haven't tried it. I don't want to change the actual coordinate values because those values are required for backend processing. I want the offset only for visualization purpose. Also, my layers are Vector Tile layers and not loaded from GeoJSON. Hence the I cannot apply the offset on featureJson

@nrathi
Copy link

nrathi commented Sep 28, 2022

+1 on this issue, could you please prioritize a fix? As others have mentioned, line-translate is tedious workaround.

@wade-flow-labs
Copy link

+1 on this issue, this is still broken.

@nielsswinkels
Copy link

nielsswinkels commented Oct 21, 2024

Using 3.7.0 this is still broken. It gets really confusing when hover does not trigger in a way that makes sense. At some points in my testing it did not even trigger at all on some lines.

Edit: Now I see there are 1257 open issues on this repository...that might give a hint on why this hasn't been fixed in 4 years. 🧐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants