还有另一种方法可以使用在Android上稳定的mapbox sdk 9.0向地图添加geoJSON多边形吗?
我有以下内容,但不确定是否正确:
GeoJsonSource source = new GeoJsonSource("geojson", geoJsonString);
mapboxMap.addSource(source);
mapboxMap.addLayer(new LineLayer("geojson", "geojson"));
This example,显示了如何使用Android版Mapbox Maps SDK将GeoJSON多边形添加到地图中。相关代码在onMapReady
回调中,提取如下(我省略了与添加点击侦听器有关的代码,因为这与您的问题无关);
@Override
public void onStyleLoaded(@NonNull Style style) {
// Add the GeoJSON as a source to the map.
addGeoJsonSourceToMap(style);
// Create FillLayer with GeoJSON source and add the FillLayer to the map.
if (style != null) {
style.addLayer(new FillLayer(geoJsonLayerId, geoJsonSourceId)
.withProperties(fillOpacity(0.5f)));
}
}
此示例中的addGeoJsonSourceToMap
帮助程序方法从外部URI加载GeoJSON,但在您的情况下,您提供的代码段的前两行将替换addGeoJsonSourceToMap(style);
调用。
因为使用FillLayer
,所以使用了[A LineLayer
而不是linked API reference documentation:
FillLayer
:
具有可选描边边框的填充多边形。
LineLayer
:
描边线。