React-native-mapbox-gl: Accept array of coordinates in `fitBounds`/`setCamera`

Created on 5 Dec 2017  路  3Comments  路  Source: nitaliano/react-native-mapbox-gl

I have to center a polyline of a route, the route can have multiple coordinate points and look like this:

image

It sort of starts and finishes in the same point so I have to find the farthest coordinate (loop through the coordinates and calculate their distances) and do fitBounds(firstPoint, farthestPoint), it would be awesome if fitBounds would accept an array and center everything by its own.

@nitaliano: if it's not possible, do you have any suggestion on how to do this faster?

Most helpful comment

@lucasbento you should use turfjs for this you can think of it as underscore for anything geo related. It's highly optimized and using turf means you can share code between mobile and web.

These are quick links to the two functions that @kristfal described above that will be able to solve this issue for you.

http://turfjs.org/docs#bbox
http://turfjs.org/docs#bboxPolygon

All 3 comments

My solution didn't work for some cases with strange routes, ended up using bound-points which works nice!

For general geo processing, I'd recommend Turf JS. In this particular case, bbox or bbox-polygon would also have solved your issue.

@lucasbento you should use turfjs for this you can think of it as underscore for anything geo related. It's highly optimized and using turf means you can share code between mobile and web.

These are quick links to the two functions that @kristfal described above that will be able to solve this issue for you.

http://turfjs.org/docs#bbox
http://turfjs.org/docs#bboxPolygon

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zeljkoX picture zeljkoX  路  4Comments

Gp2mv3 picture Gp2mv3  路  3Comments

lernerbot picture lernerbot  路  3Comments

kristfal picture kristfal  路  3Comments

olofd picture olofd  路  3Comments