ArcGlobe组件开发之动画3——由指定路径创建动画(续)

上一篇博文主要介绍了根据路径实现飞行动画的接口,本篇博文则讲解其实现过程。这里我封装了一个生成动画的类,用于动画的操作,目前只是实现了动画的生成,动画的保存以及动画的加载,后面的博文再陆续探讨动画的播放控制等功能。创建动画类代码如下:

 /// <summary>
    /// 根据路径创建飞行动画
    /// </summary>
    class AnimationCreator
    {

        public IGlobe pGlobe //Globe对象
        {
            get;
            set;
        }
        public ILayer pLayer  //包含路径的线要素图层
        {
            get;
            set;
        }
        public int pFeatureID  //路径ID
        {
            get;
            set;
        }
        public string SaveFilePath    //动画文件保存路径
        {
            get;
            set;
        }
        public AnimationCreator ()
        {
        }
        #region"Create Animation from Path"

        ///<summary> 由路径来创建一个Camera动画.这条路径有图层提供一条三维线要素</summary>
        /// 
        ///<param name="globe">IGlobe接口</param>
        ///<param name="layer">一个包含PolyLine的ILayer接口</param>
        ///<param name="featureID">包含路径的要素ID.Example: 123</param>
        ///  
        ///<remarks></remarks>
        public void CreateAnimationFromPath ()
        {
            IGlobeDisplay globeDisplay = pGlobe.GlobeDisplay;
            IScene scene = globeDisplay.Scene;

            // 获取动画扩展
            IBasicScene2 basicScene2 =  scene  as IBasicScene2;
            IAnimationExtension animationExtension = basicScene2.AnimationExtension;

            //获取路径
            IFeatureLayer featureLayer = pLayer as IFeatureLayer; 
            IFeatureClass featureClass = featureLayer.FeatureClass;
            IFeature feature = featureClass.GetFeature(pFeatureID);
            IGeometry geometry = feature.Shape;

            //创建AGAnimationUtils和AGImportPathOptions对象
            ESRI.ArcGIS.Animation.IAGAnimationUtils agAnimationUtils = new AGAnimationUtilsClass();
            ESRI.ArcGIS.Animation.IAGImportPathOptions agImportPathOptions = new AGImportPathOptionsClass();

            // 设置AGImportPathOptions的属性
            agImportPathOptions.BasicMap = (IBasicMap)pGlobe;
            agImportPathOptions.AnimationTracks = (IAGAnimationTracks)pGlobe; 
            agImportPathOptions.AnimationType = new AnimationTypeGlobeCameraClass();
            agImportPathOptions.AnimatedObject = pGlobe.GlobeDisplay.ActiveViewer.Camera; //动画对象
            agImportPathOptions.PathGeometry = geometry;                      //动画轨迹
            agImportPathOptions.ConversionType = ESRI.ArcGIS.Animation.esriFlyFromPathType.esriFlyFromPathObsAndTarget;
            agImportPathOptions.LookaheadFactor = 0.05;
            agImportPathOptions.RollFactor = 0;

            agImportPathOptions.AnimationEnvironment = animationExtension.AnimationEnvironment;
            IAGAnimationContainer AGAnimationContainer = animationExtension.AnimationTracks.AnimationObjectContainer;

            //创建并保存动画
            agAnimationUtils.CreateFlybyFromPath(AGAnimationContainer,agImportPathOptions);
            if (System.IO.File.Exists(SaveFilePath))
            {
                System.IO.File.Delete(SaveFilePath);
                agAnimationUtils.SaveAnimationFile(AGAnimationContainer,SaveFilePath,esriArcGISVersion.esriArcGISVersion10);
            }
           
        }
        #endregion
    }
把生成的.aga文件导入即可播放。效果图如下:



原文地址:https://www.cnblogs.com/giser-whu/p/3707071.html