How to programmatically set map zoom level so all points are displayed

Is it possible to call tt.map({…}) and let it automatically set the zoom level so that all points are displayed no matter how far apart they are? If the TomTom API can’t do that itself, then does anyone know how to do that programmatically? So far I have used code described here to calculate the center coordinates for a given set of latitudes and longitudes so my code can set the center of a map like this:
var midPoint = [call to function that determines midpoint of a set of lats and longs];
var map = tt.map({
container: ‘map’,
key: ‘[my key]’,
center: midPoint,
zoom: 11
});
If the zoom level could be determined programmatically too then all points could be seen at the same time. All help is greatly appreciated.

Hi,
You can try to approach this problem in a bit different way and center a map to the bounds which you can get from your coordinates.

var bounds = [[-10, 52], [10, 55]];
tt.map.fitBounds(bounds, {
 padding: { top: 10, bottom:25, left: 15, right: 5 }
 maxZoom: 12
});
1 Like