public void Apply(IAGAnimationTrack pTrack, IAGAnimationContainer pContainer, object pObject)
 {
     SetBrightness((ILayer)pObject, brightness);
     SetContrast((ILayer)pObject, contrast);
     pContainer.RefreshObject(pObject);
     return;
 }
        private void RemoveGraphicFromDisplay(IElement elem, IAGAnimationContainer animContainer)
        {
            IActiveView        view = animContainer.CurrentView as IActiveView;
            IGraphicsContainer graphicsContainer = view as IGraphicsContainer;

            graphicsContainer.DeleteElement(elem);
        }
        private void MoveElement(IElement elem, IPoint new_pos, IAGAnimationContainer pContainer)
        {
            ITransform2D transform2D = elem as ITransform2D;
            IPoint       origin;

            if (elem.Geometry.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                origin = elem.Geometry as IPoint;
            }
            else
            {
                IEnvelope elementEnvelope = elem.Geometry.Envelope;
                IArea     elementArea     = elementEnvelope as IArea;
                origin = elementArea.Centroid;
            }

            AddPropertySet(elem);

            IElementProperties prop = (IElementProperties)elem; //record the old properties
            IPropertySet       propSet;

            propSet = (IPropertySet)prop.CustomProperty;
            IEnvelope oldEnv = GetElementBound(elem, pContainer);

            propSet.SetProperty("Envelope", oldEnv);

            transform2D.Move(new_pos.X - origin.X, new_pos.Y - origin.Y);
        }
        private void buttonImport_Click(object sender, EventArgs e)
        {
            createTrackOptions.OverwriteTrack       = this.checkBoxOverwriteTrack.Checked;
            createTrackOptions.ReverseOrder         = this.checkBoxReverseOrder.Checked;
            createTrackOptions.TrackName            = this.textBoxTrackName.Text;
            createTrackOptions.SimplificationFactor = (double)this.trackBar1.Value / 100.0;
            createTrackOptions.PointElement         = pointGraphic;
            createTrackOptions.LineElement          = lineGraphic;
            createTrackOptions.AnimatePath          = this.checkBoxTracePath.Checked;

            if (this.radioButtonLineFeature.Checked)
            {
                createTrackOptions.PathGeometry = lineFeature;
            }
            else if (this.radioButtonLineGraphic.Checked)
            {
                IElement temp = (IElement)lineGraphic;
                createTrackOptions.PathGeometry = temp.Geometry;
            }

            IAGAnimationTracks    tracks     = AnimationExtension.AnimationTracks;
            IAGAnimationContainer pContainer = tracks.AnimationObjectContainer;

            AnimationUtils.CreateMapGraphicTrack(createTrackOptions, tracks, pContainer);

            AnimationExtension.AnimationContentsModified();
            this.Close();
        }
        private void RotateElement(IElement elem, double new_angle, IAGAnimationContainer pContainer)
        {
            ITransform2D transform2D = elem as ITransform2D;
            IPoint       rotateOrigin;

            if (elem.Geometry.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                rotateOrigin = elem.Geometry as IPoint;
            }
            else
            {
                IEnvelope elementEnvelope = elem.Geometry.Envelope;
                IArea     elementArea     = elementEnvelope as IArea;
                rotateOrigin = elementArea.Centroid;
            }

            AddPropertySet(elem);

            IElementProperties prop = (IElementProperties)elem; //record the old properties
            IPropertySet       propSet;

            propSet = (IPropertySet)prop.CustomProperty;
            double old_angle;

            old_angle = (double)propSet.GetProperty("Angle");

            propSet.SetProperty("Angle", new_angle); //update old angle

            transform2D.Rotate(rotateOrigin, new_angle - old_angle);
        }
 public void Apply(IAGAnimationTrack pTrack, IAGAnimationContainer pContainer, object pObject)
 {
     SetBrightness((ILayer)pObject, brightness);
     SetContrast((ILayer)pObject, contrast);
     pContainer.RefreshObject(pObject);
     return;
 }
        public void CaptureProperties(IAGAnimationContainer pContainer, object pObject)
        {
            IElement    elem = pObject as IElement;
            IActiveView view = pContainer.CurrentView as IActiveView;
            IGraphicsContainerSelect graphicsConSel = view as IGraphicsContainerSelect;
            IDisplay  disp    = view.ScreenDisplay as IDisplay;
            IEnvelope elemEnv = GetElementBound(elem, pContainer);

            if (elem.Geometry.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                Position = elem.Geometry as IPoint;
            }
            else
            {
                IEnvelope elementEnvelope = elem.Geometry.Envelope;
                IArea     elementArea     = elementEnvelope as IArea;
                Position = elementArea.Centroid;
            }

            IElementProperties elemProps = (IElementProperties)elem;

            if (elemProps.CustomProperty != null)
            {
                Rotation = (double)elemProps.CustomProperty;
            }
        }
        public void Apply(IAGAnimationTrack pTrack, IAGAnimationContainer pContainer, object pObject)
        {
            IElement elem = (IElement)pObject;

            UpdateGraphicObject(elem, pContainer, pTrack, Position, Rotation);

            return;
        }
        private void AddGraphicToDisplay(IElement elem, IAGAnimationContainer animContainer)
        {
            IActiveView        view = animContainer.CurrentView as IActiveView;
            IGraphicsContainer graphicsContainer = view as IGraphicsContainer;

            graphicsContainer.AddElement(elem, 0);
            elem.Activate(view.ScreenDisplay);
        }
        public void Apply(IAGAnimationTrack pTrack, IAGAnimationContainer pContainer, object pObject)
        {
            IElement elem = (IElement) pObject;

            UpdateGraphicObject(elem,pContainer,pTrack,Position,Rotation);

            return;
        }
Beispiel #11
0
        public string get_AnimationObjectName(IAGAnimationContainer pContainer, object pObject)
        {
            string             objectName;
            IElementProperties elemProps = (IElementProperties)pObject;

            objectName = elemProps.Name;

            return(objectName);
        }
Beispiel #12
0
        public object get_AnimationObjectByID(IAGAnimationContainer pContainer, int objectID)
        {
            IArray array;

            array = get_ObjectArray(pContainer);
            IElement elem = (IElement)array.get_Element(objectID);

            return(elem);
        }
        private void UpdateGraphicObject(IElement elem, IAGAnimationContainer pContainer, IAGAnimationTrack pTrack, IPoint new_pos, double new_angle)
        {
            if (elem == null || new_pos == null)
            {
                return; //invalidate parameter
            }
            MoveElement(elem, new_pos, pContainer);
            RotateElement(elem, new_angle, pContainer);

            return;
        }
        public string get_AnimationObjectName(IAGAnimationContainer pContainer, object pObject)
        {
            ILayer layer = (ILayer)pObject;

            if (layer != null)
            {
                return(layer.Name);
            }
            else
            {
                return("");
            }
        }
Beispiel #15
0
        /// <summary>
        /// 书签创建关键帧
        /// </summary>
        /// <param name="_pGlobe"></param>
        /// <param name="_pBook3D"></param>
        /// <returns></returns>
        public static IAGKeyframe CreateKeyframefromBook(IGlobe _pGlobe, IBookmark3D _pBook3D)
        {
            IScene _pScene = _pGlobe.GlobeDisplay.Scene;

            IAGAnimationContainer pAGAnimationContainer = _pScene as IAGAnimationContainer;
            IAGAnimationTracks    pAGAnimationTracks    = _pGlobe as IAGAnimationTracks;
            IAGAnimationUtils     pAGAutils             = new AGAnimationUtilsClass();

            ESRI.ArcGIS.Animation.IAGAnimationType pAGType = new AnimationTypeGlobeCameraClass();
            IAGKeyframe pGlobeKey = new GlobeCameraKeyframeClass();

            pAGAutils.KeyframeFromBookmark(pAGAnimationContainer, _pBook3D as ISpatialBookmark, out pGlobeKey);

            return(pGlobeKey);
        }
Beispiel #16
0
        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 int get_AnimationObjectID(IAGAnimationContainer pContainer, object pObject)
        {
            IArray objectArray = get_ObjectArray(pContainer);
            int    objCount    = objectArray.Count;

            int i = 0;

            for (i = 0; i < objCount; i++)
            {
                if (pObject == objectArray.get_Element(i))
                {
                    break;
                }
            }
            return(i);
        }
        private IEnvelope GetElementBound(IElement elem, IAGAnimationContainer pContainer)
        {
            IActiveView view = pContainer.CurrentView as IActiveView;
            IGraphicsContainerSelect graphicsContainerSelect = view as IGraphicsContainerSelect;
            IDisplay disp = view.ScreenDisplay as IDisplay;

            IEnvelope elementEnvelope = new EnvelopeClass();

            elem.QueryBounds(disp, elementEnvelope);

            if (graphicsContainerSelect.ElementSelected(elem))
            {
                elementEnvelope = elem.SelectionTracker.get_Bounds(disp);
            }

            return(elementEnvelope);
        }
        public void Interpolate(IAGAnimationTrack pTrack, IAGAnimationContainer pContainer,
                                object pObject, int propertyIndex, double time, IAGKeyframe pNextKeyframe,
                                IAGKeyframe pPrevKeyframe, IAGKeyframe pAfterNextKeyframe)
        {
            if (time < TimeStamp || time > pNextKeyframe.TimeStamp)
            {
                return;
            }

            IElement elem    = (IElement)pObject;
            IPoint   new_pos = new PointClass();

            if (propertyIndex == 0)
            {
                double x1;
                double y1;
                IPoint nextPosition = (IPoint)pNextKeyframe.get_PropertyValue(0);

                double timeFactor;
                timeFactor = (time - TimeStamp) / (pNextKeyframe.TimeStamp - TimeStamp); //ignoring pPrevKeyframe and pAfterNextKeyframe

                x1 = Position.X * (1 - timeFactor) + nextPosition.X * timeFactor;
                y1 = Position.Y * (1 - timeFactor) + nextPosition.Y * timeFactor;

                new_pos.PutCoords(x1, y1);

                if (!(elem is ILineElement))
                {
                    MoveElement(elem, new_pos, pContainer);
                    TracePath(elem, new_pos, pContainer, pTrack, this);
                    bObjectsNeedRefresh = true;
                }
            }
            if (propertyIndex == 1)
            {
                //this property only applies to the point graphic
                if (!(elem is ILineElement))
                {
                    RotateElement(elem, Rotation, pContainer);
                    bObjectsNeedRefresh = true;
                }
            }

            return;
        }
Beispiel #20
0
        public int get_AnimationObjectID(IAGAnimationContainer pContainer, object pObject)
        {
            IArray array    = get_ObjectArray(pContainer);
            int    count    = array.Count;
            int    objectID = 0;

            for (int i = 0; i < count; i++)
            {
                IElement elem = (IElement)array.get_Element(i);
                if (elem == pObject)
                {
                    break;
                }
                objectID++;
            }

            return(objectID);
        }
        private void RefreshGraphicObject(IElement elem, IAGAnimationContainer pContainer)
        {
            IActiveView view    = pContainer.CurrentView as IActiveView;
            IEnvelope   elemEnv = GetElementBound(elem, pContainer);

            IEnvelope           oldEnv     = new EnvelopeClass();
            IElementProperties2 elemProps2 = (IElementProperties2)elem;

            oldEnv = (IEnvelope)elemProps2.CustomProperty;

            IViewRefresh animRefresh = (IViewRefresh)view;

            if (oldEnv != null)
            {
                elemEnv.Union(oldEnv);
            }

            animRefresh.AnimationRefresh(esriViewDrawPhase.esriViewGraphics, elem, elemEnv);
        }
        public IArray get_ObjectArray(IAGAnimationContainer pContainer)
        {
            IActiveView view  = pContainer.CurrentView as IActiveView;
            IArray      array = new ArrayClass();

            ILayer layer1;
            int    layerCount = view.FocusMap.LayerCount;
            int    i          = 0;

            for (i = 0; i < layerCount; i++)
            {
                layer1 = view.FocusMap.get_Layer(i);
                if (get_AppliesToObject(layer1))
                {
                    array.Add(layer1);
                }
            }

            return(array);
        }
Beispiel #23
0
        public IArray get_ObjectArray(IAGAnimationContainer pContainer)
        {
            IActiveView        view = pContainer.CurrentView as IActiveView;
            IGraphicsContainer graphicsContainer = view as IGraphicsContainer;

            graphicsContainer.Reset();

            IArray   array = new ArrayClass();
            IElement elem  = graphicsContainer.Next();

            while (elem != null)
            {
                if (get_AppliesToObject(elem))
                {
                    array.Add(elem);
                }
                elem = graphicsContainer.Next();
            }

            return(array);
        }
        private bool CheckGraphicExistance(IElement elem, IAGAnimationContainer animContainer)
        {
            IActiveView        view = animContainer.CurrentView as IActiveView;
            IGraphicsContainer graphicsContainer = view as IGraphicsContainer;

            graphicsContainer.Reset();

            bool     exists = false;
            IElement temp   = graphicsContainer.Next();

            while (temp != null)
            {
                if (temp == elem)
                {
                    exists = true;
                    break;
                }
                temp = graphicsContainer.Next();
            }
            return(exists);
        }
        public void Interpolate(IAGAnimationTrack pTrack, IAGAnimationContainer pContainer,
                                object pObject, int propertyIndex, double time, IAGKeyframe pNextKeyframe,
                                IAGKeyframe pPrevKeyframe, IAGKeyframe pAfterNextKeyframe)
        {
            if (time < TimeStamp || time > pNextKeyframe.TimeStamp)
            {
                return;
            }

            double timeFactor;

            timeFactor = (time - TimeStamp) / (pNextKeyframe.TimeStamp - TimeStamp); //ignoring pPrevKeyframe and pAfterNextKeyframe
            if (propertyIndex == 0)                                                  //interpolate brightness
            {
                short brightnessInterpolated;
                short brightnessStart;
                short brightnessEnd;
                brightnessStart        = brightness;
                brightnessEnd          = System.Convert.ToInt16(pNextKeyframe.get_PropertyValue(0));
                brightnessInterpolated = System.Convert.ToInt16(timeFactor * (brightnessEnd - brightnessStart) + brightnessStart);
                SetBrightness((ILayer)pObject, brightnessInterpolated);
                bObjectsNeedRefresh = true;
            }
            else //interpolate contrast
            {
                short contrastInterpolated;
                short contrastStart;
                short contrastEnd;
                contrastStart        = contrast;
                contrastEnd          = System.Convert.ToInt16(pNextKeyframe.get_PropertyValue(1));
                contrastInterpolated = System.Convert.ToInt16(timeFactor * (contrastEnd - contrastStart) + contrastStart);
                SetContrast((ILayer)pObject, contrastInterpolated);
                bObjectsNeedRefresh = true;
            }
            return;
        }
        private void TracePath(IElement elem, IPoint new_pos, IAGAnimationContainer pContainer, IAGAnimationTrack pTrack, IAGKeyframe pKeyframe)
        {
            IAGAnimationTrackExtensions trackExtensions = (IAGAnimationTrackExtensions)(pTrack);
            IMapGraphicTrackExtension   graphicTrackExtension;

            if (trackExtensions.ExtensionCount == 0) //if there is no extension, add one
            {
                graphicTrackExtension = new MapGraphicTrackExtension();
                trackExtensions.AddExtension(graphicTrackExtension);
            }
            else
            {
                graphicTrackExtension = (IMapGraphicTrackExtension)trackExtensions.get_Extension(0);
            }

            ILineElement path = graphicTrackExtension.TraceElement;

            bool showTrace = graphicTrackExtension.ShowTrace;

            if (!showTrace)
            {
                if (CheckGraphicExistance((IElement)path, pContainer))
                {
                    RemoveGraphicFromDisplay((IElement)path, pContainer);
                }
                return;
            }

            //Add the path to the graphic container
            if (!CheckGraphicExistance((IElement)path, pContainer))
            {
                AddGraphicToDisplay((IElement)path, pContainer);
            }

            RecreateLineGeometry((IElement)path, pTrack, pKeyframe, new_pos);
        }
        public IArray get_ObjectArray(IAGAnimationContainer pContainer)
        {
            IActiveView view = pContainer.CurrentView as IActiveView;
            IArray array = new ArrayClass();

            ILayer layer1;
            int layerCount = view.FocusMap.LayerCount;
            int i = 0;
            for (i = 0; i < layerCount; i++)
            {
                layer1 = view.FocusMap.get_Layer(i);
                if (get_AppliesToObject(layer1))
                {
                    array.Add(layer1);
                }
            }

            return array;
        }
 public void CaptureProperties(IAGAnimationContainer pContainer, object pObject)
 {
     contrast   = GetContrast((ILayer)pObject);
     brightness = GetBrightness((ILayer)pObject);
 }
 public void RefreshObject(IAGAnimationTrack pTrack,
                           IAGAnimationContainer pContainer, object pObject)
 {
     bObjectsNeedRefresh = false;
     pContainer.RefreshObject(pObject);
 }
 private void AddGraphicToDisplay(IElement elem, IAGAnimationContainer animContainer)
 {
     IActiveView view = animContainer.CurrentView as IActiveView;
     IGraphicsContainer graphicsContainer = view as IGraphicsContainer;
     graphicsContainer.AddElement(elem, 0);            
     elem.Activate(view.ScreenDisplay);
 }
 private void RemoveGraphicFromDisplay(IElement elem, IAGAnimationContainer animContainer)
 {
     IActiveView view = animContainer.CurrentView as IActiveView;
     IGraphicsContainer graphicsContainer = view as IGraphicsContainer;
     graphicsContainer.DeleteElement(elem);
 }
        private void MoveElement(IElement elem, IPoint new_pos, IAGAnimationContainer pContainer)
        {
            ITransform2D transform2D = elem as ITransform2D;
            IPoint origin;

            if (elem.Geometry.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                origin = elem.Geometry as IPoint;
            }
            else
            {
                IEnvelope elementEnvelope = elem.Geometry.Envelope;
                IArea elementArea = elementEnvelope as IArea;
                origin = elementArea.Centroid;
            }

            AddPropertySet(elem);

            IElementProperties prop = (IElementProperties)elem; //record the old properties
            IPropertySet propSet;
            propSet = (IPropertySet)prop.CustomProperty;
            IEnvelope oldEnv = GetElementBound(elem, pContainer);
            propSet.SetProperty("Envelope", oldEnv);

            transform2D.Move(new_pos.X - origin.X, new_pos.Y - origin.Y);
        }
 public void ResetObject(IAGAnimationContainer pContainer, object pObject)
 {
     return;
 }
 public void CaptureProperties(IAGAnimationContainer pContainer, object pObject)
 {
     contrast = GetContrast((ILayer)pObject);
     brightness = GetBrightness((ILayer)pObject);
 }
        public void Interpolate(IAGAnimationTrack pTrack, IAGAnimationContainer pContainer,
            object pObject, int propertyIndex, double time, IAGKeyframe pNextKeyframe,
            IAGKeyframe pPrevKeyframe, IAGKeyframe pAfterNextKeyframe)
        {
            if (time < TimeStamp || time > pNextKeyframe.TimeStamp)
                return;

            double timeFactor;
            timeFactor = (time - TimeStamp) / (pNextKeyframe.TimeStamp - TimeStamp); //ignoring pPrevKeyframe and pAfterNextKeyframe
            if (propertyIndex == 0) //interpolate brightness
            {
                short brightnessInterpolated;
                short brightnessStart;
                short brightnessEnd;
                brightnessStart = brightness;
                brightnessEnd = System.Convert.ToInt16(pNextKeyframe.get_PropertyValue(0));
                brightnessInterpolated = System.Convert.ToInt16(timeFactor * (brightnessEnd - brightnessStart) + brightnessStart);
                SetBrightness((ILayer)pObject, brightnessInterpolated);
                bObjectsNeedRefresh = true;
            }
            else //interpolate contrast
            {
                short contrastInterpolated;
                short contrastStart;
                short contrastEnd;
                contrastStart = contrast;
                contrastEnd = System.Convert.ToInt16(pNextKeyframe.get_PropertyValue(1));
                contrastInterpolated = System.Convert.ToInt16(timeFactor * (contrastEnd - contrastStart) + contrastStart);
                SetContrast((ILayer)pObject, contrastInterpolated);
                bObjectsNeedRefresh = true;
            }
            return;
        }
 public object get_AnimationObjectByID(IAGAnimationContainer pContainer, int objectID)
 {
     IArray objectArray = get_ObjectArray(pContainer);
     return (object)objectArray.get_Element(objectID);
 }
        public int get_AnimationObjectID(IAGAnimationContainer pContainer, object pObject)
        {
            IArray objectArray = get_ObjectArray(pContainer);
            int objCount = objectArray.Count;

            int i = 0;
            for (i = 0; i < objCount; i++)
            {
                if (pObject == objectArray.get_Element(i))
                    break;
            }
            return i;
        }
 public string get_AnimationObjectName(IAGAnimationContainer pContainer, object pObject)
 {
     ILayer layer = (ILayer)pObject;
     if (layer != null)
     {
         return layer.Name;
     }
     else
         return "";
 }
 public void RefreshObject(IAGAnimationTrack pTrack,
     IAGAnimationContainer pContainer, object pObject)
 {         
     RefreshGraphicObject((IElement)pObject, pContainer);
 }
Beispiel #40
0
        ///<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);
            }
        }
        public string get_AnimationObjectName(IAGAnimationContainer pContainer, object pObject)
        {
            string objectName;
            IElementProperties elemProps = (IElementProperties)pObject;
            objectName = elemProps.Name;

            return objectName;
        }
        public IArray get_ObjectArray(IAGAnimationContainer pContainer)
        {
            IActiveView view = pContainer.CurrentView as IActiveView;
            IGraphicsContainer graphicsContainer = view as IGraphicsContainer;
            graphicsContainer.Reset();

            IArray array = new ArrayClass();
            IElement elem = graphicsContainer.Next();

            while (elem != null)
            {
                if(get_AppliesToObject(elem))
                    array.Add(elem);
                elem = graphicsContainer.Next();
            }

            return array;
        }
 public void RefreshObject(IAGAnimationTrack pTrack,
     IAGAnimationContainer pContainer, object pObject)
 {
     bObjectsNeedRefresh = false;
     pContainer.RefreshObject(pObject);
 }
        private IEnvelope GetElementBound(IElement elem, IAGAnimationContainer pContainer)
        {
            IActiveView view = pContainer.CurrentView as IActiveView;
            IGraphicsContainerSelect graphicsContainerSelect = view as IGraphicsContainerSelect;
            IDisplay disp = view.ScreenDisplay as IDisplay;
            
            IEnvelope elementEnvelope = new EnvelopeClass();
            elem.QueryBounds(disp, elementEnvelope);

            if (graphicsContainerSelect.ElementSelected(elem))
            {
                elementEnvelope = elem.SelectionTracker.get_Bounds(disp);
            }

            return elementEnvelope;
        }
        public void CaptureProperties(IAGAnimationContainer pContainer, object pObject)
        {
            IElement elem = pObject as IElement;
            IActiveView view = pContainer.CurrentView as IActiveView;
            IGraphicsContainerSelect graphicsConSel = view as IGraphicsContainerSelect;
            IDisplay disp = view.ScreenDisplay as IDisplay;
            IEnvelope elemEnv = GetElementBound(elem,pContainer);

            if (elem.Geometry.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                Position = elem.Geometry as IPoint;
            }
            else
            {
                IEnvelope elementEnvelope = elem.Geometry.Envelope;
                IArea elementArea = elementEnvelope as IArea;
                Position = elementArea.Centroid;
            }

            IElementProperties elemProps = (IElementProperties)elem;
            if(elemProps.CustomProperty!=null)
                Rotation = (double)elemProps.CustomProperty;
        }
        private bool CheckGraphicExistance(IElement elem, IAGAnimationContainer animContainer)
        {
            IActiveView view = animContainer.CurrentView as IActiveView;
            IGraphicsContainer graphicsContainer = view as IGraphicsContainer;
            graphicsContainer.Reset();

            bool exists = false;
            IElement temp = graphicsContainer.Next();
            while (temp != null)
            {
                if (temp == elem)
                {
                    exists = true;
                    break;
                }
                temp = graphicsContainer.Next();
            }
            return exists;
        }
        private void RefreshGraphicObject(IElement elem, IAGAnimationContainer pContainer)
        {
            IActiveView view = pContainer.CurrentView as IActiveView;
            IEnvelope elemEnv = GetElementBound(elem, pContainer);

            IEnvelope oldEnv = new EnvelopeClass();
            IElementProperties2 elemProps2 = (IElementProperties2) elem;
            oldEnv = (IEnvelope) elemProps2.CustomProperty;

            IViewRefresh animRefresh = (IViewRefresh)view;

            if (oldEnv != null)
            {
                elemEnv.Union(oldEnv);
            }

            animRefresh.AnimationRefresh(esriViewDrawPhase.esriViewGraphics, elem, elemEnv);
        }
Beispiel #48
0
 public void ResetObject(IAGAnimationContainer pContainer, object pObject)
 {
     return;
 }
        public static void CreateMapGraphicTrack(ICreateGraphicTrackOptions pOptions, IAGAnimationTracks tracks, IAGAnimationContainer pContainer)
        {
            pOptions.PathGeometry=SimplifyPath2D(pOptions.PathGeometry,pOptions.ReverseOrder,pOptions.SimplificationFactor);
            IAGAnimationType animType = new AnimationTypeMapGraphic();

            //remove tracks with the same name if overwrite is true
            if (pOptions.OverwriteTrack == true)
            {
                IArray trackArray = new ArrayClass();
                trackArray = tracks.get_TracksOfType(animType);
                int count = trackArray.Count;
                for (int i = 0; i < count; i++)
                {
                    IAGAnimationTrack temp = (IAGAnimationTrack)trackArray.get_Element(i);
                    if (temp.Name == pOptions.TrackName)
                        tracks.RemoveTrack(temp);
                }
            }

            //create the new track
            IAGAnimationTrack animTrack = tracks.CreateTrack(animType);
            IAGAnimationTrackKeyframes animTrackKeyframes = (IAGAnimationTrackKeyframes)animTrack;
            animTrackKeyframes.EvenTimeStamps = false;

            animTrack.Name = pOptions.TrackName;

            IGeometry path = pOptions.PathGeometry;
            IPointCollection pointCollection = (IPointCollection)path;

            ICurve curve = (ICurve)path;
            double length = curve.Length;
            double accuLength = 0;

            //loop through all points to create the keyframes
            int pointCount = pointCollection.PointCount;
            if (pointCount <= 1)
                return;
            for (int i = 0; i < pointCount; i++)
            {
                IPoint currentPoint = pointCollection.get_Point(i);
                
                IPoint nextPoint = new PointClass();
                if (i < pointCount-1)
                    nextPoint = pointCollection.get_Point(i + 1);
                
                IPoint lastPoint = new PointClass();
                if (i == 0)
                    lastPoint = currentPoint;
                else
                    lastPoint = pointCollection.get_Point(i-1);

                IAGKeyframe tempKeyframe = animTrackKeyframes.CreateKeyframe(i);
                
                //set keyframe properties
                double x;
                double y;
                currentPoint.QueryCoords(out x, out y);
                tempKeyframe.set_PropertyValue(0, currentPoint);
                tempKeyframe.Name = "Map Graphic keyframe " + i.ToString();
                
                //set keyframe timestamp
                accuLength += CalculateDistance(lastPoint, currentPoint);
                double timeStamp = accuLength / length;
                tempKeyframe.TimeStamp = timeStamp;

                double x1;
                double y1;
                double angle;
                if (i < pointCount - 1)
                {
                    nextPoint.QueryCoords(out x1, out y1);
                    if ((y1 - y) > 0)
                        angle = Math.Acos((x1 - x) / Math.Sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)));
                    else
                    {
                        angle = 6.2832 - Math.Acos((x1 - x) / Math.Sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)));
                    }
                    tempKeyframe.set_PropertyValue(1, angle);
                }
                else
                { 
                    IAGKeyframe lastKeyframe = animTrackKeyframes.get_Keyframe(i-1);
                    tempKeyframe.set_PropertyValue(1, lastKeyframe.get_PropertyValue(1));
                }
            }

            //attach the point element
            if(pOptions.PointElement != null)
                animTrack.AttachObject(pOptions.PointElement);

            //attach the track extension, which contains a line element for trace
            IMapGraphicTrackExtension graphicTrackExtension = new MapGraphicTrackExtension();
            graphicTrackExtension.ShowTrace = pOptions.AnimatePath;
            IAGAnimationTrackExtensions trackExtensions = (IAGAnimationTrackExtensions)animTrack;
            trackExtensions.AddExtension(graphicTrackExtension);            
        }
        private void TracePath(IElement elem, IPoint new_pos, IAGAnimationContainer pContainer, IAGAnimationTrack pTrack, IAGKeyframe pKeyframe)
        {
            IAGAnimationTrackExtensions trackExtensions = (IAGAnimationTrackExtensions)(pTrack);
            IMapGraphicTrackExtension graphicTrackExtension;
            if (trackExtensions.ExtensionCount == 0) //if there is no extension, add one
            {
                graphicTrackExtension = new MapGraphicTrackExtension();
                trackExtensions.AddExtension(graphicTrackExtension);
            }
            else
            {
                graphicTrackExtension = (IMapGraphicTrackExtension)trackExtensions.get_Extension(0);
            }

            ILineElement path = graphicTrackExtension.TraceElement;

            bool showTrace = graphicTrackExtension.ShowTrace;
            if (!showTrace)
            {
                if (CheckGraphicExistance((IElement)path, pContainer))
                {
                    RemoveGraphicFromDisplay((IElement)path, pContainer);
                }
                return;
            }

            //Add the path to the graphic container
            if (!CheckGraphicExistance((IElement)path, pContainer))
            {
                AddGraphicToDisplay((IElement)path, pContainer);
            }

            RecreateLineGeometry((IElement)path, pTrack, pKeyframe, new_pos);
        }
        private void UpdateGraphicObject(IElement elem, IAGAnimationContainer pContainer, IAGAnimationTrack pTrack, IPoint new_pos, double new_angle)
        {
            if (elem == null||new_pos==null)
                return; //invalidate parameter

            MoveElement(elem, new_pos, pContainer);
            RotateElement(elem, new_angle, pContainer);

            return;
        }
        private void RotateElement(IElement elem, double new_angle, IAGAnimationContainer pContainer)
        {
            ITransform2D transform2D = elem as ITransform2D;
            IPoint rotateOrigin;

            if (elem.Geometry.GeometryType == esriGeometryType.esriGeometryPoint)
            {
                rotateOrigin = elem.Geometry as IPoint;
            }
            else
            {
                IEnvelope elementEnvelope = elem.Geometry.Envelope;
                IArea elementArea = elementEnvelope as IArea;
                rotateOrigin = elementArea.Centroid;
            }

            AddPropertySet(elem);

            IElementProperties prop = (IElementProperties)elem; //record the old properties
            IPropertySet propSet;
            propSet = (IPropertySet)prop.CustomProperty;
            double old_angle;
            old_angle = (double)propSet.GetProperty("Angle");

            propSet.SetProperty("Angle", new_angle); //update old angle

            transform2D.Rotate(rotateOrigin, new_angle-old_angle);
        }
        public object get_AnimationObjectByID(IAGAnimationContainer pContainer, int objectID)
        {
            IArray array;
            array = get_ObjectArray(pContainer);
            IElement elem = (IElement)array.get_Element(objectID);

            return elem;
        }
        public int get_AnimationObjectID(IAGAnimationContainer pContainer, object pObject)
        {
            IArray array = get_ObjectArray(pContainer);
            int count = array.Count;
            int objectID = 0;
            for (int i = 0; i < count; i++)
            {
                IElement elem = (IElement)array.get_Element(i);
                if (elem == pObject)
                    break;
                objectID++;
            }

            return objectID;
        }
 public void RefreshObject(IAGAnimationTrack pTrack,
                           IAGAnimationContainer pContainer, object pObject)
 {
     RefreshGraphicObject((IElement)pObject, pContainer);
 }
Beispiel #56
0
        //function for creating specified number of graphics between keyframe positions
        public void generatePathBtwnKFrames()
        {
            int numPtsBtwnKFrames = 0;

            //this is the from point for the lines connecting the interpolated point graphics
            IPoint  previousPt   = new PointClass();
            IZAware prevPtZAware = (IZAware)previousPt;

            prevPtZAware.ZAware = true;
            previousPt.PutCoords(0, 0);

            //this is the line connecting the interpolated camera positions
            IPolyline connectingLine = new PolylineClass();
            IZAware   lineZAware     = (IZAware)connectingLine;

            lineZAware.ZAware = true;

            if (theCamForm.ptsBtwnKframeTextBox.Text != "")
            {
                numPtsBtwnKFrames = Convert.ToInt32(theCamForm.ptsBtwnKframeTextBox.Text);
            }
            else
            {
                MessageBox.Show("Please enter the number of points to be created");
                return;
            }
            theCamForm.playButton.Enabled         = false;
            theCamForm.stopButton.Enabled         = false;
            theCamForm.generatePathButton.Enabled = false;

            addGraphicLayer();

            string selectedTrack = theCamForm.animTracksListBox.SelectedItem.ToString();

            animationTracks.FindTrack(selectedTrack, out animationTrack);

            IAGAnimationTrackKeyframes kFrames = (IAGAnimationTrackKeyframes)animationTrack;

            int kFrameCount = kFrames.KeyframeCount;

            //loop over the keyframes in the selected camera track
            for (int i = 0; i < kFrameCount; i++)
            {
                IAGKeyframe currentKeyframe = kFrames.get_Keyframe(i);
                IAGKeyframe prevKeyframe;
                IAGKeyframe nextKeyframe;
                IAGKeyframe afterNextKeyframe;

                //if else statements to determine the keyframe arguments to the interpolate method
                //this is needed because the first and the last keyframes should be handled differently
                //than the middle keyframes
                if (i > 0)
                {
                    prevKeyframe = kFrames.get_Keyframe(i - 1);
                }

                else
                {
                    prevKeyframe = kFrames.get_Keyframe(i);
                }

                if (i < kFrameCount - 1)
                {
                    nextKeyframe = kFrames.get_Keyframe(i + 1);
                }
                else
                {
                    nextKeyframe = kFrames.get_Keyframe(i);
                }

                if (i < kFrameCount - 2)
                {
                    afterNextKeyframe = kFrames.get_Keyframe(i + 2);
                }
                else
                {
                    //this should be equal to the nextKeyFrame for the last keyframe
                    afterNextKeyframe = nextKeyframe;//kFrames.get_Keyframe(i);
                }

                double origCamLat, origCamLong, origCamAlt;
                double interLat, interLong, interAlt;
                double tarLat, tarLong, tarAlt;
                double interTarLat, interTarLong, interTarAlt;

                globeCamera.GetObserverLatLonAlt(out origCamLat, out origCamLong, out origCamAlt);
                globeCamera.GetTargetLatLonAlt(out tarLat, out tarLong, out tarAlt);


                IAGAnimationContainer pAnimContainer = animationTracks.AnimationObjectContainer;

                object objToInterpolate = (object)globeCamera;

                double timeDiff = nextKeyframe.TimeStamp - currentKeyframe.TimeStamp;

                //interpolate positions between keyframes and draw the graphics
                for (int j = 0; j < numPtsBtwnKFrames + 1; j++)
                {
                    double timeToInterpolate = currentKeyframe.TimeStamp + j * (timeDiff / (numPtsBtwnKFrames + 1));

                    //for 0 to n-1 keyframes
                    if (i >= 0 & i < kFrameCount - 1)
                    {
                        currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 4, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe);
                        currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 5, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe);
                        currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 6, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe);
                        currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 1, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe);
                        currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 2, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe);
                        currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 3, timeToInterpolate, nextKeyframe, prevKeyframe, afterNextKeyframe);

                        globeCamera.GetObserverLatLonAlt(out interLat, out interLong, out interAlt);
                        globeCamera.GetTargetLatLonAlt(out interTarLat, out interTarLong, out interTarAlt);

                        globeCamera.SetObserverLatLonAlt(origCamLat, origCamLong, origCamAlt);
                        globeCamera.SetTargetLatLonAlt(tarLat, tarLong, tarAlt);

                        IPoint  pObs      = new PointClass();
                        IZAware obsZAware = (IZAware)pObs;
                        obsZAware.ZAware = true;
                        pObs.X           = interLong;
                        pObs.Y           = interLat;
                        pObs.Z           = interAlt * 1000;

                        double symbolSize = 10000;

                        if (pObs.Z >= 10000)
                        {
                            symbolSize = 10000 + pObs.Z / 10;
                        }
                        else
                        {
                            symbolSize = pObs.Z;
                        }

                        if (j == 0)
                        {
                            addPointGraphicElements(pObs, 2552550, symbolSize);
                        }
                        else
                        {
                            addPointGraphicElements(pObs, 16732415, symbolSize);
                        }

                        connectingLine.FromPoint = previousPt;
                        connectingLine.ToPoint   = pObs;

                        if (i == 0 & j == 0)
                        {
                        }
                        else
                        {
                            addLineGraphicElements(connectingLine, 150150150);
                        }

                        previousPt.PutCoords(pObs.X, pObs.Y);
                        previousPt.Z = pObs.Z;

                        //add camera to target orientation
                        if (theCamForm.camToTargetDirectionCheckBox.Checked == true)
                        {
                            cameraToTargetDirection(interLat, interLong, interAlt, interTarLat, interTarLong, interTarAlt);
                        }

                        globeDisplay.RefreshViewers();
                    }

                    //for last keyframe
                    else if (i == kFrameCount - 1)
                    {
                        if (j == 0)
                        {
                            currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 4, 1, nextKeyframe, prevKeyframe, afterNextKeyframe);
                            currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 5, 1, nextKeyframe, prevKeyframe, afterNextKeyframe);
                            currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 6, 1, nextKeyframe, prevKeyframe, afterNextKeyframe);
                            currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 1, 1, nextKeyframe, prevKeyframe, afterNextKeyframe);
                            currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 2, 1, nextKeyframe, prevKeyframe, afterNextKeyframe);
                            currentKeyframe.Interpolate(animationTrack, pAnimContainer, objToInterpolate, 3, 1, nextKeyframe, prevKeyframe, afterNextKeyframe);

                            globeCamera.GetObserverLatLonAlt(out interLat, out interLong, out interAlt);
                            globeCamera.GetTargetLatLonAlt(out interTarLat, out interTarLong, out interTarAlt);

                            globeCamera.SetObserverLatLonAlt(origCamLat, origCamLong, origCamAlt);
                            globeCamera.SetTargetLatLonAlt(tarLat, tarLong, tarAlt);

                            IPoint  pObs      = new PointClass();
                            IZAware obsZAware = (IZAware)pObs;
                            obsZAware.ZAware = true;
                            pObs.X           = interLong;
                            pObs.Y           = interLat;
                            pObs.Z           = interAlt * 1000;

                            double symbolSize = 10000;

                            if (pObs.Z >= 10000)
                            {
                                symbolSize = 10000 + pObs.Z / 10;
                            }
                            else
                            {
                                symbolSize = pObs.Z;
                            }

                            connectingLine.FromPoint = previousPt;
                            connectingLine.ToPoint   = pObs;

                            addPointGraphicElements(pObs, 2552550, symbolSize);
                            addLineGraphicElements(connectingLine, 150150150);

                            //add camera to target orientation
                            if (theCamForm.camToTargetDirectionCheckBox.Checked == true)
                            {
                                cameraToTargetDirection(interLat, interLong, interAlt, interTarLat, interTarLong, interTarAlt);
                            }

                            globeDisplay.RefreshViewers();
                        }
                    }
                }
            }

            //enable buttons
            theCamForm.playButton.Enabled         = true;
            theCamForm.generatePathButton.Enabled = true;
        }
        public void Interpolate(IAGAnimationTrack pTrack, IAGAnimationContainer pContainer,
            object pObject, int propertyIndex, double time, IAGKeyframe pNextKeyframe,
            IAGKeyframe pPrevKeyframe, IAGKeyframe pAfterNextKeyframe)
        {
            if (time < TimeStamp || time > pNextKeyframe.TimeStamp)
                return;

            IElement elem = (IElement)pObject;
            IPoint new_pos = new PointClass();
           
            if (propertyIndex == 0)
            {
                double x1;
                double y1;
                IPoint nextPosition = (IPoint)pNextKeyframe.get_PropertyValue(0);

                double timeFactor;
                timeFactor = (time - TimeStamp) / (pNextKeyframe.TimeStamp - TimeStamp); //ignoring pPrevKeyframe and pAfterNextKeyframe

                x1 = Position.X * (1 - timeFactor) + nextPosition.X * timeFactor;
                y1 = Position.Y * (1 - timeFactor) + nextPosition.Y * timeFactor;
                
                new_pos.PutCoords(x1, y1);

                if (!(elem is ILineElement))
                {
                    MoveElement(elem, new_pos, pContainer);
                    TracePath(elem, new_pos, pContainer, pTrack, this);
                    bObjectsNeedRefresh = true;
                }
            }
            if (propertyIndex == 1)
            {
                //this property only applies to the point graphic 
                if (!(elem is ILineElement))
                {
                    RotateElement(elem, Rotation, pContainer);
                    bObjectsNeedRefresh = true;
                }
            }

            return;
        }