Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a callback after map.fitBounds?

My code :

if(!bounds.isEmpty()) {
    map.fitBounds(bounds);
    if (map.getZoom() > 11) {
        map.setZoom(11);
    }   
}  

but I see that map.setZoom(11); could be called before .fitBounds end. So the result is not what I aspect for.

Is there a way to manage a callback when .fitBound finish?

like image 913
markzzz Avatar asked May 31 '12 14:05

markzzz


1 Answers

Try this:

 if(!bounds.isEmpty()) {
    map.fitBounds(bounds);
    google.maps.event.addListenerOnce(map, 'idle', function() {
        if (map.getZoom() > 11) {
            map.setZoom(11);
        }  
    });
} 
like image 103
Rick Avatar answered Oct 19 '22 08:10

Rick