【发布时间】:2015-07-19 04:53:50
【问题描述】:
我正在使用 openlayers 3 创建顶部带有矢量特征的地图。到目前为止,一切都很好。
我有几个矢量图层,分组在一个名为 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')];
}
})
]
})
现在我想以某种方式遍历投影变量,一层一层地循环,获取每个要素层的范围,并在到达最后一层时停止。然后我想放大到这个组合范围。
这是我的基本设置(我不擅长 javascript 和循环):
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());
关于如何让它发挥作用的任何想法?
【问题讨论】:
-
我不太了解范围以创建答案,但我认为在您的循环中您可以使用 ol.extent.getBottomLeft 和 ol.extent.getTopRight 作为图层范围。存储左下角的最小值和右上角的最大值,并使用它们来创建新范围。
-
怎么样?可以试试吗?
标签: layer openlayers-3