I use openlayers 3 to create a map with vector features on top. So far, so good.
I have several vector layers grouped into 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( ({ 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( ({ 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( ({ 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( ({ 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( ({ object: Zionsburg, projection: 'EPSG:3857' })), style: function(feature, resolution) { return lookup[feature.get('landschapselement')]; } }) ] })
Now I want to somehow scroll through the projection variables, scroll through their layers one by one, get the size of each function layer and stop when the last level is reached. Then I want to zoom in to this extent.
This is my main setup (I am not good at 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 make this work?