-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix queryRenderedFeatures for symbol features #3459
Conversation
Possible fix for #2647. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me, let's 🚢 after addressing my minor remarks.
const sourceLayer = blocking.sourceLayerIndex; | ||
const featureIndex = blocking.featureIndex; | ||
if (sourceLayerFeatures[sourceLayer] === undefined) { | ||
sourceLayerFeatures[sourceLayer] = {}; | ||
} | ||
return sourceLayerFeatures[sourceLayer][featureIndex] === true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this function does not need any variables from the outer scope (it gets everything it needs from arguments), move it out to the top level scope. This way you avoid the cost of setting up a closure on every call of queryRenderedSymbols
.
// Check if feature is rendered (collision free) at current scale. | ||
function visibleAtScale(blocking, roundedScale) { | ||
return roundedScale >= blocking.placementScale && roundedScale <= blocking.maxScale; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for this function.
new Point(x1, y2) | ||
]; | ||
return intersectionTests.polygonIntersectsPolygon(rotatedQuery, bbox); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this one too, if you pass bbox
as an argument.
@@ -0,0 +1,52 @@ | |||
'use strict'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these be consolidated with util/intersection_tests.js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my - totally missed this - yes we can certainly reuse it 👍
af691b4
to
b1cb5a0
Compare
b1cb5a0
to
b876b1b
Compare
Thank you @mourner and @jfirebaugh for the review - I've addressed the requested changes. |
b876b1b
to
c8d04a6
Compare
c8d04a6
to
b68f607
Compare
@mourner it turns out those functions made more sense in GL native context because we were using them as predicates for |
Use the query geometry as polygon for intersecting with symbol features collision box. Fixes situations where e.g. unseen features were returned or vice-versa.
This PR is a port from GL native (see mapbox/mapbox-gl-native#6773).
Query test
symbol-features-in/pitched-screen
(#3447) should be passing now, but because the feature order differs from GL native, the test fails. We should probably sort features by latitude/longitude prior to JSON comparison.Benchmark reports are within standard deviation:
/cc @ansis @jfirebaugh @mourner