使用querySourceFeature获取图层功能 [英] Getting layer features with querySourceFeature
问题描述
我正在尝试从Mapbox样式层获取所有功能.我找到了querySourceFeature()方法.但是,我无法获得确切的消息来源.这里是Mapbox文档中的简单代码块.
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.
我不使用GeoJsonSource进行样式设置,我的意思是我不添加任何GeoJsonSouce.因此,"source"变量返回"null",我不知道应该用什么代替GeoJsonSource和"population-source".
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"));
总而言之,我想从Mapbox样式中获取所有功能.
To sum up, I want to get all features in one layer from Mapbox style.
推荐答案
为了获取样式层作为源,我们应该使用VectorSource()
.
In order to get style layer as source, we should use VectorSource()
.
VectorSource source = style.getSourceAs("composite");
"composite"是"style.json"中图层的源变量.
"composite" is layer' source variable in "style.json".
对于querySourceFeatures()
,我们应该给出layerSource(String[])
和Expression
.
For querySourceFeatures()
, we should give layerSource(String[])
and Expression
.
List<Feature> all_features = source.querySourceFeatures(source_layers,Expression);
"source_layers"是"style.json"中图层的源层变量.
"source_layers" is layer' source-layer variable in "style.json".
这篇关于使用querySourceFeature获取图层功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!