从Openlayers 3视口获取所有功能

Use*_*836 5 javascript openlayers-3

我试图找出Openlayers 3中图层上可见的所有功能(视口).

如果我向地图添加点击事件,我可以找到一个功能,如下所示.但我无法找到视口中可见的所有功能.任何人都可以帮忙吗?

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

Hic*_*rhi 8

我建议首先得到视图的范围:

var extent = yourMap.getView().calculateExtent(yourMmap.getSize());
Run Code Online (Sandbox Code Playgroud)

然后获得此范围内的所有功能:

yourVectorSource.forEachFeatureInExtent(extent, function(feature){
    // do something 
}); 
Run Code Online (Sandbox Code Playgroud)