mapbox / mapbox-java

The Mapbox Java SDK – Java wrappers around Mapbox APIs and other location data
https://docs.mapbox.com/android/java/overview/
MIT License
424 stars 120 forks source link

Add Turf buffer method #987

Open danesfeder opened 5 years ago

danesfeder commented 5 years ago

Turf.js has a Turf#buffer method that would be useful for defining offline map regions. An example use case in navigation would be defining a buffer around a route geometry for an offline download:

buffer

@zugaldia mentioned that this may not be a straightforward port to java, possibly necessitating bringing in a third party library to get the job done. We need to look into this a bit further / discuss if that makes sense.

cc @osana @kevinkreiser

zugaldia commented 5 years ago

Thanks @danesfeder for cutting this ticket.

The old JS Turf Buffer implementation used https://github.com/bjornharrtell/jsts which is in turn a port of the Java library https://github.com/locationtech/jts. The latest JS Turf buffer seems to use something different (d3-geo?). I'd love to use this ticket to understand our options:

Particularly in terms of size implications. We're trying to keep MAS lightweight and this might require adding a separate artifact.

langsmith commented 5 years ago

Based on https://github.com/Turfjs/turf/blob/master/packages/turf-buffer/index.js#L1, I believe we'll also need to port center() before we can add the buffer method. buffer() could also unlock cool visuals like 👇 (Off the top of my head, I'm not sure how they're creating the white FillLayer area right now without buffer() 🤔 ). GIF is from the Flyover Country app: https://play.google.com/store/apps/details?id=com.ionicframework.app303739&hl=en_US

ezgif com-resize

stale[bot] commented 5 years ago

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

langsmith commented 4 years ago

Based on https://github.com/Turfjs/turf/blob/master/packages/turf-buffer/index.js#L1, I believe we'll also need to port center() before we can add the buffer method

Porting the center method is moving at https://github.com/mapbox/mapbox-java/pull/1150

langsmith commented 4 years ago

Having this buffer method would also help with detecting whether a line has been clicked on. For example, selecting an alternate route that the Mapbox Navigation SDK displays.

Rather than having to click exactly on the line, we could use the click lat/lng, the buffer Polygon, and the Java SDK's TurfJoins.inside() method.

zugaldia commented 4 years ago

@1ec5 @MaximAlien curious, how does iOS plan to support the UI to select an alternate route?

MaximAlien commented 4 years ago

@1ec5 @MaximAlien curious, how does iOS plan to support the UI to select an alternate route?

Current implementation of alternative route selection involves conversion of tapped point to coordinate. Alternative routes are then sorted by distance to tapped coordinate (there is minimum threshold as well).

Some examples of this logic can be found here and here.