使用 querySourceFeatures 获取图层特征

Getting layer features with querySourceFeature

我正在尝试从 Mapbox 样式图层中获取所有功能。我找到了 querySourceFeature() 方法。但是,我无法获得确切的来源。这里是 Mapbox 文档中的简单代码块。

我不使用 GeoJsonSource 进行样式设置,我的意思是我不添加任何 GeoJsonSouce。所以,"source" 变量 returns "null" 我不明白应该用什么来代替 GeoJsonSource 和 "population-source"。

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

综上所述,我想从 Mapbox 样式中获取一层中的所有功能。

为了获取样式层作为源,我们应该使用VectorSource()

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

"composite" 是 "style.json" 中层的源变量。

对于querySourceFeatures(),我们应该给出layerSource(String[])Expression

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

"source_layers" 是 "style.json".

层的源层变量