This repository was archived by the owner on Jun 21, 2023. It is now read-only.
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Cannot integrate GeoJSON source as layer #679
Open
Description
I took this example: https://docs.mapbox.com/android/maps/examples/marker-symbol-layer/
It worked.
I then unsuccessfully tried to replace the points by a source geojson as explained here: https://docs.mapbox.com/android/maps/guides/data-driven-styling/#geojson
I did not change anything beside the section where I add new stuff to the map. This section looks now like this:
@Override
public void onMapReady(@NonNull final MapboxMap mapboxMap) {
try {
mapboxMap.setStyle(new Style.Builder().fromUri("mapbox://styles/mapbox/cjf4m44iw0uza2spb3q0a7s41")
// Add the SymbolLayer icon image to the map style
.withImage(ICON_ID, BitmapFactory.decodeResource(
MainActivity.this.getResources(), R.drawable.mapbox_marker_icon_default))
// Adding a GeoJson source for the SymbolLayer icons.
.withSource(new GeoJsonSource("ports",
new URI("https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_ports.geojson")))
// Adding the actual SymbolLayer to the map style. An offset is added that the bottom of the red
// marker icon gets fixed to the coordinate, rather than the middle of the icon being fixed to
// the coordinate point. This is offset is not always needed and is dependent on the image
// that you use for the SymbolLayer icon.
.withLayer(new SymbolLayer(LAYER_ID, SOURCE_ID)
.withProperties(
iconImage(ICON_ID),
iconAllowOverlap(true),
iconIgnorePlacement(true)
)
), new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
// Map is set up and the style has loaded. Now you can add additional data or make other map adjustments.
}
});
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
Somehow, the points are not being displayed..