简体   繁体   English

如何绘制GeoJSON的一部分?

[英]How to draw part of GeoJSON?

I load all geojson (countries) in VectorSource by url. It is displayed instantly on the map.我通过 url 在VectorSource中加载所有 geojson(国家/地区)。它立即显示在 map 上。

But I need to display specific part of geojson.但我需要显示 geojson 的特定部分。 For example user selects USA country and the map have to draw only USA borderies.例如,用户选择美国国家,map 必须只绘制美国边界。

How to do that in OpenLayers?如何在 OpenLayers 中做到这一点?

You should create new vector layer, and on select event add selected features from geojson file into new layer:您应该创建新的矢量图层,并在 select 事件上将 geojson 文件中的选定功能添加到新层中:

vectorCountires.getSource().clear(); vectorCountires.getSource().clear(); vectorCountires.getSource().addFeatures(arrayOfFeatures); vectorCountires.getSource().addFeatures(arrayOfFeatures);

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

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