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 frmCreateGraphicTrackOptions_Load(object sender, EventArgs e)
        {
            IAGAnimationTracks tracks = AnimationExtension.AnimationTracks;
            int    i = 1;
            string recommendedTrackName = "Map Graphic track " + i;

            while (CheckTrackName(tracks, recommendedTrackName))
            {
                i++;
                recommendedTrackName = "Map Graphic track " + i;
            }
            this.textBoxTrackName.Text          = recommendedTrackName;
            this.checkBoxOverwriteTrack.Checked = false;
            this.checkBoxReverseOrder.Checked   = false;
            this.checkBoxTracePath.Checked      = false;
            this.trackBar1.Minimum = 0;
            this.trackBar1.Maximum = 100;

            RefreshPathSourceOptions();

            helpProvider1.SetHelpString(this.radioButtonLineFeature, "Use a selected line feature as the path source.");
            helpProvider1.SetHelpString(this.radioButtonLineGraphic, "Use a selected line graphic as the path source.");
            helpProvider1.SetHelpString(this.checkBoxOverwriteTrack, "Check to overwrite existing tracks that have the same name as specified.");
            helpProvider1.SetHelpString(this.checkBoxReverseOrder, "Check to create a track that moves the graphic in a reversed direction.");
            helpProvider1.SetHelpString(this.checkBoxTracePath, "Check to show the trace of the moving point graphic in the animation. By default, the trace will be shown as a red dashed line following the path of the point graphic. The symbology of the trace can be changed in the display window after you play or preview the animation once.");
            helpProvider1.SetHelpString(this.trackBar1, "With a non-zero simplification factor, the line will be simplified and smoother.");
            helpProvider1.SetHelpString(this.textBoxTrackName, "Type a name for the track.");
        }
Esempio n. 3
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);
        }
        //The following function check if a track name exists
        private bool CheckTrackName(IAGAnimationTracks pTracks, string name)
        {
            IArray            trackArray = pTracks.AGTracks;
            IAGAnimationTrack pTrack;
            int  count      = pTracks.TrackCount;
            bool trackExist = false;

            for (int i = 0; i < count; i++)
            {
                pTrack = (IAGAnimationTrack)trackArray.get_Element(i);
                if (name == pTrack.Name)
                {
                    trackExist = true;
                    break;
                }
            }
            return(trackExist);
        }
        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);            
        }
 //The following function check if a track name exists
 private bool CheckTrackName(IAGAnimationTracks pTracks, string name)
 {
     IArray trackArray = pTracks.AGTracks;
     IAGAnimationTrack pTrack;
     int count = pTracks.TrackCount;
     bool trackExist = false;
     for (int i = 0; i < count; i++)
     {
         pTrack = (IAGAnimationTrack)trackArray.get_Element(i);
         if (name == pTrack.Name)
         {
             trackExist = true;
             break;
         }
     }
     return trackExist;
 }
        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);
        }