Search code examples
androidkotlinmapboxmapbox-androidmapbox-marker

Mapbox SymbolLayer hides markers


I use symbol layer to draw bunch of points on the map :

var imgId = R.drawable.ic_route_stop

        var featureCollection = FeatureCollection.fromFeatures(mSelectedBusStops!!.map { stop ->
            Feature.fromGeometry(com.mapbox.geojson.Point.fromLngLat(
                    stop.Lon.toDouble(),
                    stop.Lat.toDouble()))
        });
        map?.addSource(
                GeoJsonSource(mMarkerSourceIdentifier,
                        featureCollection,
                        GeoJsonOptions()
                ))

        val image = BitmapFactory.decodeResource(activity?.resources, imgId)
        map?.addImage(mMarkerImgIdentifier, image)

        var layer = SymbolLayer(mMarkerStyleLayerIdentifier, mMarkerSourceIdentifier)
        layer.setProperties(PropertyFactory.iconImage(mMarkerImgIdentifier),
                PropertyFactory.iconAllowOverlap(true))
        map?.addLayer(layer)

after this I add several markers in the map (this markers need to be animated periodically)

mSelectedBusCurrentStops?.forEach { stop ->
                (map ?: return).addMarker(MarkerOptions()
                        .icon(icon)
                        .position(LatLng(stop.lat, stop.lon)))
            }

the important part here is a markers , what I added later, those markers should be visible always. But my symbol layer hides marker icons, I need to bring markers to front. Is there any way to fix it?

this is how it looks

enter image description here


Solution

  • You need to position your SymbolLayer to be below the markers layer in the layer stack. You can achieve that with map?.addLayerBelow(layer, "com.mapbox.annotations.points").