ArcObjects Library Reference

TimeControl Playback Snippet

Open a timecontrol and control a playback sequence without displaying the timecontrol GUI.

[C#]
/// <summary>
/// Open a timecontrol and control a playback sequence without displaying the timecontrol GUI.
/// </summary>
/// <param name="application">An IApplication interface.</param>
/// <remarks></remarks>
public void TimeControlPlayback(ESRI.ArcGIS.Framework.IApplication application)
{

  if (application == null)
  {
	return;
  }

  ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)application.Document; // Explicit Cast
  ESRI.ArcGIS.Carto.IMap map = mxDocument.FocusMap;
  ESRI.ArcGIS.TrackingAnalyst.ITemporalLayer temporalLayer = null;

  if (map.get_Layer(0) is ESRI.ArcGIS.TrackingAnalyst.ITemporalLayer)
  {
      temporalLayer = (ESRI.ArcGIS.TrackingAnalyst.ITemporalLayer)map.get_Layer(0); // Explicit Cast
  }

  if (temporalLayer == null)
  {
	System.Windows.Forms.MessageBox.Show("Error: Layer is not a tracking layer");
	return;
  }

  ESRI.ArcGIS.TrackingAnalyst.ITimeControl timeControl = new ESRI.ArcGIS.TrackingAnalystUI.TimeControlClass();
  System.Int32 int32_hWnd = application.hWnd;

  timeControl.CurrentMap = mxDocument.FocusMap;
  timeControl.SetVisible(int32_hWnd, false); // This needs to be true
  timeControl.SetTemporalReferencesFromMap();
  timeControl.TemporalMode = ESRI.ArcGIS.TrackingAnalyst.enumPlaybackTemporalMode.enumTemporalHistoric;

  if (! (timeControl.Status == ESRI.ArcGIS.TrackingAnalyst.enumTimeControlStatus.enumStopped))
  {
	timeControl.Stop();
  }

  timeControl.SetTimeSequenceInterval(ESRI.ArcGIS.TrackingAnalyst.enumTemporalUnits.enumDays, 1);
  timeControl.CurrentTime = timeControl.StartTime;
  timeControl.Play(ESRI.ArcGIS.TrackingAnalyst.enumDirection.enumForward);

}
[Visual Basic .NET]
''' <summary>
''' Open a timecontrol and control a playback sequence without displaying the timecontrol GUI.
''' </summary>
''' <param name="application">An IApplication interface.</param>
''' <remarks></remarks>
Public Sub TimeControlPlayback(ByVal application As ESRI.ArcGIS.Framework.IApplication)

  If application Is Nothing Then
    Exit Sub
  End If

  Dim mxDocument As ESRI.ArcGIS.ArcMapUI.IMxDocument = CType(application.Document, ESRI.ArcGIS.ArcMapUI.IMxDocument) ' Explicit Cast
  Dim map As ESRI.ArcGIS.Carto.IMap = mxDocument.FocusMap
  Dim temporalLayer As ESRI.ArcGIS.TrackingAnalyst.ITemporalLayer = Nothing

  If TypeOf map.Layer(0) Is ESRI.ArcGIS.TrackingAnalyst.ITemporalLayer Then
    temporalLayer = CType(map.Layer(0), ESRI.ArcGIS.TrackingAnalyst.ITemporalLayer) ' Explicit Cast
  End If

  If temporalLayer Is Nothing Then
    System.Windows.Forms.MessageBox.Show("Error: Layer is not a tracking layer")
    Exit Sub
  End If

  Dim timeControl As ESRI.ArcGIS.TrackingAnalyst.ITimeControl = New ESRI.ArcGIS.TrackingAnalystUI.TimeControlClass
  Dim int32_hWnd As System.Int32 = application.hWnd

  timeControl.CurrentMap = mxDocument.FocusMap
  timeControl.SetVisible(int32_hWnd, False)  ' This needs to be true
  timeControl.SetTemporalReferencesFromMap()
  timeControl.TemporalMode = ESRI.ArcGIS.TrackingAnalyst.enumPlaybackTemporalMode.enumTemporalHistoric

  If (Not timeControl.Status = ESRI.ArcGIS.TrackingAnalyst.enumTimeControlStatus.enumStopped) Then
    timeControl.Stop()
  End If

  timeControl.SetTimeSequenceInterval(ESRI.ArcGIS.TrackingAnalyst.enumTemporalUnits.enumDays, 1)
  timeControl.CurrentTime = timeControl.StartTime
  timeControl.Play(ESRI.ArcGIS.TrackingAnalyst.enumDirection.enumForward)

End Sub


Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.ArcMapUI
  • ESRI.ArcGIS.Carto
  • ESRI.ArcGIS.Framework
  • ESRI.ArcGIS.TrackingAnalyst
  • ESRI.ArcGIS.TrackingAnalystUI
  • System.Windows.Forms