I'm using openlayers 3 to create a map with vector features on top. So far, so good.
I have several vector layers, grouped in a variable called projecten.
var projecten = new ol.layer.Group({
title: 'Projecten',
layers: [
new ol.layer.Vector({
title: 'EVZ Den Dungen',
source: new ol.source.GeoJSON(
/** @type {olx.source.GeoJSONOptions} */ ({
object: EVZDenDungen,
projection: 'EPSG:3857'
})),
style: function(feature, resolution) {
return lookup[feature.get('landschapselement')];
}
}),
new ol.layer.Vector({
title: 'EVZ Croy',
source: new ol.source.GeoJSON(
/** @type {olx.source.GeoJSONOptions} */ ({
object: EVZCroy,
projection: 'EPSG:3857'
})),
style: function(feature, resolution) {
return lookup[feature.get('landschapselement')];
}
}),
new ol.layer.Vector({
title: 'Natuurcompensatie Gasselsbroek',
source: new ol.source.GeoJSON(
/** @type {olx.source.GeoJSONOptions} */ ({
object: NatuurcompensatieGasselsbroek,
projection: 'EPSG:3857'
})),
style: function(feature, resolution) {
return lookup[feature.get('landschapselement')];
}
}),
new ol.layer.Vector({
title: 'Ebben',
source: new ol.source.GeoJSON(
/** @type {olx.source.GeoJSONOptions} */ ({
object: Ebben,
projection: 'EPSG:3857'
})),
style: function(feature, resolution) {
return lookup[feature.get('landschapselement')];
}
}),
new ol.layer.Vector({
title: 'Zionsburg',
source: new ol.source.GeoJSON(
/** @type {olx.source.GeoJSONOptions} */ ({
object: Zionsburg,
projection: 'EPSG:3857'
})),
style: function(feature, resolution) {
return lookup[feature.get('landschapselement')];
}
})
]
})
Now I want to somehow loop through the projecten variables, loop through its layers one by one, get the extent of each feature layer, and stop when the last layer has been reached. Then I want to zoom to this combined extent.
This is my basic setup (I'm not good with javascript and loops):
projecten.getLayers()
for (var i = 0, ii = layers.length; i < ii; ++i) {
layer = layers[i];
ol.extent.boundingExtend(extent, layer.getBounds());
}
map.getView().fitExtent(extent,map.getSize());
Any ideas on how I can get this to work?