Open 1ec5 opened 6 years ago
Something like ["geographic_distance", lng1, lat1, lng2, lat2]
would definitely be doable. I'm wary, though, of adding any expressions that refer to a feature's geometry, as that could open up a pretty big can of performance worms
This should be possible using Turfjs/turf-distance and Turfjs/turf-centroid.
I'm wary, though, of adding any expressions that refer to a feature's geometry, as that could open up a pretty big can of performance worms
Something I didn’t consider is that features from vector tiles are… tiled. So a feature centroid would only be meaningful for points plus polylines/polygons that are small enough to fit in a single tile at the current zoom level.
The upcoming within
expression operator (#9352) would enable a workaround for the lack of a distance operator: create a circle around the other coordinate, perhaps using turf-circle, then pass it into a within
expression. Depending on the number of steps (number of sides), this workaround could be much less performant than directly testing the distance between two points.
/cc @zmiao
A distance
expression operator was implemented in mapbox/mapbox-gl-native#16397, mapbox/mapbox-gl-native-android#339, and mapbox/mapbox-gl-native-ios#295 in every map SDK except GL JS.
The expression operator has not yet been added to the style specification, so a JSON stylesheet that includes it might fail validation (not sure).
/cc @chloekraw
Any chance this is being worked on now? There are several instances and customer use cases where it would be very helpful.
Can please someone tell if this feature will come this year for mapbox-gl? It looks like feature is full implemented since months.
There’s a draft implementation in #10616.
It would be nice to have an expression operator that evaluates to the physical distance between two geographic coordinates. Coupled with an operator that evaluates to the centroid of the current feature and even the ability to apply a gradient to a shape (#4095), it would enable interesting visualizations that draw the viewer’s attention to a particular feature. A more mundane use case would be displaying the distance of each city on the map as you hover over a particular city.
This request is inspired by the
distanceToLocation:fromLocation:(there, here)
function built into NSExpression on iOS and macOS, which returns the distance in meters from the coordinate there to the coordinate here./cc @anandthakker