This document is archived and information here might be outdated.  Recommended version.


How to get and set the drawing order of layers in globe (ArcObjects .NET 10.4 SDK)

How to get and set the drawing order of layers in globe


Summary
Globe can have draped, floating, and elevation layers. Floating layers define their own place in 3D space by containing z-values in feature geometry, feature attributes, or layer level settings. Draped layers are placed on top of a known surface layer, obtaining their z-values from it. Elevation layers provide a 3D surface for other layers to be placed upon.
This topic shows how to get and set (change) the drawing order of globe layers within their respective categories.

Getting and setting the drawing order of layers in globe

  1. Properly initialize the following variable: ESRI.ArcGIS.GlobeCore.IGlobe globe.
  2. Get IGlobeDisplay and IGlobeDrawingOrder from globe. See the following code:
[C#]
IGlobeDisplay globeDisplay=globe.GlobeDisplay;
IGlobeDrawingOrder globeDrawingOrder=(IGlobeDrawingOrder)globe; // Explicit cast.
[VB.NET]
Dim globeDisplay As IGlobeDisplay=globe.GlobeDisplay
Dim globeDrawingOrder As IGlobeDrawingOrder=CType(globe, IGlobeDrawingOrder) ' Explicit cast.
  1. Get the current drawing order of the layers in globe. This includes draped, floating, and elevation layers. See the following code:
[C#]
IEnumLayer enumLayer=globeDrawingOrder.OrderedLayers;
[VB.NET]
Dim enumLayer As IEnumLayer=globeDrawingOrder.OrderedLayers
  1. Since enumLayer contains draped, floating, and elevation layers, you have to separate them. The syntax is as follows:

    IEnumLayer variable=IGlobe.get_GlobeLayers(pUID, bRecursive, bInBaseGlobe, bSortedByDrawingPriority)
    • The Boolean variable bInBaseGlobe=true means that you want the draped and elevation layers to be returned by the method IGlobe.get_GlobeLayers.
    • The Boolean variable bInBaseGlobe=false means that you want the floating layers to be returned by the method IGlobe.get_GlobeLayers.
    • Set the Boolean variable bSortedByDrawingPriority=true if you want the result returned by IGlobe.get_GlobeLayers to return layers sorted by their drawing priority.
See the following code:
[C#]
IEnumLayer baseLayers=globe.get_GlobeLayers(null, true, true, true);
IEnumLayer floatingLayers=globe.get_GlobeLayers(null, false, false, true);
[VB.NET]
Dim baseLayers As IEnumLayer=globe.GlobeLayers(Nothing, True, True, True)
Dim floatingLayers As IEnumLayer=globe.GlobeLayers(Nothing, False, False, True)
  1. Since baseLayers contain both draped and elevation layers, you need to separate them. The ordered list for baseLayers is elevation layers followed by draped layers, which is shown as follows:
    (Top down)
    Elevation0
    Elevation1
    Draped0
    Draped1
  2. Create separate ArrayLists for draped and elevation layers. See the following code:
[C#]
ArrayList DrapedLayers=new ArrayList();
ArrayList ElevationLayers=new ArrayList();
[VB.NET]
Dim DrapedLayers As ArrayList=New ArrayList()
Dim ElevationLayers As ArrayList=New ArrayList()
  1. Loop through the IEnumLayer baseLayers to separate draped and elevation layers and store them in DrapedLayers and ElevationLayers, respectively. See the following code:
[C#]
IGlobeLayerProperties globeLayerProperties;
// It is not set to anything here but is used later in the loop.
IGlobeDisplayLayers globeDisplayLayers=(IGlobeDisplayLayers)globeDisplay; 
    // Explicit cast.
// Store the separate draw order (elevation and draped) into ArrayLists.
ILayer layer=baseLayers.Next();
while (layer != null)
{
    globeLayerProperties=globeDisplayLayers.FindGlobeProperties(layer);
    // globeLayerProperties is finally set to something.
    if (globeLayerProperties.Type != esriGlobeDataType.esriGlobeDataElevation)
    {
        DrapedLayers.Add(layer);
    }
    else if (globeLayerProperties.Type == esriGlobeDataType.esriGlobeDataElevation)
    {
        ElevationLayers.Add(layer);
    }
    //Get the next layer.
    layer=baseLayers.Next();
}
[VB.NET]
Dim globeLayerProperties As IGlobeLayerProperties
' It is not set to anything here but is used later in the loop.
Dim globeDisplayLayers As IGlobeDisplayLayers=CType(globeDisplay, IGlobeDisplayLayers) ' Explicit cast.

' Store the separate draw order (elevation and draped) into ArrayLists.
Dim layer As ILayer=baseLayers.Next()
Do While Not layer Is Nothing
    globeLayerProperties=globeDisplayLayers.FindGlobeProperties(layer)
    ' globeLayerProperties is finally set to something.
    If globeLayerProperties.Type <> esriGlobeDataType.esriGlobeDataElevation Then
        DrapedLayers.Add(layer)
    ElseIf globeLayerProperties.Type=esriGlobeDataType.esriGlobeDataElevation Then
        ElevationLayers.Add(layer)
    End If
    
    'Get the next layer.
    layer=baseLayers.Next()
Loop
  1. Once the draped and elevation layers have been separated, layers can be obtained by individually casting the elements of the ArrayLists to ILayer. For example, see the following code for getting the first layer from the DrapedLayers ArrayList:
[C#]
// To get the layers from the ArrayLists, cast individual elements to ILayer.
// For example, getting the first layer in the DrapedLayers list:
ILayer theDrapedLayer=(ILayer)DrapedLayers[0]; // Explicit cast.
[VB.NET]
' To get the layers from the ArrayLists, cast individual elements to ILayer.
' For example, getting the first layer in the DrapedLayers list:
Dim theDrapedLayer As ILayer=CType(DrapedLayers(0), ILayer) ' Explicit cast.
  1. The methods on ESRI.ArcGIS.GlobeCore.IGlobeDrawingOrder can be used for changing the drawing order of the layers. For example, to move a layer backward, see the following code:
[C#]
// For example, to move a layer backward:
globeDrawingOrder.MoveBackward(theDrapedLayer);
globeDisplay.RefreshViewers();
[VB.NET]
' For example, to move a layer backward:
globeDrawingOrder.MoveBackward(theDrapedLayer)
globeDisplay.RefreshViewers()
  1. The floating layers are stored in the IEnumLayer variable floatingLayers. The individual floating layers can be obtained as shown in the following code:
[C#]
// Get the floating layers.
ILayer theFloatingLayer=floatingLayers.Next();
while (theFloatingLayer != null)
{
    // Code to work with theFloatingLayer.
    theFloatingLayer=floatingLayers.Next();
}
[VB.NET]
' Get the floating layers.
Dim theFloatingLayer As ILayer=floatingLayers.Next()
Do While Not theFloatingLayer Is Nothing
    ' Code to work with theFloatingLayer.
    theFloatingLayer=floatingLayers.Next()
Loop






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS for Desktop Basic: 3D Analyst ArcGIS for Desktop Basic: 3D Analyst
ArcGIS for Desktop Standard: 3D Analyst ArcGIS for Desktop Standard: 3D Analyst
ArcGIS for Desktop Advanced: 3D Analyst ArcGIS for Desktop Advanced: 3D Analyst
Engine Developer Kit Engine: 3D Analyst