How to set marker Z-index on MapBox Android?
Asked Answered
O

3

7

My app shows a user marker. Basically, the user marker shows where the current user is on the map but I also have other markers placed on the map. In the end, it covers up my user marker. I want my User Marker to be on the top of the map. I want it to be rendered last so it shows on the very top.

Any idea?

Oxyhydrogen answered 17/2, 2017 at 1:7 Comment(2)
do you find the solution for your problem?Fin
@PhanVanLinh, unfortunately no. There is no way to control this unless otherwise you implement your own Marker which is possible via ViewMarkerOptions which implements a view I think, there are other cool options there like anchor, offset, etc. Can't remember if it has z-ordering. Can't believe this basic stuff in 2D rendering was left out which is a shame really. I can't go down ViewMarkerOptions though, the map becomes so slow if you have hundreds of them. I think the best option would be the Mapbox Studio, I haven't tried it though.Oxyhydrogen
N
7

In case anyone is looking for a newer answer for latest SDKs.

Mapbox Marker class is now deprecated in newer versions of Mapbox Android SDK. Annotations plugin is suggested instead, which has a Symbol class for markers.

In mapbox-android-plugin-annotation-v7 library Symbol class had a withZIndex() method which allowed to manipulate Z-ordering of map objects.

In mapbox-android-plugin-annotation-v8 this method was renamed to withSymbolSortKey() (which was a bit tricky to find and discover).

Nihon answered 17/9, 2020 at 12:32 Comment(0)
I
1

There is a solution from here https://github.com/mapbox/mapbox-gl-native/pull/5294

If you use MarkerView, you can bring your marker to the very top with MarkerViewManager#select call.

mapboxMap.getMarkerViewManager().select(marker);

It will end by calling View#bringToFront from Android View API, the selected marker view will show on top of all other marker views.

Ice answered 28/11, 2017 at 11:19 Comment(0)
S
1

I think this may help:

Mapbox Android SDK: Bring marker to front

Yes. Starting with Mapbox Android SDK v4.1, the selected marker will come to front.

You can select a marker with mapboxMap.selectMarker(marker);

Symer answered 1/4, 2019 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.