-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Enable Within
Expression with paint property + Filter Expression
#16157
Conversation
Within
Expression with paint propertyWithin
Expression with paint property + Filter Expression
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.
Do we have tests for the new expression?
ccc57ee
to
b9c9918
Compare
@zmiao do you anticipate extending |
b9c9918
to
93aa3db
Compare
src/mbgl/style/expression/within.cpp
Outdated
} | ||
if (wn != 0) { | ||
return 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.
Here, you return a result immediately if you're inside the first ring, even if subsequent holes negate that result — this leads to incorrect results with holes.
Another small gotcha is that GL Native resolves overlapping rings in a polygon with an even-odd rule instead of a non-zero one, so you want to return true
if wn
is even, not necessarily zero.
If so, you could remove the branching into two loops and simplify the code — here's an example from one of my library of the same routine: https://github.com/mapbox/which-polygon/blob/master/index.js#L81-L95
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.
One more point — the naming pointWithinPolygons
is a little misleading, since you're testing against a single polygon which has multiple rings (an outer ring and holes), not multiple polygons.
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.
fixed!
2ccbd68
to
3cdc8dc
Compare
dfe8285
to
a48cc17
Compare
@mourner In our initial plan, we planned to implement the |
21ae274
to
7dd1483
Compare
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.
The algorithmic fixes look 👍 (will leave the C++/native-specific code for others to review)
3c3d0f8
to
e9c6eba
Compare
a868c3c
to
2f3cd78
Compare
Add geometry type checker
add canonical as pointer fix review findings
Fix polygon within algorithm Add Unit tests Fix incorrect metrics folder for ios-render-test-runner job
Address review findings/nit
2f3cd78
to
4e66246
Compare
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.
lgtm, +changelog
…nd filter expression
d8b568a
to
3c065b8
Compare
This pr introduces a new expression type
within
. Currently the usage is: [within
,geoJSONObj
]. It returns true if the feature is inside the geometry boundary that defined bygeoJSONObj
.geoJSONObj
should be inlined.This pr also enables the usages of setting paint property and filter expression with
within
expression. Following example shows how to set different color based on the feature's geometry location.With the variation of geometry types, there would be different within cases, like point within polygon, line within polygon, polygon within polygon, etc. Right now we only support point/points within polygon/polygons.