1
votes

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?

1
Do you have 2 bounding boxes and want the center of each one, or do you have one bounding box and the 2 locations correspond to the southwest and northeast corners? - LuisTavares
@lusitanica, I have 2 bounding boxes and need to get the center of each one - Nady
The 1st bbox coordinates: [110.2672863, -7.1144639, 110.5088836, -6.9319917] The 2nd bbox coordinates: [106.4784234, -6.3744575, 106.973975, -5.6480984] - Nady

1 Answers

1
votes

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).