using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Display;
namespace AE03_13
{
    public partial class Form1 : Form
    {
        //Ա
        IPointCollection pPointCollection;//㼯
        IMarkerElement pMarkerElement = new MarkerElementClass();
        IElement pElement;
        IGraphicsContainer pGraphicsContainer;
        int i=0;//
        int j = 0;
        IPoint pPoint;//˶ĵ

        public Form1()
        {
            InitializeComponent();
        }
        //ȡϵĵ
        public IGeometryCollection makeLinePoint(IGeometry geometry,int pointnum)
        {
            IGeometryCollection pGeometryCollection;
            if (geometry is IPolyline)
            {
                //ϵĵļ
                IConstructGeometryCollection pConstructGeometryCollection = new GeometryBagClass();
                pConstructGeometryCollection.ConstructDivideEqual(geometry as IPolyline, pointnum, esriConstructDivideEnum.esriDivideIntoPolylines);//ȷ
                IEnumGeometry pEnumGeometry = pConstructGeometryCollection as IEnumGeometry;//Ҫö
                pGeometryCollection = new MultipointClass();//㼯
                IPolyline pPolyline1 = pEnumGeometry.Next() as IPolyline;
                object o = Type.Missing;
                pGeometryCollection.AddGeometry(pPolyline1.FromPoint, ref o, ref o);

                while (pPolyline1 != null)
                {
                    pGeometryCollection.AddGeometry(pPolyline1.ToPoint, ref o, ref o);
                    pPolyline1 = pEnumGeometry.Next() as IPolyline;
                }
                return pGeometryCollection;

            }
            else
            {
                return null;
            }
        }
        //ɫ
        public IRgbColor getRGB(int r, int g, int b, byte t)
        {
            IRgbColor pRgbColor = new RgbColorClass();
            pRgbColor.Red = r;
            pRgbColor.Green = g;
            pRgbColor.Blue = b;
            pRgbColor.Transparency = t;//͸
            return pRgbColor;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass();
            pSimpleMarkerSymbol.Color = getRGB(25,220,220,1);
            pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;
            pSimpleMarkerSymbol.Size = 15;
            pMarkerElement.Symbol = pSimpleMarkerSymbol;
            pElement = pMarkerElement as IElement;

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if(i>pPointCollection.PointCount-1)
            {
                i = 0;//״̬Ϊʼ
            }
            j = i;
            pPoint = pPointCollection.get_Point(j);
            pElement.Geometry = pPoint;
            i++;
            pGraphicsContainer.AddElement(pElement,0);
            axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics,null,null);
        }

        private void ʼToolStripMenuItem_Click(object sender, EventArgs e)
        {
            pGraphicsContainer = axMapControl1.ActiveView.GraphicsContainer;
            IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;//õǰͼ
            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;//Ҫؼ
            IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
            IFeature pFeature = pFeatureCursor.NextFeature();
            IPolyline pPolyline = pFeature.Shape as IPolyline;
            pPointCollection = makeLinePoint(pPolyline as IGeometry, 10) as IPointCollection;
            timer1.Enabled = true;
            timer1.Interval = 500;
        }

        private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            timer1.Interval = 0;
        }
    }
}
