A track stores the collection of keyframes whose values and transitions define the interpolated values for each frame of the animation. This property will always return 4 tracks and specifically it will contain one CameraTrack, LayerTrack, TimeTrack and RangeTrack. Each track type stores a corresponding keyframe for that type and is used to animate either the camera position, map time, map range, or layer visibility and transparency. The duration of the animation is equal to the time of the last keyframe in all tracks. The animation is removed from the map by deleting all keyframes in all tracks.
public List<CameraKeyframe> GetCameraKeyframes()
{
var mapView = MapView.Active;
if (mapView != null)
returnnull;
var animation = mapView.Map.Animation;
var cameraTrack = animation.Tracks.OfType<CameraTrack>().First(); //There will always be only 1 CameraTrack in the animation.
return cameraTrack.Keyframes.OfType<CameraKeyframe>().ToList();
}
publicvoid CreateCameraKeyframe(TimeSpan atTime)
{
var mapView = MapView.Active;
if (mapView != null)
return;
var animation = mapView.Map.Animation;
var cameraTrack = animation.Tracks.OfType<CameraTrack>().First(); //There will always be only 1 CameraTrack in the animation.
cameraTrack.CreateKeyframe(mapView.Camera, atTime, ArcGIS.Core.CIM.AnimationTransition.FixedArc);
}
publicvoid CreateTimeKeyframe(TimeSpan atTime)
{
var mapView = MapView.Active;
if (mapView != null)
return;
var animation = mapView.Map.Animation;
var timeTrack = animation.Tracks.OfType<TimeTrack>().First(); //There will always be only 1 TimeTrack in the animation.
timeTrack.CreateKeyframe(mapView.Time, atTime, ArcGIS.Core.CIM.AnimationTransition.Linear);
}
publicvoid CreateRangeKeyframe(ArcGIS.Desktop.Mapping.Range range, TimeSpan atTime)
{
var mapView = MapView.Active;
if (mapView != null)
return;
var animation = mapView.Map.Animation;
var rangeTrack = animation.Tracks.OfType<RangeTrack>().First(); //There will always be only 1 RangeTrack in the animation.
rangeTrack.CreateKeyframe(range, atTime, ArcGIS.Core.CIM.AnimationTransition.Linear);
}
publicvoid CreateLayerKeyframe(Layer layer, double transparency, TimeSpan atTime)
{
var mapView = MapView.Active;
if (mapView != null)
return;
var animation = mapView.Map.Animation;
var layerTrack = animation.Tracks.OfType<LayerTrack>().First(); //There will always be only 1 LayerTrack in the animation.
layerTrack.CreateKeyframe(layer, atTime, true, transparency, ArcGIS.Core.CIM.AnimationTransition.Linear);
}