Reputation: 13
please could anyone help?
I need to use a map.toFly() method to interpolate between 2 locations.
According to the Mapbox documentation, I need to pass in an object describing the destination I want to fly to. The object has to have a center property holding an array with centre Long/lat coordinates of the destination I need to be taken to.
https://docs.mapbox.com/mapbox-gl-js/example/flyto/
My problem with implementing the method is that I only have bounding box coordinates of the 2 locations between which I need to interpolate . I can’t do something like this: map.flyTo(bbox)
Does anyone know how to obtain centre Long/lat coordinates of each location based on their bbox coordinates?
Upvotes: 1
Views: 1209
Reputation: 2206
Assuming you have 2 LngLatBounds
objects you can call the getCenter()
method.
var point1 = bounds1.getCenter();
var point2 = bounds2.getCenter();
where both bounds1
and bounds2
are objects of the type LngLatBounds
.
Check: https://docs.mapbox.com/mapbox-gl-js/api/#lnglatbounds#getcenter
Edit: for the values you gave in your comment it would be for the first bounds:
var sw1 = new mapboxgl.LngLat(110.2672863, -7.1144639);
var ne1 = new mapboxgl.LngLat(110.5088836, -6.9319917);
var bounds1 = new mapboxgl.LngLatBounds(sw1, ne1);
Note: Mapbox GL uses longitude, latitude coordinate order (as opposed to latitude, longitude).
Upvotes: 1