You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Filter expressions: Is it possible to filter polygons which contain a particular point? #9891
I have a layer containing geojson polygons, and I would like to filter it to polygons that contain a certain lat long point. I would like to devise a filter expression that accomplishes this. Looking through the reference of expressions, I see a "within" statement that returns true when a particular point is within a polygon. That is almost what I want, but its first argument is the point, and the second arg is the polygon to search. It is my understanding that when applying a filter to a layer, the item from the layer is going to be inserted at the beginning of the filter expression. This would not work for me then, as it would be trying to determine whether the polygon is within the point, which makes no sense. Is there any way I can manipulate the ordering of the filter expression, perhaps using variables, such that I can perform a query as to whether a particular point lies within a polygon for each polygon in a layer?
There isn't a contains expression that's the opposite of within. A possible workaround might be to use queryRenderedFeatures (or querySouceFeatures) to find the features that intersect with a particular point and then use setFeatureState to update the fill-opacity of your polygons, similar to the hover effect example. If you need more guidance, I'd recommend contacting Mapbox Support.
Activity
ryanhamley commentedon Jul 27, 2020
There isn't a
containsexpression that's the opposite ofwithin. A possible workaround might be to usequeryRenderedFeatures(orquerySouceFeatures) to find the features that intersect with a particular point and then usesetFeatureStateto update thefill-opacityof your polygons, similar to the hover effect example. If you need more guidance, I'd recommend contacting Mapbox Support.