Represents a layer based on a layer package file (.lpk) or ArcGIS Desktop layer file (.lyr).

Namespace:  ESRI.ArcGISExplorer.Mapping

Assembly:  ESRI.ArcGISExplorer (in ESRI.ArcGISExplorer.dll) Version: 2.0.0.1500 (2.0.0.1500)

Syntax

C#
public sealed class PackageLayer : Layer, 
	IMapItemParent
Visual Basic (Declaration)
Public NotInheritable Class PackageLayer _
	Inherits Layer _
	Implements IMapItemParent

Remarks

The layer classes are a subset of MapItems that reference geographic data. A PackageLayer enables an ArcGIS Desktop layer file (.lyr) or a layer package file (.lpk) to be added to the map and displayed by the ArcGIS Explorer application.

ArcGIS Desktop layers are very similar to layers in ArcGIS Explorer; a layer represents an item of map content referencing geographic data. ArcGIS Desktop layers and group layers can be exported into a layer file (.lyr) which stores symbology and a reference to the underlying data, such as a feature class stored in a geodatabase. Layer files provide the ability to symbolize data using one of the many rendering options available in ArcGIS Desktop.

A layer package is similar to a layer file but can also contain the underlying data rather than simply referencing it. A layer package file (.lpk) is a single, ready-to-use file containing an ArcGIS Desktop layer or group layer and the data it uses. Desktop users can create layer packages so they can easily share both the symbology and data with other ArcGIS users. The advantage of using a layer package over a regular ArcGIS Desktop layer is that the data is packaged alongside the symbology - the layer can be displayed without relying on an external data source. Note that PackageLayers created from ArcSDE or map service data sources will always reference the data rather than containing it within the package.

If a layer package file is uploaded to ArcGIS Online, it can be made available for download. The downloadable file is not the actual layer package, but rather a small layer package information file (.pkinfo).

When a connected PackageLayer is added to the map, the related data is draped over the basemap and any existing layers. The layer must be in a connected state before data can be displayed. There are two ways to connect a layer to data:

1. Instantiate a PackageLayer and connect explicitly.

  • Create a new PackageLayer, populate the Path property and call PackageLayer.Connect()
  • A constructor is also provided to allow you to specify the URL or file path when you instantiate a layer. If the properties specified are incorrect, the PackageLayer will remain disconnected but no exception will be thrown; use the ConnectionStatus property to diagnose why a layer could not be connected.

2. Instantiate and connect with a single method call.

  • Use either the static Open method or OpenLayerFile method to both instantiate a PackageLayer and connect to its underlying data source with a single method call.
  • If successful the method will return a connected PackageLayer object. In contrast to the Connect method, an exception will be thrown if the URL or file path specified for the layer file\layer package file is incorrect. Therefore it is good practice to wrap a call to either of these methods in a try/catch block, so that any exceptions raised as a result of a connection failure will be caught.
  • The URL or file path you specify will be stored in the PackageLayer.Path property.

If a PackageLayer is added to the map in an unconnected state, no data will be displayed. The layer will still appear in the ArcGIS Explorer contents window with an exclamation mark to indicate the layer is not connected.

Once connected, you can access data dependent properties such as the geographical extent of the layer.

It is possible for a PackageLayer to reference spatial, vector data stored in an ESRI shapefile or geodatabase. If the layer is connected you can also retrieve the underlying data for the PackageLayer using the Table property. To verify if a PackageLayer contains tabular data use the HasTable property.

Layer packages and layer files can be created from group layers that contain one or more layers of information. Each constituent layer is represented by a PackageChildLayer object. Although the PackageLayer.ChildItems property is a MapItemCollection, it will always return a collection of PackageChildLayer objects and you cannot add to the collection.

Examples

The code below illustrates two approaches opening, connecting and adding a PackageLayer to the Map. The first creates a new PackageLayer then connects it manually whereas the second approach uses the static OpenLayerFile method to create a PackageLayer and connect it automatically. Note the differences in how to check for failed connections between the two approaches.
CopyC#
//Approach 1. Create a new PackageLayer, connect it manually then add it to the Map
PackageLayer pl1 = new PackageLayer(@"C:\Data\PackageLayers\US 2008-2013 Projected Growth.lpk");

//Connect the PackageLayer to its underlying data source.
bool connected = pl1.Connect();

//Test whether the connection succeeded
if (connected)
{
  //Add the PackageLayer to the Map
  ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map.ChildItems.Add(pl1);
}
else
{
  if (pl1.ConnectionStatus.HasError)
  {
    System.Diagnostics.Debug.Print(pl1.ConnectionStatus.ErrorString);
  }
}

//Approach 2. Create and connect a new PackageLayer then add it to the Map
PackageLayer pl2 = null;

try
{
  pl2 = PackageLayer.OpenLayerFile(@"C:\Data\PackageLayers\SeattleAP.lyr");
}
//Report connection problems
catch (Exception ex)
{
  System.Diagnostics.Debug.Print(ex.Message);
}

if (pl2 != null)
{
  //Add the PackageLayer to the Map
  ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map.ChildItems.Add(pl2);
}
CopyVB.NET
'Approach 1. Create a new PackageLayer, connect it manually then add it to the Map
Dim pl1 As PackageLayer = New PackageLayer("C:\Data\PackageLayers\US 2008-2013 Projected Growth.lpk")

'Connect the PackageLayer to its underlying data source.
Dim connected As Boolean = pl1.Connect()

'Test whether the connection succeeded
If (connected) Then
  'Add the PackageLayer to the Map
  ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map.ChildItems.Add(pl1)
Else

  If (pl1.ConnectionStatus.HasError) Then
    System.Diagnostics.Debug.Print(pl1.ConnectionStatus.ErrorString)
  End If
End If

'Approach 2. Create and connect a new PackageLayer then add it to the Map
Dim pl2 As PackageLayer = Nothing

Try
  pl2 = PackageLayer.OpenLayerFile("C:\Data\PackageLayers\SeattleAP.lyr")
Catch ex As Exception
  'Report connection problems
  System.Diagnostics.Debug.Print(ex.Message)
End Try

If Not pl2 Is Nothing Then
  'Add the PackageLayer to the Map
  ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map.ChildItems.Add(pl2)
End If

Inheritance Hierarchy

System..::.Object

  ESRI.ArcGISExplorer.Mapping..::.MapItem

    ESRI.ArcGISExplorer.Mapping..::.Layer

      ESRI.ArcGISExplorer.Mapping..::.PackageLayer

See Also