Here are the steps to achieve this:
- Create an array that contains all the positions of the markers. Basically, add you create your markers, copy the position value into an array.
- Pass this array into the
atlas.data.BoundingBox.fromPositions
method to calculate the bounding box of the data. - Use the maps
setCamera
function and pass the bounding box value in as thebounds
property. Set thepadding
property to something like50
to account for the pixel size of the marker.
Here is a quick sample:
var markerPositions = [];
//Add code to add marker position from marker when creating marker.
//Calculate bounding box.
var bbox = atlas.data.BoundingBox.fromPositions(markerPositions);
//Set map camera.
map.setCamera({
bounds: bbox,
padding: 50
});