About the Make a custom time slider Sample
[C#]
CustomTimeSliderButton.cs
using System; using System.Collections.Generic; using System.Text; using System.IO; using ESRI.ArcGIS.ArcMapUI; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Display; using System.Windows.Forms; namespace MakeACustomTimeControl2008 { public class CustomTimeSliderButton : ESRI.ArcGIS.Desktop.AddIns.Button { ITimeExtent m_myLayerTimeExtent = null; ITimeDuration m_layerInterval = null; TimeSliderDialog m_sliderDlg = null; public CustomTimeSliderButton() { } protected override void OnClick() { IMxDocument pMxDoc = ArcMap.Document; if (pMxDoc.SelectedLayer == null) { MessageBox.Show("There is no layer selected. First select a time-aware layer."); return; } IFeatureLayer pFLyr = pMxDoc.SelectedLayer as IFeatureLayer; ITimeData pTimeData = pFLyr as ITimeData; if (!pTimeData.SupportsTime) { MessageBox.Show("Select a time-aware layer first."); return; } m_myLayerTimeExtent = pTimeData.GetFullTimeExtent(); ITimeDataDisplay pTimeDataDisplayProperties = pFLyr as ITimeDataDisplay; esriTimeUnits LayerIntervalUnits = pTimeDataDisplayProperties.TimeIntervalUnits; double LayerInterval = pTimeDataDisplayProperties.TimeInterval; ITime startTime = m_myLayerTimeExtent.StartTime; ITime endTime = (ITime)((IClone)startTime).Clone(); switch (LayerIntervalUnits) { case esriTimeUnits.esriTimeUnitsYears: ((ITimeOffsetOperator)endTime).AddYears(LayerInterval, false, true); break; case esriTimeUnits.esriTimeUnitsMonths: ((ITimeOffsetOperator)endTime).AddMonths(LayerInterval, false, true); break; case esriTimeUnits.esriTimeUnitsDays: ((ITimeOffsetOperator)endTime).AddDays(LayerInterval); break; case esriTimeUnits.esriTimeUnitsHours: ((ITimeOffsetOperator)endTime).AddHours(LayerInterval); break; case esriTimeUnits.esriTimeUnitsMinutes: ((ITimeOffsetOperator)endTime).AddMinutes(LayerInterval); break; case esriTimeUnits.esriTimeUnitsSeconds: ((ITimeOffsetOperator)endTime).AddSeconds(LayerInterval); break; } ITimeExtent pTimeExt = new TimeExtentClass(); pTimeExt.SetExtent(startTime, endTime); m_layerInterval = pTimeExt.QueryTimeDuration(); m_sliderDlg = new TimeSliderDialog(this); m_sliderDlg.Show(); } public ITimeExtent GetTimeExtent() { return m_myLayerTimeExtent; } public void UpdateCurrentTime(double progress) { if (progress <= 0) progress = 0.05; else if (progress >= 100) progress = 0.95; //Calculate how far into the layer to jump ITimeDuration offsetToNewCurrentTime = m_myLayerTimeExtent.QueryTimeDuration(); offsetToNewCurrentTime.Scale(progress); IMxDocument pMxDoc = ArcMap.Document; IMap pMap = pMxDoc.FocusMap; IActiveView pActiveView = pMap as IActiveView; IScreenDisplay pScreenDisplay = pActiveView.ScreenDisplay; ITimeDisplay pTimeDisplay = pScreenDisplay as ITimeDisplay; ITime startTime = m_myLayerTimeExtent.StartTime; ITime endTime = (ITime)((IClone)startTime).Clone(); ((ITimeOffsetOperator)endTime).AddDuration(m_layerInterval); ITimeExtent pTimeExt = new TimeExtentClass(); pTimeExt.SetExtent(startTime, endTime); pTimeExt.Empty = false; ((ITimeOffsetOperator)pTimeExt).AddDuration(offsetToNewCurrentTime); pTimeDisplay.TimeValue = pTimeExt as ITimeValue; pActiveView.Refresh(); } protected override void OnUpdate() { Enabled = true; } } }
[Visual Basic .NET]
CustomTimeSliderButton.vb
Imports ESRI.ArcGIS.ArcMapUI Imports ESRI.ArcGIS.Carto Imports ESRI.ArcGIS.esriSystem Imports ESRI.ArcGIS.Display Imports System.Windows.Forms Public Class CustomTimeSliderButton Inherits ESRI.ArcGIS.Desktop.AddIns.Button Private m_myLayerTimeExtent As ITimeExtent = Nothing Private m_myLayerIntervalUnits As ESRI.ArcGIS.esriSystem.esriTimeUnits Private m_myLayerInterval As Double = 0 Private m_sliderDlg As TimeSliderDialog = Nothing Public Sub New() End Sub Protected Overrides Sub OnClick() Dim pMxDoc As IMxDocument = My.ArcMap.Document If pMxDoc.SelectedLayer Is Nothing Then MessageBox.Show("There is no layer selected. First select a time-aware layer.") Return End If Dim pFLyr As IFeatureLayer = TryCast(pMxDoc.SelectedLayer, IFeatureLayer) Dim pTimeData As ITimeData = TryCast(pFLyr, ITimeData) If (Not pTimeData.SupportsTime) Then MessageBox.Show("Select a time-aware layer first.") Return End If m_myLayerTimeExtent = pTimeData.GetFullTimeExtent() Dim pTimeDataDisplayProperties As ITimeDataDisplay = TryCast(pFLyr, ITimeDataDisplay) m_myLayerIntervalUnits = pTimeDataDisplayProperties.TimeIntervalUnits m_myLayerInterval = pTimeDataDisplayProperties.TimeInterval m_sliderDlg = New TimeSliderDialog(Me) m_sliderDlg.Show() End Sub Public Function GetTimeExtent() As ITimeExtent Return m_myLayerTimeExtent End Function Private Sub Multiply(ByVal duration As ITimeDuration, ByVal factor As Double) duration.SetFromTicks(CLng(Fix(duration.QueryTicks() * factor))) End Sub Public Sub UpdateCurrentTime(ByVal progress As Double) My.ArcMap.Application.StatusBar.Message(0) = "progress = " & progress & ", interval = " & m_myLayerInterval 'Calculate how far into the layer to jump Dim offsetToNewCurrentTime As ITimeDuration = m_myLayerTimeExtent.QueryTimeDuration offsetToNewCurrentTime.Scale(progress) Dim pMxDoc As IMxDocument = My.ArcMap.Document Dim pMap As IMap = pMxDoc.FocusMap Dim pActiveView As IActiveView = TryCast(pMap, IActiveView) Dim pScreenDisplay As IScreenDisplay = pActiveView.ScreenDisplay Dim pTimeDisplay As ITimeDisplay = TryCast(pScreenDisplay, ITimeDisplay) Dim endTime As ITime = m_myLayerTimeExtent.StartTime Dim endTimeDuration As ITimeOffsetOperator endTimeDuration = TryCast(endTime, ITimeOffsetOperator) endTimeDuration.AddDuration(offsetToNewCurrentTime) Dim startTime As ITime = CType((CType(endTime, IClone)).Clone(), ITime) Dim startTimeOffsetOp As ITimeOffsetOperator startTimeOffsetOp = TryCast(startTime, ITimeOffsetOperator) Select Case m_myLayerIntervalUnits Case ESRI.ArcGIS.esriSystem.esriTimeUnits.esriTimeUnitsYears startTimeOffsetOp.AddYears(-1 * m_myLayerInterval, False, True) Case ESRI.ArcGIS.esriSystem.esriTimeUnits.esriTimeUnitsMonths startTimeOffsetOp.AddMonths(-1 * m_myLayerInterval, False, True) Case ESRI.ArcGIS.esriSystem.esriTimeUnits.esriTimeUnitsDays startTimeOffsetOp.AddDays(-1 * m_myLayerInterval) Case ESRI.ArcGIS.esriSystem.esriTimeUnits.esriTimeUnitsHours startTimeOffsetOp.AddHours(-1 * m_myLayerInterval) Case ESRI.ArcGIS.esriSystem.esriTimeUnits.esriTimeUnitsMinutes startTimeOffsetOp.AddMinutes(-1 * m_myLayerInterval) Case ESRI.ArcGIS.esriSystem.esriTimeUnits.esriTimeUnitsSeconds startTimeOffsetOp.AddSeconds(-1 * m_myLayerInterval) End Select Dim pTimeExt As ITimeExtent = New TimeExtentClass() pTimeExt.SetExtent(startTime, endTime) pTimeDisplay.TimeValue = TryCast(pTimeExt, ITimeValue) pActiveView.Refresh() End Sub Protected Overrides Sub OnUpdate() Enabled = True End Sub End Class