Getting layer features with querySourceFeature

六月ゝ 毕业季﹏ 提交于 2019-12-13 04:25:19

问题


I'm trying to get all features from Mapbox style layer. I found querySourceFeature() method. However, I cannot get exact source. Here simple code block from Mapbox documentation.

I don't use GeoJsonSource for styling, I mean I dont add any GeoJsonSouce. So, "source" variable returns "null" and I did not understand what should come instead of GeoJsonSource and "population-source".

GeoJsonSource source = style.getSourceAs("population-source");
List<Feature> features = source.querySourceFeatures(Expression.get("population"));

To sum up, I want to get all features in one layer from Mapbox style.


回答1:


In order to get style layer as source, we should use VectorSource().

VectorSource source = style.getSourceAs("composite");

"composite" is layer' source variable in "style.json".

For querySourceFeatures(), we should give layerSource(String[]) and Expression.

List<Feature> all_features = source.querySourceFeatures(source_layers,Expression);

"source_layers" is layer' source-layer variable in "style.json".



来源:https://stackoverflow.com/questions/58267691/getting-layer-features-with-querysourcefeature

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!