最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get all features from the Openlayers 3 viewport - Stack Overflow

programmeradmin4浏览0评论

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

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;
            });
});
Share Improve this question edited Jan 12, 2017 at 16:06 ahocevar 5,64719 silver badges32 bronze badges asked Aug 5, 2016 at 9:31 User1836User1836 1833 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 16

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 
}); 
发布评论

评论列表(0)

  1. 暂无评论