Get all features from the Openlayers 3 viewport

不问归期 提交于 2019-12-23 10:06:50

问题


I am trying to find out all the features which are visible (viewport) on a layer in Openlayers 3.

I am able to find out a single feature if I add a click event to the map which is as follows. But I am not able to find all the features which are visible in the viewport. Could anyone help with this?

map.on('click', function(evt) {
        var feature = map.forEachFeatureAtPixel(evt.pixel,
            function(feature, layer) {
                return feature;
            });
});

回答1:


I propose that first you get the extent of the view :

var extent = yourMap.getView().calculateExtent(yourMmap.getSize());

then get all features within this extent :

yourVectorSource.forEachFeatureInExtent(extent, function(feature){
    // do something 
}); 


来源:https://stackoverflow.com/questions/38785940/get-all-features-from-the-openlayers-3-viewport

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!