SERG
SERG

Reputation: 3971

How to get bounds after MapboxGeocoder flyto event?

Looks like if I call map.getBounds inside geocoder I always get the previous results. Is there a callback or something to get the bounds after geocode flies to the destinations. Here is my code:

var geocoder = new MapboxGeocoder({accessToken: mapboxgl.accessToken});
geocoder.on('result', function(ev) {

        console.log("CENTER:",ev.result.center);
        console.log("BOUNDS:",map.getBounds());
        //loadByBounds(map.getBounds());
    });

Upvotes: 3

Views: 1003

Answers (1)

Andi-lo
Andi-lo

Reputation: 2312

Maybe you can react to the mooveend event by applying an event listener.

"Mooveend: Fired just after the map completes a transition from one view to another, as the result of either user interaction or methods such as Map#jumpTo."

https://www.mapbox.com/mapbox-gl-js/api/#map.event:moveend

Upvotes: 2

Related Questions