从 Openlayers 3 视口获取所有功能
Get all features from the Openlayers 3 viewport
我试图找出在 Openlayers 3 中的图层上可见的所有功能(视口)。
如果我在地图上添加一个点击事件,我可以找到一个单一的地图项,如下所示。但是我无法找到视口中可见的所有功能。有人可以帮忙吗?
map.on('click', function(evt) {
var feature = map.forEachFeatureAtPixel(evt.pixel,
function(feature, layer) {
return feature;
});
});
我建议您首先了解视图的范围:
var extent = yourMap.getView().calculateExtent(yourMmap.getSize());
然后得到这个范围内的所有特征:
yourVectorSource.forEachFeatureInExtent(extent, function(feature){
// do something
});
我试图找出在 Openlayers 3 中的图层上可见的所有功能(视口)。
如果我在地图上添加一个点击事件,我可以找到一个单一的地图项,如下所示。但是我无法找到视口中可见的所有功能。有人可以帮忙吗?
map.on('click', function(evt) {
var feature = map.forEachFeatureAtPixel(evt.pixel,
function(feature, layer) {
return feature;
});
});
我建议您首先了解视图的范围:
var extent = yourMap.getView().calculateExtent(yourMmap.getSize());
然后得到这个范围内的所有特征:
yourVectorSource.forEachFeatureInExtent(extent, function(feature){
// do something
});