Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set marker Z-index on MapBox Android?

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?

like image 444
Neon Warge Avatar asked Feb 17 '17 01:02

Neon Warge


3 Answers

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).

like image 56
Jedi-Philosopher Avatar answered Oct 12 '22 12:10

Jedi-Philosopher


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.

like image 20
alijandro Avatar answered Oct 12 '22 12:10

alijandro


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);

like image 1
Ivan Yulin Avatar answered Oct 12 '22 12:10

Ivan Yulin