Getting and setting the drawing order of layers in globe
- Properly initialize the following variable: ESRI.ArcGIS.GlobeCore.IGlobe globe.
- Get IGlobeDisplay and IGlobeDrawingOrder from globe. See the following code:
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.
- Get the current drawing order of the layers in globe. This includes draped, floating, and elevation layers. See the following code:
IEnumLayer enumLayer = globeDrawingOrder.OrderedLayers;
[VB.NET]
Dim enumLayer As IEnumLayer = globeDrawingOrder.OrderedLayers
- 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)
- 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 - Create separate ArrayLists for draped and elevation layers. See the following code:
ArrayList DrapedLayers = new ArrayList();
ArrayList ElevationLayers = new ArrayList();
[VB.NET]
Dim DrapedLayers As ArrayList = New ArrayList()
Dim ElevationLayers As ArrayList = New ArrayList()
- Loop through the IEnumLayer baseLayers to separate draped and elevation layers and store them in DrapedLayers and ElevationLayers, respectively. See the following code:
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
- 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:
// 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.
- 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:
// 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()
- The floating layers are stored in the IEnumLayer variable floatingLayers. The individual floating layers can be obtained as shown in the following code:
// 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):
ESRI.ArcGIS.3DAnalyst (ESRI.ArcGIS.Analyst3D)ESRI.ArcGIS.Carto ESRI.ArcGIS.GlobeCore ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)System.Collections
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 |