I have a map with some layers, and the layers have different features on them. I have a function that iterates through each layer and creates an extent from all the features' geometry extent. Then I fit the map to this extent. I want to have a different center for the map and still fit all the features in the view of the map.
Is there a function that can enlarge/extend a given extent to have a new center?
I'm using OpenLayers 4.6.4 Example of code, below, so in essence I want to give a center parameter and have a function that extends/enlarges the extent already calculated.
/**
* Fits all the features in a layer on the map.
* @param {*Layer on map which should get all the features from} layer
*/
function fitLayersFeatureOnMap(layers, center) {
var featuresOnLayers = [];
_.each(layers, function(layer) {
featuresOnLayers.push(mapLayers[layer].getSource().getFeatures());
});
var extentOfAllFeatures = ol.extent.createEmpty();
_.each(_.flatten(featuresOnLayers), function (feature) {
ol.extent.extend(extentOfAllFeatures, feature.getGeometry().getExtent());
});
map.getView().fit(extentOfAllFeatures);
}