How to assign layers to keyframes

177
1
11-21-2021 05:01 AM
DonKihout
New Contributor

Hello everyone! Im trying to automate the animation creation process using ArcGIS Pro SDK. I have a few raster layers each of which is tied to a specific time. So i need to create several keyframes in each of which the corresponding raster layer will be visible. Can i to access layers properties in keyframes properties like in standart animation creation toolbar using SDK or there are another solutions?

I will be glad to recieve every answer!

0 Kudos
1 Reply
CharlesMacleod
Esri Regular Contributor

For an animation sample, see https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Map-Exploration/CustomAnimation 

The example below will remove any existing layer keyframes and add new keyframes for four layers - layersA, B, C, and D - so that each is visible for three seconds.  If the timing needs to line up with the CameraTrack, the TrackTime can be pulled from each keyframe for that track.  

Also, for a layer track the keyframes added to the beginning (zero seconds) should duplicate the second keyframe.  Otherwise it would only show for an instant before transitioning to the second keyframe.

layerTrack.CreateKeyFrame: https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/#topic11829.html 

 

 

var map = ....
//has four layers - eg raster layers - layersA, layersB, layersC, layersD
//
if (map != null)
      {
        LayerTrack layerTrack = null;
        foreach (var track in map.Animation.Tracks)
        {
          if (!(track is LayerTrack))
            continue;

          layerTrack = track as LayerTrack;
          break;
        }

        if (layerTrack.Keyframes.Count > 0)
          layerTrack.DeleteKeyframe(0, layerTrack.Keyframes.Count - 1);
        //Layer, time on the track, Visibility, Transparency, Animation type
        layerTrack.CreateKeyframe(layersA, new TimeSpan(0, 0, 0), true, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersB, new TimeSpan(0, 0, 0), false, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersC, new TimeSpan(0, 0, 0), false, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersD, new TimeSpan(0, 0, 0), false, 1.0, AnimationTransition.Linear);

        layerTrack.CreateKeyframe(layersA, new TimeSpan(0, 0, 3), true, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersB, new TimeSpan(0, 0, 3), false, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersC, new TimeSpan(0, 0, 3), false, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersD, new TimeSpan(0, 0, 3), false, 1.0, AnimationTransition.Linear);

        layerTrack.CreateKeyframe(layersA, new TimeSpan(0, 0, 6), false, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersB, new TimeSpan(0, 0, 6), true, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersC, new TimeSpan(0, 0, 6), false, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersD, new TimeSpan(0, 0, 6), false, 1.0, AnimationTransition.Linear);

        layerTrack.CreateKeyframe(layersA, new TimeSpan(0, 0, 9), false, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersB, new TimeSpan(0, 0, 9), false, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersC, new TimeSpan(0, 0, 9), true, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersD, new TimeSpan(0, 0, 9), false, 1.0, AnimationTransition.Linear);

        layerTrack.CreateKeyframe(layersA, new TimeSpan(0, 0, 12), false, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersB, new TimeSpan(0, 0, 12), false, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersC, new TimeSpan(0, 0, 12), false, 1.0, AnimationTransition.Linear);
        layerTrack.CreateKeyframe(layersD, new TimeSpan(0, 0, 12), true, 1.0, AnimationTransition.Linear);
      }

 

 

 

 

 

 

 

0 Kudos