Get and Set AcMapLayer order using Map 3D Platform API

By Partha Sarkar

I am modifying this post with updated details on how to set a FDO Layer Order in Display Manager. Thanks to one of our ADN Partners who pointed out that when we use SetOrder(int value) it is setting the Layer Order as seen under “Groups” but if we active the “Draw Order”, you will find the layer order is unchanged. Let me explain it with some screenshots and how we can actually set the Layer Order which will change the visual display order.

public virtual int GetOrder() ->    Member of Autodesk.Gis.Map.Platform.AcMapLayer

public virtual void SetOrder(int value) ->     Member of Autodesk.Gis.Map.Platform.AcMapLayer


Let's assume we have three FDO layers as seen in the following screenshot:

 

Layer_Order_1

If you build your application using the following C# code snippet, and run your custom command, you will see the Layer Order is changed under "Groups" –

if (layer.Name == "City_Boundary")
{
  // Set Layer Order
  layer.SetOrder(4);
}
msg += "Layer Name : " + layer.Name + "     " + "Layer Order: " + layer.GetOrder().ToString() + "n";
but it's unchanged when you move to "Draw Order" tab:

 
Now the question is, how do I change the Draw Order to see the "City_Boundary" goes below and "Roads" come up ? To modify the draw order of a layer, we have to remove it from the layer collection and insert it at the desired index. Here is a relevant code snippet :
 

// Get the Map Object
AcMapMap currentMap = AcMapMap.GetCurrentMap();         
 
//Get layer to Change the Order
 
var layers = currentMap.GetLayers();
var myLayer = layers.GetItem("City_Boundary");
if (layers.Remove(myLayer))
{
  // Int index value should be correct w.r.t number of Layers in Display Manager
  // Otherwise you would see an message " Index is out of range."
  // And the Layer won't be inserted
  layers.Insert(2, myLayer);
}
}

 

And expected result :


Layer_Order_4

 

Hope this is useful to you!

 

 


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading