Select to view content in your preferred language

Change GraphicsLayer Z Index

8768
4
03-18-2011 01:05 PM
FrancoisChartrand
Emerging Contributor
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
Emerging Contributor
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
Emerging Contributor
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
Deactivated User

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.