Keep GraphicsLayer as topmost layer?

10-16-2014 06:09 PM
New Contributor


I've searched all API docs and can't find a method to keep my GraphicsLayer as my topmost layer:

If I add the layers in the following order, everything is ok, because graphicsLayer was added at last, it is the topmost layer...:

1) Add basemap

2) Add gdb (geodatabase) (green polygons)

3) Add graphicsLayer


But If I add them in the following order:

1) Add basemap

2) Add graphicsLayer

3) Add gdb (geodatabase) (green polygons)

My graphicsLayer sits behind the featureLayers in the geodatabase, how do I move my graphicsLayer on top of all layers again?


Please advice

Thank you in advance

0 Kudos
3 Replies
New Contributor II

Hi Peter,

One simple way (recently introduced in 10.2.4) is to make use of MapView.GraphicOverlay instead of GraphicLayers.
According to the documentation, GraphicOverlay will always appear above your MapView.Map.Layers.

In terms of API, GraphicOverlay is almost exactly the same as GraphicLayer

Another way is to make use of the Move/MoveItem/Insert methods to reorder your layers, or insert new layers at a specified index

LayerCollection Class

Occasional Contributor II

What I've done for cases that I needed to add graphics layers, or any layer for that matter, on the fly based on user input AND make sure that I keep a default set of layers in order at the top is to:

1) create a list of the known default layers and their order (ie. the layers you want on top and in what order you want them)

2) tie into the event for when a layer is added, removed, or reordered in the map

3) that event is handled by then moving (you may have to remove the layer from the map and then insert it into the new desired index position) all of the layers in the default order list back into their default position (ex. you could have three graphics layers that you want to always be on top to handle point, line, or polygon data)

I don't have any code samples right now to help you out, but if you need it let me know and I'll get back to you. Hopefully the general idea helps you out.

0 Kudos
Esri Notable Contributor

Cedric's suggestion is spot on. This is exactly one of the main use-cases of GraphicsOverlay. We really want to drive people toward using the overlays for this temporary data, and leave the Map a non-changing entity. Ie you have your map, and then you have stuff you put on top of your map during your session. The new API structure makes this easy.

If you do want to keep things in a map for now, perhaps looking at GroupLayers is easier. Ie always create 3 group layers up front: Basemap, GdbData, Graphics, and just add your data to each group later.