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.
You can upload GeoJSON files to Mapbox as tilesets using Mapbox Tiling Service or as datasets or tilesets using the Mapbox Uploads API. You can also upload GeoJSON files to Mapbox Studio, which uses the Uploads API, as either datasets or tilesets.
Map to initialize a Mapbox map inside an HTML element on a webpage. You can use the map parameters style , center , and zoom to define the initial appearance of the map. The string value for accessToken should be a valid access token from a Mapbox user account.
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With