Change GraphicsLayer Z Index

7002
4
03-18-2011 01:05 PM
FrancoisChartrand
New Contributor III
Hi,

I know about Graphic.SetZIndex and Graphic.GetZIndex. These methods allow to change the Z index of Graphics in a layer. However, these methods don't exist for the Layer itself.

How should I control the Z index for all my different GraphicsLayers? It seems to be related to the order in which my layers are added to the map.

Thank you
4 Replies
FrancoisChartrand
New Contributor III
Any idea anybody?

This is really annoying. I have two GraphicLayers: GL1 and GL2. The graphics from GL1 are drawn over graphics from GL2 because GL1 is added first to Map Control.

How can I control that?
FrancoisChartrand
New Contributor III
I found a way to do it. It is not really clean, but at least it works...

public void MoveUpLayer(Layer layer)
{
    int index = Map.Layers.IndexOf(layer);
    if (index < 0)
        return;

    Map.Layers.RemoveAt(index);
    Map.Layers.Insert(index - 1, layer);
}

public void MoveDownLayer(Layer layer)
{
    int index = Map.Layers.IndexOf(layer);
    if (index < 0)
        return;

    Map.Layers.RemoveAt(index);
    Map.Layers.Insert(index + 1, layer);
}


I don't know if ArcGIS developers are reading these posts, but they should consider adding SetZIndex and GetZIndex to the Layer class. It would be a lot cleaner...
SurajPatil
New Contributor

Yeah..indeed its a real pain of not having those SetZIndex and GetZIndex methods for the Graphics Layer.

JenniferNery
Esri Regular Contributor
This is correct. The only way you can change the order of your layers is to add/remove them from your Map.Layers.

Graphic.SetZIndex() only applies to features belonging to the same layer.