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


Add Tracking Layer To Map Snippet (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference

Add Tracking Layer To Map Snippet

Add a tracking layer (shapefile) to the active map.

[C#]
/// <summary>
/// Add a tracking layer (shapefile) to the active map.
/// </summary>
/// <param name="map"></param>
/// <param name="string_ShapefileDirectory">A System.String that is the directory location where a shapefiel is located. Example: "D:\arcgis\ArcTutor\Tracking_Analyst\Simple"</param>
/// <param name="string_TemporalFieldName">A System.String that is the TemporalFieldName. Example: "TA_DATE"</param>
/// <param name="string_TemporalObjectColumnName">A System.String that is the TemporalObjectColumnName. Example: "EVENTID"</param>
/// <remarks></remarks>
public void AddTrackingLayerToMap(ESRI.ArcGIS.Carto.IMap map, System.String string_ShapefileDirectory, System.String string_TemporalFieldName, System.String string_TemporalObjectColumnName)
{

  if (map == null)
  {
        return;
  }

  ESRI.ArcGIS.TrackingAnalyst.ITemporalRenderer temporalRenderer=new ESRI.ArcGIS.TrackingAnalyst.CoTrackSymbologyRendererClass();

  // Get the hurricane feature class from the shape file
  ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory=new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
  ESRI.ArcGIS.Geodatabase.IWorkspace workspace=workspaceFactory.OpenFromFile(string_ShapefileDirectory, 0);
  ESRI.ArcGIS.Geodatabase.IEnumDataset enumDataset=workspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);
  ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass=(ESRI.ArcGIS.Geodatabase.IFeatureClass)(enumDataset.Next());

  // Create a tracking layer
  ESRI.ArcGIS.TrackingAnalyst.ITemporalLayer temporalLayer=new ESRI.ArcGIS.TrackingAnalyst.TemporalFeatureLayerClass();
  ESRI.ArcGIS.Carto.ILayer layer=(ESRI.ArcGIS.Carto.ILayer)temporalLayer;
  ESRI.ArcGIS.Carto.IFeatureLayer featureLayer=(ESRI.ArcGIS.Carto.IFeatureLayer)layer;

  // Set the temporal column and event id column
  // Note: Set up the renderer before adding to layer
  temporalRenderer.TemporalFieldName=string_TemporalFieldName;
  temporalRenderer.TemporalObjectColumnName=string_TemporalObjectColumnName;

  temporalLayer.Renderer=(ESRI.ArcGIS.Carto.IFeatureRenderer)temporalRenderer;

  // Set the data
  featureLayer.FeatureClass=featureClass;

  // Add layer to map
  map.AddLayer(layer);

}
[Visual Basic .NET]
''' <summary>
''' Add a tracking layer (shapefile) to the active map.
''' </summary>
''' <param name="map"></param>
''' <param name="string_ShapefileDirectory">A System.String that is the directory location where a shapefiel is located. Example: "D:\arcgis\ArcTutor\Tracking_Analyst\Simple"</param>
''' <param name="string_TemporalFieldName">A System.String that is the TemporalFieldName. Example: "TA_DATE"</param>
''' <param name="string_TemporalObjectColumnName">A System.String that is the TemporalObjectColumnName. Example: "EVENTID"</param>
''' <remarks></remarks>
Public Sub AddTrackingLayerToMap(ByVal map As ESRI.ArcGIS.Carto.IMap, ByVal string_ShapefileDirectory As System.String, ByVal string_TemporalFieldName As System.String, ByVal string_TemporalObjectColumnName As System.String)

  If map Is Nothing Then
    Exit Sub
  End If

  Dim temporalRenderer As ESRI.ArcGIS.TrackingAnalyst.ITemporalRenderer=New ESRI.ArcGIS.TrackingAnalyst.CoTrackSymbologyRendererClass

  ' Get the hurricane feature class from the shape file
  Dim workspaceFactory As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory=New ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass
  Dim workspace As ESRI.ArcGIS.Geodatabase.IWorkspace=workspaceFactory.OpenFromFile(string_ShapefileDirectory, 0)
  Dim enumDataset As ESRI.ArcGIS.Geodatabase.IEnumDataset=workspace.Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny)
  Dim featureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass=CType(enumDataset.Next, ESRI.ArcGIS.Geodatabase.IFeatureClass)

  ' Create a tracking layer
  Dim temporalLayer As ESRI.ArcGIS.TrackingAnalyst.ITemporalLayer=New ESRI.ArcGIS.TrackingAnalyst.TemporalFeatureLayerClass
  Dim layer As ESRI.ArcGIS.Carto.ILayer=CType(temporalLayer, ESRI.ArcGIS.Carto.ILayer)
  Dim featureLayer As ESRI.ArcGIS.Carto.IFeatureLayer=CType(layer, ESRI.ArcGIS.Carto.IFeatureLayer)

  ' Set the temporal column and event id column
  ' Note: Set up the renderer before adding to layer
  temporalRenderer.TemporalFieldName=string_TemporalFieldName
  temporalRenderer.TemporalObjectColumnName=string_TemporalObjectColumnName

  temporalLayer.Renderer=CType(temporalRenderer, ESRI.ArcGIS.Carto.IFeatureRenderer)

  ' Set the data
  featureLayer.FeatureClass=featureClass

  ' Add layer to map
  map.AddLayer(layer)

End Sub

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Carto
  • ESRI.ArcGIS.DataSourcesFile
  • ESRI.ArcGIS.Display
  • ESRI.ArcGIS.Geodatabase
  • ESRI.ArcGIS.GlobeCore
  • ESRI.ArcGIS.System
  • ESRI.ArcGIS.TrackingAnalyst