OpenLayers 3获取列表中所有功能内容的范围

Fat*_*tAl 7 javascript openlayers-3

我想放大列表中包含的所有功能的范围。

首先,我将功能列表中:

selectedFeatures = [];    
vector2.getSource().forEachFeature(function(feature) {
                var att = feature.get("NOM");
                if (att == strUser) {
                    selectedFeatures.push(feature);
                    }
                });
Run Code Online (Sandbox Code Playgroud)

其次,这是我的问题...我想放大列表“ selectedFeatures”上所有功能的范围

我尝试这样做,但总是无限返回我:

var vectorSource = new ol.source.Vector({
        projection: 'EPSG:3857',
        features: selectedFeatures //add an array of features
        });

var dataExtent = vectorSource.getExtent();
map.getView().fitExtent(dataExtent, map.getSize())
console.log("Extents : " + dataExtent);
Run Code Online (Sandbox Code Playgroud)

有人有解决方案来获取列表中包含的功能的范围吗?

Pou*_*sen 5

这应该做的把戏吗?

var extent = features[0].getGeometry().getExtent().slice(0);
features.forEach(function(feature){ ol.extent.extend(extent,feature.getGeometry().getExtent())});
Run Code Online (Sandbox Code Playgroud)