从 Openlayers 3 视口获取所有功能

问题描述 投票:0回答:1

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

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

map.on('click', function(evt) {
        var feature = map.forEachFeatureAtPixel(evt.pixel,
            function(feature, layer) {
                return feature;
            });
});
javascript openlayers-3
1个回答
16
投票

我建议你首先了解视图的范围:

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

然后获取这个范围内的所有特征:

yourVectorSource.forEachFeatureInExtent(extent, function(feature){
    // do something 
}); 
© www.soinside.com 2019 - 2024. All rights reserved.