I'm attempting to add markers to a map from a GeoJSON File that has been added to the "asset" folder.
I've attempted to follow the documentation however have been unable to get the expected result since the markers are no where to be found when running the app.
My Attempt:
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
mapboxMap.setStyle(Style.MAPBOX_STREETS,
new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
enableLocationComponent(style);
GeoJsonSource source = null;
try {
source = new GeoJsonSource("geojson-source", new URI("asset://markerdata.geojson"));
} catch (URISyntaxException e) {
e.printStackTrace();
}
style.addSource(source);
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.marker);
style.addImage("marker", icon);
SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id"); // ?
symbolLayer.setProperties(PropertyFactory.iconImage("marker"));
style.addLayer(symbolLayer);
}
});
}
I have noticed that SymbolLayer
expects a layer-id
and source-id
however fail to understand what these are.
The markers should appear if you put the GeoJsonSource
id as the SymbolLayer
source id:
SymbolLayer symbolLayer = new SymbolLayer("layer-id", "geojson-source");
The layer id is an identifier for the layer, the source id is the id of the data source to display, in your case it's "geojson-source".