Skip to content
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

Distance expression operator #6062

Open
1ec5 opened this issue Jan 26, 2018 · 8 comments · May be fixed by #10616
Open

Distance expression operator #6062

1ec5 opened this issue Jan 26, 2018 · 8 comments · May be fixed by #10616
Assignees
Labels
cross-platform 📺 Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.) feature 🍏
Projects

Comments

@1ec5
Copy link
Contributor

1ec5 commented Jan 26, 2018

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

@1ec5 1ec5 added feature 🍏 cross-platform 📺 Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.) labels Jan 26, 2018
@anandthakker
Copy link
Contributor

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

@gorbypark
Copy link

gorbypark commented Jan 26, 2018

This should be possible using Turfjs/turf-distance and Turfjs/turf-centroid.

@1ec5
Copy link
Contributor Author

1ec5 commented Jan 26, 2018

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.

@1ec5
Copy link
Contributor Author

1ec5 commented Mar 2, 2020

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

@1ec5
Copy link
Contributor Author

1ec5 commented May 1, 2020

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

@avi-c
Copy link

avi-c commented Sep 15, 2020

Any chance this is being worked on now? There are several instances and customer use cases where it would be very helpful.

@enersis-pst
Copy link
Contributor

Can please someone tell if this feature will come this year for mapbox-gl? It looks like feature is full implemented since months.

@1ec5
Copy link
Contributor Author

1ec5 commented Jan 20, 2022

There’s a draft implementation in #10616.

@1ec5 1ec5 linked a pull request Jan 20, 2022 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cross-platform 📺 Requires coordination with Mapbox GL Native (style specification, rendering tests, etc.) feature 🍏
Projects
Expressions
  
API / Spec
Development

Successfully merging a pull request may close this issue.

6 participants