Inheritance: IMapGraphicTrackExtension, IPersistStream
        public void Apply()
        {
            IAGAnimationTrackExtensions trackExtensions = (IAGAnimationTrackExtensions)targetTrack;
            IMapGraphicTrackExtension   trackExtension;

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

            trackExtension.ShowTrace = propPage.CheckBoxShowTrace.Checked;
        }
        public void Init(IAGAnimationTrack track)
        {
            targetTrack = track;

            IAGAnimationTrackExtensions trackExtensions = (IAGAnimationTrackExtensions)targetTrack;
            IMapGraphicTrackExtension trackExtension;
            if (trackExtensions.ExtensionCount == 0) //if there is no extension, add one
            {
                trackExtension = new MapGraphicTrackExtension();
                trackExtensions.AddExtension(trackExtension);
            }
            else
            {
                trackExtension = (IMapGraphicTrackExtension)trackExtensions.get_Extension(0);
            }
            this.checkBoxTrace.Checked = trackExtension.ShowTrace;
        }
        public void Init(IAGAnimationTrack track)
        {
            targetTrack = track;

            IAGAnimationTrackExtensions trackExtensions = (IAGAnimationTrackExtensions)targetTrack;
            IMapGraphicTrackExtension   trackExtension;

            if (trackExtensions.ExtensionCount == 0) //if there is no extension, add one
            {
                trackExtension = new MapGraphicTrackExtension();
                trackExtensions.AddExtension(trackExtension);
            }
            else
            {
                trackExtension = (IMapGraphicTrackExtension)trackExtensions.get_Extension(0);
            }
            this.checkBoxTrace.Checked = trackExtension.ShowTrace;
        }
        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 void Apply()
        {
            IAGAnimationTrackExtensions trackExtensions = (IAGAnimationTrackExtensions)targetTrack;
            IMapGraphicTrackExtension trackExtension;
            if (trackExtensions.ExtensionCount == 0) //if there is no extension, add one
            {
                trackExtension = new MapGraphicTrackExtension();
                trackExtensions.AddExtension(trackExtension);
            }
            else
            {
                trackExtension = (IMapGraphicTrackExtension)trackExtensions.get_Extension(0);
            }

            trackExtension.ShowTrace = propPage.CheckBoxShowTrace.Checked;
        }
        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);
        }
        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);
        }