问题
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