How to create a map layer animation track


This sample illustrates how to create a map layer animation track and add it to the animation track container. In the procedure "CreateAGAnimTrackMapLayer", two map layer keyframes will be created as an example. More keyframes can be created following the same method.

How to use

  1. Open ArcMap and add a layer (feature or raster) to the ArcMap TOC;
  2. Copy and paste the following code into the VB editor in ArcMap;
  3. Make sure that "ESRI Animation Object Library" and "ESRI AnimationUI Object Library" are checked in the References dialog box of the VBA project;
  4. Run the macro "CreateAndAddMapLayerTrack";
  5. 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 layer track has been created.
[VBA]
Public Sub CreateAndAddMapLayerTrack()
    '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 first layer in TOC
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Dim pLayer As ILayer
    Set pLayer = pMxDoc.Maps.Item(0).Layer(0)
    
    Dim iStartTransp As Integer
    Dim iEndTransp As Integer
    Dim bStartVis As Boolean
    Dim bEndVis As Boolean
    
    'Change these variables to create a different track
    iStartTransp = 0
    iEndTransp = 100
    bStartVis = True
    bEndVis = True
    
    'Create the track
    Dim pAnimTrack As IAGAnimationTrack
    Set pAnimTrack = CreateAGAnimTrackMapLayer(pLayer, iStartTransp, iEndTransp, _
                     bStartVis, bEndVis)
    
    '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 CreateAGAnimTrackMapLayer(ByRef pLayer As ILayer, ByVal startTransparency As Integer, _
                                           ByVal endTransparency As Integer, ByVal startVisibility As Boolean, _
                                           ByVal endVisibility As Boolean) As IAGAnimationTrack
    Dim pAnimTrack As IAGAnimationTrack
    Dim pAnimTrackKeyframes As IAGAnimationTrackKeyframes
    Dim pKeyframe As IAGKeyframe
    Dim pAnimtype As IAGAnimationType
    
    Set pAnimtype = New AnimationTypeMapLayer
    Set pKeyframe = New MapLayerKeyframe
    Set pAnimTrack = New AGAnimationTrack
    Set pAnimTrackKeyframes = pAnimTrack
    
    'Set the AnimationType property of the track
    Set pAnimTrack.AnimationType = pAnimtype
    pAnimTrack.Name = "Maplayertrack1"
    
    'Set keyframe 1
    pAnimTrackKeyframes.InsertKeyframe pKeyframe, -1
    pKeyframe.TimeStamp = 0#
    pKeyframe.Name = "Maplayerkeyframe1"
    pKeyframe.PropertyValue(0) = startVisibility
    pKeyframe.PropertyValue(1) = startTransparency
    
    'Set keyframe 2
    Set pKeyframe = New MapLayerKeyframe
    pAnimTrackKeyframes.InsertKeyframe pKeyframe, -1
    pKeyframe.TimeStamp = 1#
    pKeyframe.Name = "Maplayerkeyframe2"
    pKeyframe.PropertyValue(0) = endVisibility
    pKeyframe.PropertyValue(1) = endTransparency
    
    'Attach the layer object to the track
    pAnimTrack.AttachObject pLayer
    
    Set CreateAGAnimTrackMapLayer = 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