To make the queryRenderedFeatures hitbox for a feature larger, it is necessary to generate a bounding box around the cursor. We should add a utility method to make this easier.
queryRenderedFeatures(LngLatBounds.createAroundPoint(event.point, 10, 10));
queryRenderedFeatures(event.point, { width: 10, height: 10 }); // define a rectangle
queryRenderedFeatures(event.point, { radius: 10 }); // define a circle
queryRenderedFeatures(event.point.outset(10, 10)); // define a rectangle
cc @lyzidiamond @jfirebaugh @mourner
cc @ebendennis, the user who inspired this question!
queryRenderedFeatures(event.point, { width: 10 }); // like radius, but square
Would this be:
radius: 5 with the old featuresAt)? orradius:10)? or20/Math.pow(2,0.5))?Besides the ambiguity @peterqliu points out, I think it鈥檚 important to be able to make the dx and dy different, which option 3 wouldn鈥檛 allow for.
@peterqliu @1ec5 Thanks for the feedback! I updated proposals above to be more clear.
I think using radius to describe any rectangle would be confusing. Proposal 2 is the least confusing to me 鉂わ笍
I think we should not add anything to the library. The code to do this is trivial: [[p.x - 5, p.y - 5], [p.x + 5, p.y + 5]].
Let's point people towards the solution above for now 鈽濓笍.
Let's point people towards the solution above for now 鈽濓笍.
This is probably the best answer, but won't decrease the support load of people asking this in the future. Is there some proactive way to communicate this, or do we just keep responding when the questions come?
We can make an example. Like https://www.mapbox.com/mapbox-gl-js/example/using-box-queryrenderedfeatures/ except on click.
I needed this. Didn't dare to ask and found it pretty hard to find. Especially the 'best practice' that you do not work with an actual radius but with a box is good to know. A simpler example than the one mentioned would have been helpful for me.
Oh, I didn't know this was possible - but was hoping there was a way to improve the hit-testing on very narrow line features.
My suggestion: update existing examples like https://www.mapbox.com/mapbox-gl-js/example/queryrenderedfeatures/ to use a bounding box. It's probably a better method for people to use by default.
Most helpful comment
I think we should not add anything to the library. The code to do this is trivial:
[[p.x - 5, p.y - 5], [p.x + 5, p.y + 5]].