Sto usando gli openlayer 3 per creare una mappa con caratteristiche vettoriali in alto. Fin qui tutto bene.openlayers 3 zoom in estensione combinata
Ho diversi livelli vettoriali, raggruppati in una variabile denominata 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')];
}
})
]
})
Ora voglio in qualche modo un ciclo tra le variabili projecten, ciclo attraverso i suoi strati uno per uno, ottenere l'estensione di ogni strato funzione, e fermarsi quando è stato raggiunto l'ultimo strato. Quindi voglio zoomare su questa estensione combinata.
Questa è la mia impostazione di base (io non sono bravo con javascript e loop):
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());
Tutte le idee su come posso ottenere questo lavoro?
Non conosco le estensioni abbastanza bene da creare una risposta, ma penso che nel tuo ciclo puoi utilizzare ol.extent.getBottomLeft e ol.extent.getTopRight per l'estensione del livello. Memorizza i valori minimi dei valori in basso a sinistra e massimo in alto a destra e usa quelli per creare la tua nuova estensione. –
Come? Puoi fare un tentativo? – user1697335