简体   繁体   English

获取map中某一层所有特征的数据

[英]Getting the data of all the features on a layer in a map

So I'm building a project where I'm displaying a map with different layers on top of it.所以我正在构建一个项目,我在其中显示一个 map,上面有不同的层。 When I click on a specific polygon on a layer, I get the data of that polygon (basically the attributes table) using the getFeatureInfoUrl() method and I display it by simply running a for loop.当我单击图层上的特定多边形时,我使用getFeatureInfoUrl()方法获取该多边形的数据(基本上是属性表),并通过简单地运行 for 循环来显示它。 Now I want to get the data of all the polygons on that layer.现在我想获取该层上所有多边形的数据。 Is there a method to do that or am I just supposed to use the getFeatureInfoUrl() method?有没有一种方法可以做到这一点,或者我只是应该使用getFeatureInfoUrl()方法? I'm getting the data from a GeoServer and using the OpenLayers library.我正在从 GeoServer 获取数据并使用 OpenLayers 库。

var url = this.wmsSource.getFeatureInfoUrl(
        evt.coordinate,
        viewResolution,
        'EPSG:3857',
        {'INFO_FORMAT': 'text/html'}
      );

This is the code for a specific polygon, and it just returns one feature.这是特定多边形的代码,它只返回一个要素。 But this works for one specific coordinate only so I'm not sure how to move forward with this.但这仅适用于一个特定的坐标,所以我不确定如何推进这一点。 I could try the FEATURE_COUNT: 1, option but then I would have to specify manually how many features are there and it would still require me to click on the map. Want to get the data without clicking on the map.我可以尝试FEATURE_COUNT: 1,选项,但我必须手动指定有多少功能,它仍然需要我点击 map。想要获取数据而不点击 map。

 vectorLayer.getSource()?.on('addfeature', function(evt:any){ debugger var feature=evt.feature; })

you can get all feature from this code.您可以从此代码中获得所有功能。 I hope this is helpful for you.我希望这对你有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM