About the Set the time extents for a layer then render the layer Sample
[C#]
SetTimeExtentsButton.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Display;
namespace SetTimeExtentsForALayer2008
{
public class SetTimeExtentsButton : ESRI.ArcGIS.Desktop.AddIns.Button
{
public SetTimeExtentsButton()
{
}
protected override void OnClick()
{
IMxDocument pMxDoc = ArcMap.Document;
IMap pMap = pMxDoc.FocusMap;
string sampeMapFileName = "BasicHurricanes.mxd";
if (pMap.LayerCount < 1)
{
MessageBox.Show("Before running this sample, load the associated file \'" + sampeMapFileName + "\'");
return;
}
if (pMap.get_Layer(0).Name != "atlantic_hurricanes_2000")
{
MessageBox.Show("Before running this sample, load the associated file \'" + sampeMapFileName + "\'");
return;
}
ITimeZoneFactory pTZFac = new TimeZoneFactoryClass();
//making the first layer of the focused map time-aware
IFeatureLayer pFLyr = pMap.get_Layer(0) as IFeatureLayer;
ITimeData pTimeData = pFLyr as ITimeData;
String localTimeZoneId = pTZFac.QueryLocalTimeZoneWindowsID();
ITimeReference timeRef = pTZFac.CreateTimeReferenceFromWindowsID(localTimeZoneId);
if (pTimeData.SupportsTime)
{
pTimeData.UseTime = true;
ITimeTableDefinition pTimeDataDef = pFLyr as ITimeTableDefinition;
pTimeDataDef.StartTimeFieldName = "Date_Time";
pTimeDataDef.TimeReference = timeRef;
ITimeDataDisplay pTimeAnimProp = pFLyr as ITimeDataDisplay;
pTimeAnimProp.TimeIntervalUnits = esriTimeUnits.esriTimeUnitsHours;
pTimeAnimProp.TimeInterval = 12.0;
}
//
IActiveView pActiveView = pMap as IActiveView;
IScreenDisplay pScreenDisplay = pActiveView.ScreenDisplay;
ITimeDisplay pTimeDisplay = pScreenDisplay as ITimeDisplay;
pTimeDisplay.TimeReference = timeRef;
ITime pStartTime = new TimeClass();
pStartTime.Year = 2000; pStartTime.Month = 9; pStartTime.Day = 25;
ITime pEndTime = new TimeClass();
pEndTime.Year = 2000; pEndTime.Month = 9; pEndTime.Day = 30;
ITimeExtent pTimeExt = new TimeExtentClass();
pTimeExt.StartTime = pStartTime;
pTimeExt.EndTime = pEndTime;
pTimeDisplay.TimeValue = pTimeExt as ITimeValue;
pActiveView.ContentsChanged();
}
protected override void OnUpdate()
{
//Enabled = ArcMap.Application != null;
Enabled = true;
}
}
}
[Visual Basic .NET]
SetTimeExtentsButton.vb
Imports System.Windows.Forms
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.ArcMapUI
Public Class SetTimeExtentsButton
Inherits ESRI.ArcGIS.Desktop.AddIns.Button
Public Sub New()
End Sub
Protected Overrides Sub OnClick()
Dim pMxDoc As IMxDocument = My.ArcMap.Document
Dim pMap As IMap = pMxDoc.FocusMap
Dim sampeMapFileName As String = "BasicHurricanes.mxd"
If pMap.LayerCount < 1 Then
MessageBox.Show("Before running this sample, load the associated file '" & sampeMapFileName & "'")
Return
End If
If pMap.Layer(0).Name <> "atlantic_hurricanes_2000" Then
MessageBox.Show("Before running this sample, load the associated file '" & sampeMapFileName & "'")
Return
End If
Dim pTZFac As ITimeZoneFactory = New TimeZoneFactoryClass()
'making the first layer of the focused map time-aware
Dim pFLyr As IFeatureLayer = TryCast(pMap.Layer(0), IFeatureLayer)
Dim pTimeData As ITimeData = TryCast(pFLyr, ITimeData)
If pTimeData.SupportsTime Then
pTimeData.UseTime = True
Dim pTimeDataDef As ITimeTableDefinition = TryCast(pFLyr, ITimeTableDefinition)
pTimeDataDef.StartTimeFieldName = "Date_Time"
pTimeDataDef.TimeReference = pTZFac.CreateTimeReferenceFromWindowsID(pTZFac.QueryLocalTimeZoneWindowsID)
Dim pTimeAnimProp As ITimeDataDisplay = TryCast(pFLyr, ITimeDataDisplay)
pTimeAnimProp.TimeIntervalUnits = ESRI.ArcGIS.esriSystem.esriTimeUnits.esriTimeUnitsHours
pTimeAnimProp.TimeInterval = 12.0
End If
'
Dim pActiveView As IActiveView = TryCast(pMap, IActiveView)
Dim pScreenDisplay As IScreenDisplay = pActiveView.ScreenDisplay
Dim pTimeDisplay As ITimeDisplay = TryCast(pScreenDisplay, ITimeDisplay)
pTimeDisplay.TimeReference = pTZFac.CreateTimeReferenceFromWindowsID(pTZFac.QueryLocalTimeZoneWindowsID)
Dim pStartTime As ITime = New TimeClass()
pStartTime.Year = 2000
pStartTime.Month = 9
pStartTime.Day = 25
Dim pEndTime As ITime = New TimeClass()
pEndTime.Year = 2000
pEndTime.Month = 9
pEndTime.Day = 30
Dim pTimeExt As ITimeExtent = New TimeExtentClass()
pTimeExt.StartTime = pStartTime
pTimeExt.EndTime = pEndTime
pTimeDisplay.TimeValue = TryCast(pTimeExt, ITimeValue)
pActiveView.ContentsChanged()
End Sub
Protected Overrides Sub OnUpdate()
Enabled = True
End Sub
End Class