OpenLayers 3 gets all of the content in the list

I want to zoom in on all the features in the list.

First, I put my function in a list:

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

      

Second, here's my problem ... I want to zoom in on the entire feature in my "selectedFeatures" list

I try this but always give me infinite length back:

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);

      

Anyone have a solution to get the scope of the features listed?

+3


source to share


1 answer


Should this do the trick?



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

      

+2


source







All Articles