public void InitAnimationByAgaFile(AxGlobeControl _axGlobeControl, string _FlyPathName, string FlyFoldPath, bool _NotFlyByPolyline, int _FlySpeedRating) { try { IsFlyByPolyline = _NotFlyByPolyline; string FlyFilePath = FlyFoldPath + "\\" + _FlyPathName + ".aga"; if (!File.Exists(FlyFilePath)) //如果此文件不存在 { return; } pAgAnimationUtils = new AGAnimationUtilsClass(); IBasicScene2 basicScene2 = (IBasicScene2)scene; // Explicit Cast pAnimationExtension = basicScene2.AnimationExtension; //飞行时长设置 switch (_FlySpeedRating) { case 1: FlyDurationTime = 40; break; case 2: FlyDurationTime = 30; break; case 3: FlyDurationTime = 20; break; case 4: FlyDurationTime = 15; break; case 5: FlyDurationTime = 10; break; default: FlyDurationTime = 20; break; } pAnimationExtension.AnimationEnvironment.AnimationDuration = FlyDurationTime; IAGAnimationContainer pContainer = pAnimationExtension.AnimationTracks.AnimationObjectContainer; pAgAnimationUtils.LoadAnimationFile(pContainer, FlyFilePath);//值不在预期的范围内; animPlayer = (IAGAnimationPlayer)pAgAnimationUtils; } catch { } }
//按预订的路径飞行 public bool InitAnimationPlay(AxGlobeControl _axGlobeControl, string _FlyPathName, string FlyFoldPath, int _FlySpeedRating, bool _IsFlyLoop, bool _IsFlyLookdown) { bool IsFoundPolyline = true; //是否能找到对应的Polyline try { scene = _axGlobeControl.GlobeDisplay.Scene; globe = _axGlobeControl.Globe; IBasicScene2 basicScene = (IBasicScene2)globe; pAgAnimationUtils = new AGAnimationUtilsClass(); //按路径飞行 ILayer layer = getLayerByName(scene, ANIMATIONPATH_LayerName); if (layer == null) { IsFoundPolyline = false; return(IsFoundPolyline); } FlyPathPolyline = getPolylineFromLayer(layer, _FlyPathName); if (FlyPathPolyline == null) { IsFoundPolyline = false; return(IsFoundPolyline); } //启用三维线 IZAware flyPathZAware = (IZAware)FlyPathPolyline; flyPathZAware.ZAware = true; pAnimationExtension = basicScene.AnimationExtension; CreateAnimationFromPath(globe, FlyPathPolyline, FlySpeedRating, IsFlyLoop, IsFlyLookdown); //配置飞行 //InitAnimationParameters(); //IAGAnimationContainer pContainer = pAnimationExtension.AnimationTracks.AnimationObjectContainer; //pAgAnimationUtils.LoadAnimationFile(pContainer, FlyFilePath);//值不在预期的范围内; animPlayer = (IAGAnimationPlayer)pAgAnimationUtils; } catch { } return(IsFoundPolyline); }
///<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(string path, string SaveFilePath) { IGlobe pGlobe = axGlobeControl1.Globe; IGlobeDisplay globeDisplay = pGlobe.GlobeDisplay; IScene scene = globeDisplay.Scene; // 获取动画扩展 IBasicScene2 basicScene2 = scene as IBasicScene2; IAnimationExtension animationExtension = basicScene2.AnimationExtension; //获取路径 //读取shp文件 IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory(); string pFolder = System.IO.Path.GetDirectoryName(path); string pFileName = System.IO.Path.GetFileName(path); //2打开shapeFile工作空间 IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pFolder, 0); IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; //3、打开要素类 IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(pFileName); //4、创建要素图层 IFeatureLayer pFLayer = new FeatureLayerClass(); //5、关联图层和要素类 pFLayer.FeatureClass = pFeatureClass; pFLayer.Name = pFeatureClass.AliasName; int b = pFeatureClass.ObjectClassID; ILayer pLayer = pFLayer; IFeatureLayer featureLayer = pLayer as IFeatureLayer; IFeatureClass featureClass = featureLayer.FeatureClass; //int pFeatureID = pFeatureClass.FeatureClassID; int pFeatureID = 0; 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); //播放 //获取AGAnimationEnvironment对象 IBasicScene2 basicscene = pGlobe as IBasicScene2; IAnimationExtension animationEx = basicscene.AnimationExtension; IAGAnimationEnvironment agAnimationEnv; agAnimationEnv = animationEx.AnimationEnvironment; agAnimationEnv.AnimationDuration = Convert.ToDouble("30"); //持续时间 agAnimationEnv.PlayType = esriAnimationPlayType.esriAnimationPlayTypeDuration; //播放模式 agAnimationEnv.PlayMode = esriAnimationPlayMode.esriAnimationPlayOnceForward; agAnimationEnv.PlayMode = esriAnimationPlayMode.esriAnimationPlayOnceReverse; //agAnimationEnv.PlayMode = esriAnimationPlayMode.esriAnimationPlayLoopForward; //agAnimationEnv.PlayMode = esriAnimationPlayMode.esriAnimationPlayLoopReverse; IAGAnimationPlayer agAnimationPlayer = agAnimationUtils as IAGAnimationPlayer; agAnimationPlayer.PlayAnimation(pGlobe as IAGAnimationTracks, agAnimationEnv, null); //保存 if (System.IO.File.Exists(SaveFilePath)) { System.IO.File.Delete(SaveFilePath); agAnimationUtils.SaveAnimationFile(AGAnimationContainer, SaveFilePath, esriArcGISVersion.esriArcGISVersion10); } }
/// <summary> ///第三个参数是移动的方式,其中1表示移动观察者,2表示移动目标,其他表示两个都移动 /// </summary> /// <param name="_pScene">_pGlobe</param> /// <param name="_pPolyline">_pPolyline</param> /// <param name="_pType">_pType</param> public void CreateAnimationFromPath(IGlobe _pGlobe, IPolyline _pPolyline, int _FlySpeedRating, bool _IsFlyLoop, bool _IsFlyLookdown)//int _pType,, double _pDuration) { try { #region //esri写的 scene = _pGlobe.GlobeDisplay.Scene; // 获取动画扩展对象 //ESRI.ArcGIS.Analyst3D.IBasicScene2 pBasicScene2 = (ESRI.ArcGIS.Analyst3D.IBasicScene2)_pScene; // Explicit Cast //ESRI.ArcGIS.Animation.IAnimationExtension pAnimationExtension = pBasicScene2.AnimationExtension; //创建两个对象,一个用于导入路径,一个用于播放 //ESRI.ArcGIS.Animation.IAGAnimationUtils pAGAnimationUtils = new ESRI.ArcGIS.Animation.AGAnimationUtilsClass(); pAGImportPathOptions = new ESRI.ArcGIS.Animation.AGImportPathOptionsClass(); // 设置参数 //参数设置不正确会出错,尤其是类型,对象等信息! pAGImportPathOptions.BasicMap = (ESRI.ArcGIS.Carto.IBasicMap)scene; pAGImportPathOptions.AnimationTracks = (ESRI.ArcGIS.Animation.IAGAnimationTracks)scene; // pAGImportPathOptions.AnimationType = new ESRI.ArcGIS.GlobeCore.AnimationTypeCameraClass(); //在Globe中不能用这个 pAGImportPathOptions.AnimationType = new AnimationTypeGlobeCameraClass(); pAGImportPathOptions.LookaheadFactor = 1; pAGImportPathOptions.PutAngleCalculationMethods(esriPathAngleCalculation.esriAngleAddRelative, esriPathAngleCalculation.esriAngleAddRelative, esriPathAngleCalculation.esriAngleAddRelative); //pAGImportPathOptions.AnimatedObject = _pScene.SceneGraph.ActiveViewer.Camera; //在Globe中不能用这个 pAGImportPathOptions.AnimatedObject = _pGlobe.GlobeDisplay.ActiveViewer.Camera; pAGImportPathOptions.PathGeometry = _pPolyline; //俯视飞行 if (_IsFlyLoop) { pAGImportPathOptions.ConversionType = ESRI.ArcGIS.Animation.esriFlyFromPathType.esriFlyFromPathObserver; //观察者移动 } else //正常飞行 { pAGImportPathOptions.ConversionType = ESRI.ArcGIS.Animation.esriFlyFromPathType.esriFlyFromPathObsAndTarget; //都移动 } //else //{ // pAGImportPathOptions.ConversionType = ESRI.ArcGIS.Animation.esriFlyFromPathType.esriFlyFromPathTarget; //} pAGImportPathOptions.LookaheadFactor = 1; pAGImportPathOptions.RollFactor = 0; pAGImportPathOptions.AnimationEnvironment = pAnimationExtension.AnimationEnvironment; // //InitAnimationParameters(); //持续时间 double FlyPathLength = FlyPathPolyline.Length; double flyDuration = FlyPathLength * 500 / _FlySpeedRating; //飞行路线长度*300*飞行速度等级/中速等级 FlyDurationTime = flyDuration; //记录飞行时间 pAnimationExtension.AnimationEnvironment.AnimationDuration = flyDuration; pAnimationExtension.AnimationEnvironment.IsIntervalPlay = false; pAnimationExtension.AnimationEnvironment.PlayMode = esriAnimationPlayMode.esriAnimationPlayOnceForward; pAnimationExtension.AnimationEnvironment.PlayTime = pAnimationExtension.AnimationEnvironment.AnimationDuration; //IAGAnimationEnvironment pAGAeviroment = new AGAnimationEnvironmentClass(); ESRI.ArcGIS.Animation.IAGAnimationContainer AGAnimationContainer = pAnimationExtension.AnimationTracks.AnimationObjectContainer; // 创建飞行路线类似ArcGlobe中的Import,通过ArcGlobe学习ArcGlobe开发! pAgAnimationUtils.CreateFlybyFromPath(AGAnimationContainer, pAGImportPathOptions); //该接口相当于播放的界面,可以自己做一个界面 animPlayer = pAgAnimationUtils as IAGAnimationPlayer; //animPlayer.PlayAnimation(_pScene as IAGAnimationTracks, pAGAeviroment, null); //开始飞行 #endregion } catch { } #region //用改变观察者和观察点的方式 //if (this.m_pScene.AreaOfInterest == null) // return; //// Explicit Cast //IBasicScene2 basicScene2 = (IBasicScene2)_pGlobe; //m_pAnimationExtension = basicScene2.AnimationExtension; //m_pAgAnimationUtils = new AGAnimationUtilsClass(); //IAGImportPathOptions agImportPathOptions = new AGImportPathOptionsClass(); //agImportPathOptions.AnimationEnvironment = m_pAnimationExtension.AnimationEnvironment; //IAGAnimationContainer AGAnimationContainer = m_pAnimationExtension.AnimationTracks.AnimationObjectContainer; //if (AGAnimationContainer != null) //{ // m_pAgAnimationUtils.CreateFlybyFromPath(AGAnimationContainer, agImportPathOptions); //} #endregion }
//按预订的路径飞行 public bool InitAnimationPlay(AxGlobeControl _axGlobeControl, string _FlyPathName, string FlyFoldPath, int _FlySpeedRating,bool _IsFlyLoop,bool _IsFlyLookdown) { bool IsFoundPolyline = true; //是否能找到对应的Polyline try { scene = _axGlobeControl.GlobeDisplay.Scene; globe = _axGlobeControl.Globe; IBasicScene2 basicScene = (IBasicScene2)globe; pAgAnimationUtils = new AGAnimationUtilsClass(); //按路径飞行 ILayer layer = getLayerByName(scene, ANIMATIONPATH_LayerName); if (layer == null) { IsFoundPolyline = false; return IsFoundPolyline; } FlyPathPolyline = getPolylineFromLayer(layer, _FlyPathName); if (FlyPathPolyline == null) { IsFoundPolyline = false; return IsFoundPolyline; } //启用三维线 IZAware flyPathZAware = (IZAware)FlyPathPolyline; flyPathZAware.ZAware = true; pAnimationExtension = basicScene.AnimationExtension; CreateAnimationFromPath(globe, FlyPathPolyline, FlySpeedRating, IsFlyLoop, IsFlyLookdown); //配置飞行 //InitAnimationParameters(); //IAGAnimationContainer pContainer = pAnimationExtension.AnimationTracks.AnimationObjectContainer; //pAgAnimationUtils.LoadAnimationFile(pContainer, FlyFilePath);//值不在预期的范围内; animPlayer = (IAGAnimationPlayer)pAgAnimationUtils; } catch { } return IsFoundPolyline; }
public void InitAnimationByAgaFile(AxGlobeControl _axGlobeControl, string _FlyPathName, string FlyFoldPath, bool _NotFlyByPolyline, int _FlySpeedRating) { try { IsFlyByPolyline = _NotFlyByPolyline; string FlyFilePath = FlyFoldPath + "\\" + _FlyPathName + ".aga"; if (!File.Exists(FlyFilePath)) //如果此文件不存在 { return; } pAgAnimationUtils = new AGAnimationUtilsClass(); IBasicScene2 basicScene2 = (IBasicScene2)scene; // Explicit Cast pAnimationExtension = basicScene2.AnimationExtension; //飞行时长设置 switch (_FlySpeedRating) { case 1: FlyDurationTime = 40; break; case 2: FlyDurationTime = 30; break; case 3: FlyDurationTime = 20; break; case 4: FlyDurationTime = 15; break; case 5: FlyDurationTime = 10; break; default: FlyDurationTime = 20; break; } pAnimationExtension.AnimationEnvironment.AnimationDuration = FlyDurationTime; IAGAnimationContainer pContainer = pAnimationExtension.AnimationTracks.AnimationObjectContainer; pAgAnimationUtils.LoadAnimationFile(pContainer, FlyFilePath);//值不在预期的范围内; animPlayer = (IAGAnimationPlayer)pAgAnimationUtils; } catch { } }
//int _pType,, double _pDuration) /// <summary> ///第三个参数是移动的方式,其中1表示移动观察者,2表示移动目标,其他表示两个都移动 /// </summary> /// <param name="_pScene">_pGlobe</param> /// <param name="_pPolyline">_pPolyline</param> /// <param name="_pType">_pType</param> public void CreateAnimationFromPath(IGlobe _pGlobe, IPolyline _pPolyline, int _FlySpeedRating, bool _IsFlyLoop, bool _IsFlyLookdown) { try { #region //esri写的 scene = _pGlobe.GlobeDisplay.Scene; // 获取动画扩展对象 //ESRI.ArcGIS.Analyst3D.IBasicScene2 pBasicScene2 = (ESRI.ArcGIS.Analyst3D.IBasicScene2)_pScene; // Explicit Cast //ESRI.ArcGIS.Animation.IAnimationExtension pAnimationExtension = pBasicScene2.AnimationExtension; //创建两个对象,一个用于导入路径,一个用于播放 //ESRI.ArcGIS.Animation.IAGAnimationUtils pAGAnimationUtils = new ESRI.ArcGIS.Animation.AGAnimationUtilsClass(); pAGImportPathOptions = new ESRI.ArcGIS.Animation.AGImportPathOptionsClass(); // 设置参数 //参数设置不正确会出错,尤其是类型,对象等信息! pAGImportPathOptions.BasicMap = (ESRI.ArcGIS.Carto.IBasicMap)scene; pAGImportPathOptions.AnimationTracks = (ESRI.ArcGIS.Animation.IAGAnimationTracks)scene; // pAGImportPathOptions.AnimationType = new ESRI.ArcGIS.GlobeCore.AnimationTypeCameraClass(); //在Globe中不能用这个 pAGImportPathOptions.AnimationType = new AnimationTypeGlobeCameraClass(); pAGImportPathOptions.LookaheadFactor = 1; pAGImportPathOptions.PutAngleCalculationMethods(esriPathAngleCalculation.esriAngleAddRelative, esriPathAngleCalculation.esriAngleAddRelative, esriPathAngleCalculation.esriAngleAddRelative); //pAGImportPathOptions.AnimatedObject = _pScene.SceneGraph.ActiveViewer.Camera; //在Globe中不能用这个 pAGImportPathOptions.AnimatedObject = _pGlobe.GlobeDisplay.ActiveViewer.Camera; pAGImportPathOptions.PathGeometry = _pPolyline; //俯视飞行 if (_IsFlyLoop) { pAGImportPathOptions.ConversionType = ESRI.ArcGIS.Animation.esriFlyFromPathType.esriFlyFromPathObserver;//观察者移动 } else //正常飞行 { pAGImportPathOptions.ConversionType = ESRI.ArcGIS.Animation.esriFlyFromPathType.esriFlyFromPathObsAndTarget;//都移动 } //else //{ // pAGImportPathOptions.ConversionType = ESRI.ArcGIS.Animation.esriFlyFromPathType.esriFlyFromPathTarget; //} pAGImportPathOptions.LookaheadFactor = 1; pAGImportPathOptions.RollFactor = 0; pAGImportPathOptions.AnimationEnvironment = pAnimationExtension.AnimationEnvironment; // //InitAnimationParameters(); //持续时间 double FlyPathLength = FlyPathPolyline.Length; double flyDuration = FlyPathLength *500 /_FlySpeedRating; //飞行路线长度*300*飞行速度等级/中速等级 FlyDurationTime = flyDuration; //记录飞行时间 pAnimationExtension.AnimationEnvironment.AnimationDuration = flyDuration; pAnimationExtension.AnimationEnvironment.IsIntervalPlay = false; pAnimationExtension.AnimationEnvironment.PlayMode = esriAnimationPlayMode.esriAnimationPlayOnceForward; pAnimationExtension.AnimationEnvironment.PlayTime = pAnimationExtension.AnimationEnvironment.AnimationDuration; //IAGAnimationEnvironment pAGAeviroment = new AGAnimationEnvironmentClass(); ESRI.ArcGIS.Animation.IAGAnimationContainer AGAnimationContainer = pAnimationExtension.AnimationTracks.AnimationObjectContainer; // 创建飞行路线类似ArcGlobe中的Import,通过ArcGlobe学习ArcGlobe开发! pAgAnimationUtils.CreateFlybyFromPath(AGAnimationContainer, pAGImportPathOptions); //该接口相当于播放的界面,可以自己做一个界面 animPlayer = pAgAnimationUtils as IAGAnimationPlayer; //animPlayer.PlayAnimation(_pScene as IAGAnimationTracks, pAGAeviroment, null); //开始飞行 #endregion } catch { } #region //用改变观察者和观察点的方式 //if (this.m_pScene.AreaOfInterest == null) // return; //// Explicit Cast //IBasicScene2 basicScene2 = (IBasicScene2)_pGlobe; //m_pAnimationExtension = basicScene2.AnimationExtension; //m_pAgAnimationUtils = new AGAnimationUtilsClass(); //IAGImportPathOptions agImportPathOptions = new AGImportPathOptionsClass(); //agImportPathOptions.AnimationEnvironment = m_pAnimationExtension.AnimationEnvironment; //IAGAnimationContainer AGAnimationContainer = m_pAnimationExtension.AnimationTracks.AnimationObjectContainer; //if (AGAnimationContainer != null) //{ // m_pAgAnimationUtils.CreateFlybyFromPath(AGAnimationContainer, agImportPathOptions); //} #endregion }