-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[bug] map.queryRenderedFeatures() doesn't account for {text,icon}-offset or {text,icon}-rotate #6075
Comments
Closes #6075 `textPixelRatio` is used to scale tile coordinates to viewport coordinates; the value that was being passed here, EXTENT / tileSize, was the reciprocal of the ratio needed -- we were passing 16 instead of 0.0625. As a result, the corners of the viewport-projected collision box that we reconstructed here, https://github.com/mapbox/mapbox-gl-js/blob/f13c86ea356c384fdab31855b9152f5bf5ef97b8/src/symbol/collision_index.js#L322-L325, were 16^2 times farther from the anchor than they should have been. With `icon-offset: [0, 0]`, this didn't matter, because the incorrectly large box would contain the (much smaller) correct box. But when there's an offset, it too gets scaled too much, and so we run out of luck.
* Add failing test for issue #6075 * Fix incorrect textPixelRatio argument Closes #6075 `textPixelRatio` is used to scale tile coordinates to viewport coordinates; the value that was being passed here, EXTENT / tileSize, was the reciprocal of the ratio needed -- we were passing 16 instead of 0.0625. As a result, the corners of the viewport-projected collision box that we reconstructed here, https://github.com/mapbox/mapbox-gl-js/blob/f13c86ea356c384fdab31855b9152f5bf5ef97b8/src/symbol/collision_index.js#L322-L325, were 16^2 times farther from the anchor than they should have been. With `icon-offset: [0, 0]`, this didn't matter, because the incorrectly large box would contain the (much smaller) correct box. But when there's an offset, it too gets scaled too much, and so we run out of luck.
* Add failing test for issue mapbox#6075 * Fix incorrect textPixelRatio argument Closes mapbox#6075 `textPixelRatio` is used to scale tile coordinates to viewport coordinates; the value that was being passed here, EXTENT / tileSize, was the reciprocal of the ratio needed -- we were passing 16 instead of 0.0625. As a result, the corners of the viewport-projected collision box that we reconstructed here, https://github.com/mapbox/mapbox-gl-js/blob/f13c86ea356c384fdab31855b9152f5bf5ef97b8/src/symbol/collision_index.js#L322-L325, were 16^2 times farther from the anchor than they should have been. With `icon-offset: [0, 0]`, this didn't matter, because the incorrectly large box would contain the (much smaller) correct box. But when there's an offset, it too gets scaled too much, and so we run out of luck.
* Add failing test for issue mapbox#6075 * Fix incorrect textPixelRatio argument Closes mapbox#6075 `textPixelRatio` is used to scale tile coordinates to viewport coordinates; the value that was being passed here, EXTENT / tileSize, was the reciprocal of the ratio needed -- we were passing 16 instead of 0.0625. As a result, the corners of the viewport-projected collision box that we reconstructed here, https://github.com/mapbox/mapbox-gl-js/blob/f13c86ea356c384fdab31855b9152f5bf5ef97b8/src/symbol/collision_index.js#L322-L325, were 16^2 times farther from the anchor than they should have been. With `icon-offset: [0, 0]`, this didn't matter, because the incorrectly large box would contain the (much smaller) correct box. But when there's an offset, it too gets scaled too much, and so we run out of luck.
The actual issue here was due to |
Hi @anandthakker, thanks for working on this. Unfortunately, this isn't fixed in Note that the cursor should be set to "pointer" when hovered over the wrench, and "" otherwise. The wrench is rotated 90 degrees, but the "hover" zone doesn't consider the rotation. |
Oof, thanks @mike-marcacci. Reopening for the |
Per chat with @ChrisLoer, the best way to fix this is most likely to use a covering of circles (like we do for line-placed labels) rather than a box. |
@anandthakker @mike-marcacci is there a workaround for this? |
@santinogue there isn't one that I've found. Fortunately, while this bug is live for us, we're in a "closed beta" of sorts, so we've been able to explain how to "click above the handle" to the limited users... but it's definitely a bad experience :-/ Depending on exactly what you're trying to accomplish, you might consider arranging a set of small transparent icons where you would expect the visual area to be, and use them as click/mouse targets... |
Hey @anandthakker! I just wanted to check up on this – is this guy planned for an upcoming release by chance? If not, I'd be happy to work on it if you could elaborate on your "covering of circles" strategy. |
Hey @mike-marcacci - nope, this isn't specifically planned for a release yet. The strategy @ChrisLoer and I had in mind was to use "collision circles" to represent rotated symbol features, rather than viewport-aligned rectangles. Currently, we only use collision circles for text labels that have
addSymbol in symbol_layout.js : mapbox-gl-js/src/symbol/symbol_layout.js Lines 207 to 211 in 66c0e33
So we'd need to refactor these a bit to add an additional path for using a set of collision circles also in the case where we have Also worth noting #5474, which would simplify some of the collision circle logic. |
Agree with @anandthakker that the full fix here is to use collision circles to represent rotated icon geometry -- but just wanted to note that part of the problem may be easier to solve:
|
I experimented with a simple implementation of this in I'm going to look into doing the harder part of #4798 (handling line labels) to see if it makes sense to pull into one PR. I'll also take a look at #4861 (handling |
@ChrisLoer, what's the recommended way to use collision circles with queryRenderedFeatures? My idea is to simply use How would you cover symbols with multiple circles? Would you add multiple layers with 0 opacity? I'm trying to find a workaround for #6621 |
Hi @hyperknot sorry for the confusion, but "collision circles" here refers to an underlying implementation detail -- there's nothing that's directly accessible to you as an SDK user. The good news is, I think #6621 is mainly a duplicate of a bug that we recently fixed and should ship this week! 😄 |
Fixes issue #6075. Does not fix collision detection for point symbols with *-rotation-alignment: map, or for line-placed symbols with *-offset set.
Fixes issue #6075. Does not fix collision detection for point symbols with *-rotation-alignment: map, or for line-placed symbols with *-offset set.
Fixes issue #6075. Does not fix collision detection for point symbols with *-rotation-alignment: map, or for line-placed symbols with *-offset set.
Fixed @mike-marcacci and @santinogue, will this address your current issues? We're still tracking offsets for line-placed labels separately as #4798 and point labels with |
Hi @ChrisLoer! Thank you so much for working on this. I just built master (making sure it includes #6631) and tested it against the example in the fiddle above, and sadly it didn't work. I've got a little bit of time right now to look into this further, so I'll post back once I have more to offer! |
Actually, scratch that. It looks like it built from a stale cache. I can confirm that this is fixed!! Thanks SO much! |
NOTE: this bug cannot be reproduced in mapbox-gl-js 0.44.0, because it is blocked by this other, more serious bug.
Using v0.43.0, map.queryRenderedFeatures() doesn't account for the
icon-rotate
layout property ofsymbol
layers, and returns runs as if it were set to0
.VIEW SCREENCAST
The text was updated successfully, but these errors were encountered: