Bring markers above polyline with deprecated markers
Hi How to bring all the markers above polyline. I'm using deprecated 'Marker' and 'LineManager' to draw marker and polyline. I think with Layers its possible, but its hard for me to switch now, is there any with 'Marker'?
This is how i add marker and polyline
LatLng latLng = new LatLng(mLatLngList.get(i).getLatituede(), mLatLngList.get(i).getLongitude());
MarkerOptions markerOptions = new MarkerOptions().position(latLng).icon(icon).setTitle(cabList.get(i).getCabId());
Marker marker = mMapboxMap.addMarker(markerOptions);
mMapboxMap.setStyle(new Style.Builder().fromUrl(getString(R.string.mapbox_style_url_light)), style -> {
mLineManager = new LineManager(mMapView, mapboxMap, style);
LineOptions lineOptions = new LineOptions()
.withLatLngs(points)
.withLineJoin(Property.LINE_JOIN_ROUND)
.withLineColor(ColorUtils.colorToRgbaString(getResources().getColor(R.color.colorPrimary)))
.withLineWidth(4.0f);
mMapBoxLines = mLineManager.create(lineOptions);
});
I even tried manually removing line layer and adding below symbol layer, but it didn't work.
SymbolLayer symbolLayer = (SymbolLayer) mMapboxMap.getStyle().getLayer("mapbox-android-symbol-layer");
LineLayer lineLayer = (LineLayer) mMapboxMap.getStyle().getLayer("mapbox-android-line-layer");
mMapboxMap.getStyle().removeLayer(lineLayer);
mMapboxMap.getStyle().addLayerBelow(lineLayer, symbolLayer.getSourceId());
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.0.0'
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:4.3.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:0.4.0'
With components from package com.mapbox.mapboxsdk.annotations this isn't possible, the layers are hardcoded and always placed on top of the loaded style in specific order. With AnnotationPlugin (high level wrapper around Layers) and with Layers this is possible.
I'm using deprecated 'Marker' and 'LineManager' to draw marker and polyline.
To clarify, you can use SymbolManager to replace your Markers and you can place these layers where you want in your style order.
Ok. Thanks. So if I use SymbolManager then how can I change the z order of each layer?
All the different manager constructors expose a belowLayer param:
/**
* Create a symbol manager, used to manage symbols.
*
* @param mapboxMap the map object to add symbols to
* @param style a valid a fully loaded style object
* @param belowLayerId the id of the layer above the circle layer
*/
@UiThread
public SymbolManager(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap, @NonNull Style style, @Nullable String belowLayerId) {
this(mapView, mapboxMap, style, belowLayerId, null);
}
The id's for layers are generated from the template:
mapbox-android-<annotation-type>-layer-%s
Where %s = a integer number starting at 0.
so the first symbol layer id would be:
mapbox-android-symbol-layer-0