【问题标题】:Get all features from the Openlayers 3 viewport从 Openlayers 3 视口获取所有功能
【发布时间】:2016-08-05 09:31:48
【问题描述】:

我正在尝试找出 Openlayers 3 中图层上所有可见的特征(视口)。

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

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

【问题讨论】:

    标签: javascript openlayers-3


    【解决方案1】:

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

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

    然后得到这个范围内的所有特征:

    yourVectorSource.forEachFeatureInExtent(extent, function(feature){
        // do something 
    }); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多