从Openlayers 3视口中获取所有功能 [英] Get all features from the Openlayers 3 viewport
本文介绍了从Openlayers 3视口中获取所有功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试找出Openlayers 3的图层上所有可见(视口)的功能.
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 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
});
这篇关于从Openlayers 3视口中获取所有功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文