private void RecreateLineGeometry(IElement elem, IAGAnimationTrack pTrack, IAGKeyframe pKeyframe, IPoint new_pos)
        {
            IGeometry        newGeometry = new PolylineClass();
            IPointCollection newPointCol = (IPointCollection)newGeometry;

            IAGAnimationTrackKeyframes trackKeyframes = (IAGAnimationTrackKeyframes)pTrack;
            int    tCount  = trackKeyframes.KeyframeCount;
            object missing = Type.Missing;

            for (int i = 0; i < tCount; i++)
            {
                IAGKeyframe tempKeyframe = trackKeyframes.get_Keyframe(i);
                newPointCol.AddPoint((IPoint)tempKeyframe.get_PropertyValue(0), ref missing, ref missing);
                if ((IPoint)tempKeyframe.get_PropertyValue(0) == (IPoint)pKeyframe.get_PropertyValue(0))
                {
                    break;
                }
            }
            if (new_pos != null)
            {
                newPointCol.AddPoint(new_pos, ref missing, ref missing);
            }

            elem.Geometry = newGeometry;
        }
        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 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;
        }
        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 RecreateLineGeometry(IElement elem, IAGAnimationTrack pTrack, IAGKeyframe pKeyframe, IPoint new_pos)
        {
            IGeometry newGeometry = new PolylineClass();
            IPointCollection newPointCol = (IPointCollection)newGeometry;

            IAGAnimationTrackKeyframes trackKeyframes = (IAGAnimationTrackKeyframes)pTrack;
            int tCount = trackKeyframes.KeyframeCount;
            object missing = Type.Missing;
            for (int i = 0; i < tCount; i++)
            {
                IAGKeyframe tempKeyframe = trackKeyframes.get_Keyframe(i);
                newPointCol.AddPoint((IPoint)tempKeyframe.get_PropertyValue(0), ref missing, ref missing);
                if ((IPoint)tempKeyframe.get_PropertyValue(0) == (IPoint)pKeyframe.get_PropertyValue(0))
                    break;
            }
            if (new_pos != null)
                newPointCol.AddPoint(new_pos, ref missing, ref missing);

            elem.Geometry = newGeometry;
        }
        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;
        }
        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);
        }