This sample code illustrates how to create a map view animation track, set map view keyframes, and add it to the animation track container. The procedure "CreateAGAnimTrackMapView" creates two map view keyframes for the track. More keyframes can be created following the same method.
How to use
- Open ArcMap and add a layer (feature or raster) to the ArcMap TOC;
- Copy and paste the following code into the VB editor in ArcMap;
- Make sure that "ESRI Animation Object Library" and "ESRI AnimationUI Object Library" are checked in the References dialog box of the VBA project;
- Change the variables used by the "CreateAGAnimTrackTimeLayer" function according to your data;
- Run the macro "CreateAndAddMapViewTrack";
- Click the Animation dropdown on the animation toolbar and click Animation Manager. In the Animation Manager dialog box, click the Tracks tab to verify that a new map view animation track has been created.
Public Sub CreateAndAddMapViewTrack()
'Get the animation extension
Dim pAnimExt As IAnimationExtension
Set pAnimExt = FindAnimationExtension()
'Get the animation track container from the animation extension
Dim pAnimTracks As IAGAnimationTracks
Set pAnimTracks = pAnimExt.AnimationTracks
'Get the frist layer in TOC
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Dim pView As IActiveView
Set pView = pMap
'Change pEnv1 and pEnv2 to create your own map view track
Dim pEnv1 As IEnvelope
Set pEnv1 = pView.Extent
Dim pEnv2 As IEnvelope
Set pEnv2 = pView.Extent
pEnv2.CenterAt pEnv2.LowerLeft
'Create the track
Dim pAnimTrack As IAGAnimationTrack
Set pAnimTrack = CreateAGAnimTrackMapView(pMap, pEnv1, pEnv2)
'Add the track to the animation track container so that it is visible in the Animation Manager
pAnimTracks.AddTrack pAnimTrack
pAnimExt.AnimationContentsModified
End Sub
Private Function CreateAGAnimTrackMapView(ByRef pMap As IMap, ByRef pStartViewExtent As IEnvelope, _
ByRef pEndViewExtent As IEnvelope) As IAGAnimationTrack
Dim pAnimTrack As IAGAnimationTrack
Dim pAnimTrackKeyframes As IAGAnimationTrackKeyframes
Dim pKeyframe As IAGKeyframe
Dim pAnimtype As IAGAnimationType
Set pAnimtype = New AnimationTypeMapView
Set pKeyframe = New MapViewKeyframe
Set pAnimTrack = New AGAnimationTrack
Set pAnimTrackKeyframes = pAnimTrack
'Set the AnimationType property of the track
Set pAnimTrack.AnimationType = pAnimtype
pAnimTrack.Name = "Mapviewtrack1"
'Set keyframe 1
pAnimTrackKeyframes.InsertKeyframe pKeyframe, -1
pKeyframe.TimeStamp = 0
pKeyframe.Name = "Mapviewkeyframe1"
pKeyframe.PropertyValue(0) = pStartViewExtent
'Set keyframe 2
Set pKeyframe = New MapViewKeyframe
pAnimTrackKeyframes.InsertKeyframe pKeyframe, -1
pKeyframe.TimeStamp = 1
pKeyframe.Name = "Mapviewkeyframe2"
pKeyframe.PropertyValue(0) = pEndViewExtent
'Attach the map object to the track
pAnimTrack.AttachObject pMap
Set CreateAGAnimTrackMapView = pAnimTrack
End Function
Private Function FindAnimationExtension() As IAnimationExtension
Dim pUID As New UID
pUID.Value = "esriAnimation.AnimationExtension"
Dim pAnimExt As IAnimationExtension
Set pAnimExt = Application.FindExtensionByCLSID(pUID)
Set FindAnimationExtension = pAnimExt
End Function