Ejemplo n.º 1
0
        private void mapMain_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //left click - fill array of coordinates
                Coordinate coord = mapMain.PixelToProj(e.Location);

                if (polygonmouseClick == true)
                {
                    if (firstClick == true)
                    {
                        //Creat a list to contain the polygon coordinates
                        List <Coordinate> polygonArray = new List <Coordinate>();

                        //Create an instance for LinearRing class.
                        //We pass the polygon List to the constructor of this class
                        LinearRing polygonGeometry = new LinearRing(polygonArray);

                        //add polygonGeomety instance to polygonFeature
                        IFeature polygonFeature = polygonF.AddFeature(polygonGeometry);

                        //add first coordinate
                        polygonFeature.Coordinates.Add(coord);

                        //add to the list of coordinates
                        xCoordinates.Add(coord.X);
                        yCoordinates.Add(coord.Y);

                        //set the polygon feature attribute
                        polygonID = polygonID + 1;
                        polygonFeature.DataRow["PolygonID"] = polygonID;
                        firstClick = false;

                        //Add volume data column
                        polygonFeature.DataRow["Volume"] = 0;
                    }
                    else
                    {
                        //second or more clicks-add points to the existing feature
                        IFeature existingFeature = (IFeature)polygonF.Features[polygonF.Features.Count - 1];

                        existingFeature.Coordinates.Add(coord);

                        //add to the list of coordinates
                        xCoordinates.Add(coord.X);
                        yCoordinates.Add(coord.Y);

                        //refresh the map if line has 2 or more points
                        if (existingFeature.Coordinates.Count != 0)
                        {
                            //refresh the map
                            polygonF.InitializeVertices();
                            mapMain.ResetBuffer();
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public FeatureSet DrawLine()
        {
            FeatureSet lineF = new FeatureSet(FeatureType.Line);

            lineF.Projection = map.Projection;
            lineF.DataTable.Columns.Add("Value", typeof(double));//方便之后在等值线上标注
            MapLineLayer lineLayer = default(MapLineLayer);

            lineLayer = (MapLineLayer)map.Layers.Add(lineF);
            LineSymbolizer symnol = new LineSymbolizer(Color.Black, 2);

            lineLayer.Symbolizer = symnol;
            string[] thename = raster.Filename.Split('\\');
            lineLayer.LegendText = thename[thename.Length - 1] + "_line";
            //MapLabelLayer
            MapLabelLayer  labelLayer = new MapLabelLayer();
            ILabelCategory category   = labelLayer.Symbology.Categories[0];

            category.Expression = "[Value]";
            category.SelectionSymbolizer.BackColorEnabled = true;
            category.Symbolizer.BorderVisible             = false;
            category.Symbolizer.BackColor   = Color.FromArgb(128, Color.LightBlue);;
            category.Symbolizer.FontStyle   = FontStyle.Regular;
            category.Symbolizer.FontColor   = Color.Black;
            category.Symbolizer.FontSize    = 8.5f;
            category.Symbolizer.Orientation = ContentAlignment.MiddleCenter;
            category.Symbolizer.Alignment   = StringAlignment.Center;
            lineLayer.ShowLabels            = true;
            lineLayer.LabelLayer            = labelLayer;

            /*double min_X, min_Y, max_X, max_Y;
             * min_X = raster.Xllcenter - raster.CellWidth / 2;
             * min_Y = raster.Yllcenter - raster.CellHeight / 2;
             * max_X = raster.CellToProj(0, raster.NumColumns-1).X + raster.CellWidth / 2;
             * max_Y = raster.CellToProj(0, 0).Y + raster.CellHeight/2;
             * double interspace = (raster.CellToProj(1, 1).X - raster.CellToProj(0, 0).X) *
             *  (raster.CellToProj(1, 1).X - raster.CellToProj(0, 0).X) + (raster.CellToProj(1, 1).Y - raster.CellToProj(0, 0).Y) *
             *  (raster.CellToProj(1, 1).Y - raster.CellToProj(0, 0).Y);
             * Console.WriteLine("minX: " + min_X + " , minY: "+ min_Y + " , maxX: " + max_X + " , maxY: " + max_Y);*/
            List <Tin_Point> lpoints = new List <Tin_Point>();

            foreach (var lines in contourData)
            {
                //if(lines.Key == 18)
                //{
                //int i = 0;
                foreach (var line in lines.Value)
                {
                    Tin_Point p1 = new Tin_Point(line.startPoint.X, line.startPoint.Y, lines.Key);
                    Tin_Point p2 = new Tin_Point(line.endPoint.X, line.endPoint.Y, lines.Key);
                    //p1.Type = i;
                    //p2.Type = i;
                    lpoints.Add(p1);
                    lpoints.Add(p2);
                    List <Coordinate> lineArray    = new List <Coordinate>();
                    LineString        lineGeometry = new LineString(lineArray);
                    IFeature          lineFeature  = lineF.AddFeature(lineGeometry);
                    lineFeature.Coordinates.Add(line.startPoint);
                    lineFeature.Coordinates.Add(line.endPoint);
                    lineFeature.DataRow["Value"] = lines.Key;
                    lineF.InitializeVertices();
                    //i++;
                }
                //}
            }

            /*
             * Polish polish = new Polish();
             * List<List<Tin_Point>> new_tin_points = polish.ClassifyLine(lpoints);
             * Console.WriteLine("new_tin_point num: " + new_tin_points.Count);
             * foreach(var lines in new_tin_points)
             * {
             *  //int i = 0;
             *  foreach(var p in lines)
             *  {
             *      Console.Write(p.X + " , " + p.Y + "||");
             *  }
             *  Console.WriteLine("*********************************");
             * }
             * foreach (var lines in new_tin_points)
             * {
             *  //int i = 0;
             *
             *   Console.WriteLine(lines[0].X + " , " + lines[0].Y + "||" + lines[lines.Count-1].X + " , " + lines[lines.Count - 1].Y);
             * }
             *
             *
             * foreach (var freeline in new_tin_points)
             * {
             *  List<Coordinate> lineArray = new List<Coordinate>(); ;
             *  ILineString lineGeometry = new LineString(lineArray);
             *  IFeature lineFeature = lineF.AddFeature(lineGeometry);
             *  lineFeature.DataRow["Value"] = (int)freeline[0].Value;
             *  foreach (var p in freeline)
             *  {
             *      Coordinate coordinate = new Coordinate(p.X, p.Y);
             *      lineArray.Add(coordinate);
             *      lineFeature.Coordinates.Add(coordinate);
             *      lineF.InitializeVertices();
             *  }
             * }
             */
            map.ResetBuffer();
            return(lineF);
        }
Ejemplo n.º 3
0
        public void FreeLine(List <Tin_Point> freeline)
        {
            if (freeline.Count < 4)
            {
                Console.WriteLine("不符合标准!");
                return;
                //return null;
            }
            else
            {
            }
            //label标识
            //
            List <Coordinate> lineArray    = new List <Coordinate>();;
            ILineString       lineGeometry = new LineString(lineArray);
            IFeature          lineFeature  = fs.AddFeature(lineGeometry);

            lineFeature.DataRow["Value"] = freeline[0].Value;
            //非封闭的等值线,需要在最前面加入p0,p0=p1,pn+1 = pn
            freeline.Add(freeline[freeline.Count - 1]);
            int i, j, n;

            n = freeline.Count;//等值点总数
            for (i = freeline.Count - 1; i > 0; i--)
            {
                freeline[i] = freeline[i - 1];
            }
            freeline.Add(freeline[freeline.Count - 1]);
            //
            double t1, t2, t3, t, a, b, c, d, x, y;//abcd为参数,xy为新插入点的坐标,

            //t1,t2,t3分别表示系数的开方,t1表示一次项系数,t2表示二次项系数,它表示3此项系数
            t = 0.5f / Clip; //系数0-0.5
                             //List<List<Tin_Point>> point_list = new List<List<Tin_Point>>();
            for (i = 0; i < n - 2; i++)
            {
                //
                Coordinate coordinate = new Coordinate(freeline[i + 1].X, freeline[i + 1].Y);
                lineArray.Add(coordinate);
                lineFeature.Coordinates.Add(coordinate);
                //
                //point_list.Add(new List<Tin_Point>());
                //List<Tin_Point> tp = new List<Tin_Point>();
                //point_list.Add(tp);
                for (j = 1; j < Clip; j++)
                {
                    t1 = j * t;
                    t2 = t1 * t1;
                    t3 = t2 * t1;
                    //下面是公式的表达
                    a = 4.0 * t2 - t1 - 4.0 * t3;
                    b = 1.0 - 10.0 * t2 + 12.0 * t3;
                    c = t1 + 8.0 * t2 - 12.0 * t3;
                    d = 4.0 * t3 - 2.0 * t2;
                    x = a * freeline[i].X + b * freeline[i + 1].X + c * freeline[i + 2].X + d * freeline[i + 3].X;
                    y = a * freeline[i].Y + b * freeline[i + 1].Y + c * freeline[i + 2].Y + d * freeline[i + 3].Y;
                    //Tin_Point new_point = new Tin_Point(x, y);
                    //
                    coordinate = new Coordinate(x, y);
                    lineArray.Add(coordinate);
                    LineString ls = new LineString(lineArray);
                    lineFeature.Coordinates.Add(coordinate);
                    fs.InitializeVertices();
                    //
                    //point_list[i].Add(new_point);
                }
                if (i == n - 3)
                {
                    coordinate = new Coordinate(freeline[i + 2].X, freeline[i + 2].Y);
                    lineArray.Add(coordinate);
                    LineString ls = new LineString(lineArray);
                    lineFeature.Coordinates.Add(coordinate);
                    fs.InitializeVertices();
                }
                //tp.Clear();
            }

            map.ResetBuffer();
            //return point_list;
        }
Ejemplo n.º 4
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (comboBox1.Text == "")
     {
         MessageBox.Show("要素信息不能为空", "TIN提示信息", MessageBoxButtons.OKCancel);
     }
     if (comboBox5.Text == "")
     {
         MessageBox.Show("纬度选择", "TIN提示信息", MessageBoxButtons.OKCancel);
     }
     if (comboBox6.Text == "")
     {
         MessageBox.Show("经度选择", "TIN提示信息", MessageBoxButtons.OKCancel);
     }
     if (flag == false)
     {
         FeatureSet     delaunayline = new FeatureSet(FeatureType.Line);
         MapLineLayer   ml           = (MapLineLayer)map.Layers.Add(delaunayline);
         LineSymbolizer symbol       = new LineSymbolizer(Color.Black, 2);
         ml.Symbolizer = symbol;
         ml.LegendText = "delaunay";
         List <Tin_Point> tin_Points = new List <Tin_Point>();
         for (int i = 0; i < ifeatureset.Features.Count; i++)
         {
             //Console.WriteLine("x: " + ifeatureset.Features[i].BasicGeometry.Coordinates[0].X + ", y: " + ifeatureset.Features[i].BasicGeometry.Coordinates[0].Y);
             tin_Points.Add(new Tin_Point(ifeatureset.Features[i].BasicGeometry.Coordinates[0].X, ifeatureset.Features[i].BasicGeometry.Coordinates[0].Y));
         }
         Delaunay        delaunay  = new Delaunay();
         List <Triangle> triangles = new List <Triangle>();
         triangles = delaunay.ConstructionDelaunay(tin_Points);
         foreach (var tri in triangles)
         {
             Coordinate        a            = new Coordinate(tri.p1.X, tri.p1.Y);
             Coordinate        b            = new Coordinate(tri.p2.X, tri.p2.Y);
             Coordinate        c            = new Coordinate(tri.p3.X, tri.p3.Y);
             List <Coordinate> lineArray    = new List <Coordinate>();
             ILineString       lineGeometry = new LineString(lineArray);
             IFeature          lineFeature  = delaunayline.AddFeature(lineGeometry);
             lineArray.Add(a);
             lineArray.Add(b);
             lineArray.Add(c);
             DotSpatial.Topology.LineString ls = new LineString(lineArray);
             lineFeature.Coordinates.Add(a);
             lineFeature.Coordinates.Add(b);
             lineFeature.Coordinates.Add(c);
             delaunayline.InitializeVertices();
             map.ResetBuffer();
         }
     }
     if (FileName != "")
     {
         ifeatureset.SaveAs(FileName, true);
         if (checkBox1.CheckState == CheckState.Checked)
         {
             var shp = Shapefile.OpenFile(FileName);
             shp.Projection = ifeatureset.Projection;
             map.Layers.Add(shp);
         }
     }
     MessageBox.Show("TIN操作完成", "TIN提示信息", MessageBoxButtons.OK);
     this.Close();
 }
Ejemplo n.º 5
0
        public void RaisePostBackEvent(string eventArgument)
        {
            GDIMap m = ControlMap;

            string[] arg = eventArgument.Split('|');

            string cmd = arg[0].ToUpper();

            switch (cmd)
            {
            case "CLICK":
            {
                if (MapClick != null)
                {
                    System.Drawing.Point pt1 = new System.Drawing.Point(Convert.ToInt32(arg[2]), Convert.ToInt32(arg[3]));
                    Coordinate           pm1 = m.PixelToProj(pt1);

                    MapClickEventArgs mc = new MapClickEventArgs();

                    mc.button = Convert.ToInt32(arg[1]);;
                    mc.x      = pm1.X;
                    mc.y      = pm1.Y;

                    MapClick(this, mc);
                }
            }
            break;

            case "ADDFEATURE":
            {
                int num = Convert.ToInt32(arg[1]);

                System.Drawing.Point pt = new System.Drawing.Point();
                Coordinate[]         pm = new Coordinate[num];

                for (int i = 0; i < num; i++)
                {
                    pt.X = Convert.ToInt32(arg[(i + 1) * 2]);
                    pt.Y = Convert.ToInt32(arg[(i + 1) * 2 + 1]);

                    pm[i] = m.PixelToProj(pt);
                }


                FeatureSet  fs = m.Layers.SelectedLayer.DataSet as FeatureSet;
                Feature     f;
                FeatureType ft = FeatureType.Unspecified;

                if (m.Layers.SelectedLayer != null)
                {
                    IMapFeatureLayer MFL = (IMapFeatureLayer)m.Layers.SelectedLayer;

                    if (MFL.GetType() == typeof(MapPointLayer))
                    {
                        ft = FeatureType.Point;
                    }
                    if (MFL.GetType() == typeof(MapLineLayer))
                    {
                        ft = FeatureType.Line;
                    }
                    if (MFL.GetType() == typeof(MapPolygonLayer))
                    {
                        ft = FeatureType.Polygon;
                    }

                    if (ft != FeatureType.Unspecified)
                    {
                        f = new Feature(ft, pm);

                        if (AddFeature != null)
                        {
                            AddFeature(this, fs, f);
                        }
                        else
                        {
                            fs.AddFeature(f);
                            fs.InitializeVertices();
                        }
                    }
                }
            }
            break;

            case "DATAGRID":
            {
                if (m.Layers.SelectedLayer != null)
                {
                    //string script=null;

                    if (DataOnGrid != null)
                    {
                        DataGridEventArgs e   = new DataGridEventArgs();
                        IMapFeatureLayer  MFL = (IMapFeatureLayer)m.Layers.SelectedLayer;

                        int n = MFL.Selection.Count;

                        if (n > 0)
                        {
                            FeatureSet fs = MFL.Selection.ToFeatureSet();
                            e.Recordsource = fs.DataTable;
                        }
                        else
                        {
                            e.Recordsource = MFL.DataSet.DataTable;
                        }

                        DataOnGrid(this, e);
                    }
                }
            }
            break;

            case "FORCEREFRESH":
            {
                //simply do nothing
            }
            break;
            }
        }
Ejemplo n.º 6
0
        private void drawToolStripMenuItem_Click(object sender, EventArgs e)    //绘制曲流颈和曲流轴
        {
            //DataColumn column = new DataColumn("LineID");
            //if (!lineF_.DataTable.Columns.Contains("LineID"))
            //{
            //    lineF_.DataTable.Columns.Add(column);
            //}

            foreach (List <DotSpatial.Topology.Coordinate> FeaturePoint in FeaturePoints)
            {
                //Create a new List called lineArray.
                //This list will store the Coordinates
                //We are going to store the mouse click coordinates into this array.
                List <DotSpatial.Topology.Coordinate> lineArray = new List <DotSpatial.Topology.Coordinate>();
                //Create an instance for LineString class.
                //We need to pass collection of list coordinates
                LineString lineGeometry = new LineString(lineArray);

                //Add the linegeometry to line feature
                //add 曲流颈 coordinate to the line feature
                IFeature lineFeature1 = lineF_.AddFeature(lineGeometry); //添加线要素
                lineFeature1.Coordinates.Add(FeaturePoint[0]);
                lineFeature1.Coordinates.Add(FeaturePoint[1]);

                //DataRowBuilder dataRowBuilder1 = new DataRowBuilder();
                //lineFeature1.DataRow = new DataRow();

                //Add the linegeometry to line feature
                //add 曲流轴 coordinate to the line feature
                IFeature lineFeature2 = lineF_.AddFeature(lineGeometry); //添加线要素
                lineFeature2.Coordinates.Add(FeaturePoint[2]);
                lineFeature2.Coordinates.Add(FeaturePoint[3]);

                //refresh the map if line has 2 or more points
                if (lineFeature1.Coordinates.Count >= 2 && lineFeature2.Coordinates.Count >= 2)
                {
                    lineF_.InitializeVertices();
                    map1.ResetBuffer();
                }
            }

            //set projection
            lineF_.Projection = map1.Projection;

            //initialize the featureSet attribute table
            DataColumn column = new DataColumn("LineID");

            if (!lineF_.DataTable.Columns.Contains("LineID"))
            {
                lineF_.DataTable.Columns.Add(column);
            }

            //add the featureSet as map layer
            lineLayer = (MapLineLayer)map1.Layers.Add(lineF_);

            //Set the symbolizer to the line feature.
            LineSymbolizer symbol = new LineSymbolizer(Color.Red, Color.Red, 2, DashStyle.Dot, LineCap.Square);

            lineLayer.Symbolizer = symbol;
            lineLayer.LegendText = "line";
            MessageBox.Show("Draw Over!!!");
        }
Ejemplo n.º 7
0
        public void RaiseCallbackEvent(String eventArgument)
//        public virtual void RaiseCallbackEvent(String eventArgument)  //to override in subclass
        {
//            returnCommand = "REFRESH";  //unsightly refresh when change legend selection
            returnCommand = "NOTHING";

//            string Nm = SessionName;  //not used

            GDIMap m = (GDIMap)System.Web.HttpContext.Current.Session[(string)ViewState[ClientID]];

            if (m == null)
            {
                return;
            }

            string[] arg = eventArgument.Split('|');

            string cmd = arg[0].ToUpper();

            switch (cmd)
            {
            case "ZOOMALL":
            {
                ZoomAll(ref m);
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "SELECT":
            {
                if (m.Layers.SelectedLayer != null)
                {
                    System.Drawing.Point pt1 = new System.Drawing.Point(Convert.ToInt32(arg[1]), Convert.ToInt32(arg[2]));
                    System.Drawing.Point pt2 = new System.Drawing.Point(Convert.ToInt32(arg[3]), Convert.ToInt32(arg[4]));

                    Coordinate pm1 = m.PixelToProj(pt1);
                    Coordinate pm2 = m.PixelToProj(pt2);

                    Extent ex = new Extent(Math.Min(pm1.X, pm2.X), Math.Min(pm1.Y, pm2.Y),
                                           Math.Max(pm1.X, pm2.X), Math.Max(pm1.Y, pm2.Y));

                    IEnvelope MapEnv = m.Extent.ToEnvelope();

                    m.Layers.SelectedLayer.ClearSelection(out MapEnv);


                    m.Layers.SelectedLayer.ClearSelection();

                    IEnvelope affectedarea = null;

//                                m.Layers.SelectedLayer.Select(m.ViewExtents.ToEnvelope(), ex.ToEnvelope(), Symbology.SelectionMode.IntersectsExtent, out affectedarea);
                    m.Layers.SelectedLayer.Select(ex.ToEnvelope(), ex.ToEnvelope(), Symbology.SelectionMode.Intersects, out affectedarea);

                    returnCommand = "STRUCTURE";
                }
                else
                {
                    returnValue   = "<table><tr><td>Select a layer first.<p></td></tr><table>";
                    returnCommand = "POPUP";
//                                returnValue = "Select a layer first.";
//                                returnCommand = "ALERT";
                }
            }
            break;

            case "INFO":
            {
                System.Drawing.Point pt = new System.Drawing.Point(Convert.ToInt32(arg[2]), Convert.ToInt32(arg[3]));
                Coordinate           pm = m.PixelToProj(pt);

                Extent ex = new Extent(pm.X, pm.Y, pm.X, pm.Y);

                if (m.Layers.SelectedLayer != null)
                {
                    FeatureSet fs = m.Layers.SelectedLayer.DataSet as FeatureSet;

//                                List<IFeature> flist = fs.Select(ex);  //returns empty list when IndexMode == false
                    List <int> flist = fs.SelectIndices(ex);

                    int n = flist.Count;

//                                returnValue = "<table border='1'>";  //looks goofy
                    returnValue = "<table>";

                    if (n > 0)
                    {
                        for (int i = 0; i < fs.DataTable.Columns.Count; i++)
                        {
                            returnValue += "<tr><td>" + fs.DataTable.Columns[i].ColumnName +
//                                                       "</td><td>" + flist[0].DataRow[i].ToString() + "</td></tr>";
                                           "</td><td>" + fs.GetFeature(flist[0]).DataRow[i].ToString() + "</td></tr>";
                        }

                        returnValue  += "</table>";
                        returnCommand = "POPUP";
                    }
                }
                else
                {
                    returnValue   = "<table><tr><td>Select a layer first.<p></td></tr><table>";
                    returnCommand = "POPUP";
//                                returnValue = "Select a layer first.";
//                                returnCommand = "ALERT";
                }
            }
            break;


            case "RESIZE":
            {
                Size NewSz    = new Size(Convert.ToInt32(arg[2]), Convert.ToInt32(arg[3]));
                Size ActualSz = ControlSize;

                if (ActualSz.Width == 0 || ActualSz.Height == 0)
                {
                    ControlSize = NewSz;

                    ZoomAll(ref m);

                    returnCommand = "STRUCTURE";
                }
                else
                {
                    if (NewSz != ActualSz)
                    {
                        ControlSize = NewSz;

                        returnCommand = "STRUCTURE";
                    }
                    else
                    {
                        returnCommand = "NOTHING";
                    }
                }
            }
            break;

            case "ZOOMRECT":
            {
                System.Drawing.Point pt1 = new System.Drawing.Point(Convert.ToInt32(arg[1]), Convert.ToInt32(arg[2]));
                System.Drawing.Point pt2 = new System.Drawing.Point(Convert.ToInt32(arg[3]), Convert.ToInt32(arg[4]));

                Coordinate pm1 = m.PixelToProj(pt1);
                Coordinate pm2 = m.PixelToProj(pt2);

                Extent x = new Extent(Math.Min(pm1.X, pm2.X),
                                      Math.Min(pm1.Y, pm2.Y),
                                      Math.Max(pm1.X, pm2.X),
                                      Math.Max(pm1.Y, pm2.Y));

                m.ViewExtents = x;
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "ZOOMIN":
            {
                int x = Convert.ToInt32(arg[1]);
                int y = Convert.ToInt32(arg[2]);

                System.Drawing.Point pntZoomAndCenter = new System.Drawing.Point((x - m.Size.Width / 2), (y - m.Size.Height / 2));
                m.MapFrame.Pan(pntZoomAndCenter);
                m.ZoomIn();
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "ZOOMOUT":
            {
                int x = Convert.ToInt32(arg[1]);
                int y = Convert.ToInt32(arg[2]);

                System.Drawing.Point pnt = new System.Drawing.Point((x - m.Size.Width / 2), (y - m.Size.Height / 2));

                m.MapFrame.Pan(pnt);
                m.ZoomOut();
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "PAN":
            {
                int x = Convert.ToInt32(arg[1]);
                int y = Convert.ToInt32(arg[2]);

// not used:                System.Drawing.Point pnt = new System.Drawing.Point((x - m.Size.Width / 2), (y - m.Size.Height / 2));

                m.MapFrame.Pan(new System.Drawing.Point(x, y));
                returnCommand = "REFRESH";
            }
            break;

            case "WHEELIN":
            {
                m.ZoomIn();
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "WHEELOUT":
            {
                m.ZoomOut();
                returnCommand = "REFRESHANDHIDEBUFFER";
            }
            break;

            case "DATAGRID":          //moved to here from RaisePostBackEvent
            {
                if (m.Layers.SelectedLayer != null)
                {
                    //string script=null;

                    IMapFeatureLayer MFL = (IMapFeatureLayer)m.Layers.SelectedLayer;

                    int n = MFL.Selection.Count;

                    FeatureSet fs;
                    DataTable  rs;
                    if (n > 0)
                    {
                        fs = MFL.Selection.ToFeatureSet();
                        rs = fs.DataTable;
                    }
                    else
                    {
                        fs = MFL.DataSet as FeatureSet;
                        rs = fs.DataTable;
                    }

                    if (DataOnGrid != null)              //Let event handler display grid?
                    {
                        DataGridEventArgs e = new DataGridEventArgs();
                        e.Recordsource = rs;
                        DataOnGrid(this, e);
                    }
                    else              //Display default HTML grid
                    {
                        returnValue = "<table border='1'><tr>";

                        for (int h = 0; h < rs.Columns.Count; h++)
                        {
                            returnValue += "<th>" + rs.Columns[h].ColumnName + "</th>";
                        }
                        returnValue += "</tr>";

                        string rowHtml;
                        for (int r = 0; r < rs.Rows.Count; r++)
                        {              //note: _much_ faster if build each row separately
                            rowHtml = "<tr>";
                            for (int c = 0; c < rs.Columns.Count; c++)
                            {
                                rowHtml += "<td>" + fs.GetFeature(r).DataRow[c].ToString() + "</td>";
                            }
                            rowHtml     += "</tr>";
                            returnValue += rowHtml;
                        }
                        returnValue  += "</table>";
                        returnCommand = "POPUP";
                    }
                }
                else
                {
                    returnValue   = "<table><tr><td>Select a layer first.<p></td></tr><table>";
                    returnCommand = "POPUP";
                }
            }
            break;

            case "ADDFEATURE":          //moved to here from RaisePostBackEvent
            {
                int num = Convert.ToInt32(arg[1]);

                System.Drawing.Point pt = new System.Drawing.Point();
                Coordinate[]         pm = new Coordinate[num];

                for (int i = 0; i < num; i++)
                {
                    pt.X = Convert.ToInt32(arg[(i + 1) * 2]);
                    pt.Y = Convert.ToInt32(arg[(i + 1) * 2 + 1]);

                    pm[i] = m.PixelToProj(pt);
                }

                if (m.Layers.SelectedLayer != null)
                {
                    FeatureSet  fs = m.Layers.SelectedLayer.DataSet as FeatureSet;
                    Feature     f;
                    FeatureType ft = FeatureType.Unspecified;

                    IMapFeatureLayer MFL = (IMapFeatureLayer)m.Layers.SelectedLayer;

                    if (MFL.GetType() == typeof(MapPointLayer))
                    {
                        ft = FeatureType.Point;
                    }
                    if (MFL.GetType() == typeof(MapLineLayer))
                    {
                        ft = FeatureType.Line;
                    }
                    if (MFL.GetType() == typeof(MapPolygonLayer))
                    {
                        ft = FeatureType.Polygon;
                    }

                    if (ft != FeatureType.Unspecified)
                    {
                        f = new Feature(ft, pm);

                        try
                        {
                            if (AddFeature != null)
                            {
                                AddFeature(this, fs, f);
                            }
                            else
                            {
                                try
                                {
                                    fs.AddFeature(f);
                                    fs.Save();
                                }
                                catch
                                {
                                    fs.Features.Remove(f);
                                    throw;              //re-throw exception
                                }
                                fs.InitializeVertices();
                            }
                            //Apparently have to force recreating labels when add feature.
                            if (MFL.LabelLayer != null)
                            {
                                // Recreating label layer works.
//                                            MapLabelLayer NewLabels = new MapLabelLayer();
//                                            NewLabels.Symbology = MFL.LabelLayer.Symbology;
//                                            NewLabels.Symbolizer = MFL.LabelLayer.Symbolizer;
//                                            MFL.LabelLayer = NewLabels;
                                // Recreating just labels also works.
                                MFL.LabelLayer.CreateLabels();
                            }
                            returnCommand = "FORCEREFRESH";
                        }
                        catch (Exception e)
                        {
                            returnValue   = "Unable to save feature.<p>" + e.Message;
                            returnCommand = "POPUPANDREFRESH";              //erase new shape too
                        }

//                                    fs.IndexMode = true;
                        //Adding a feature sets FeatureSet.IndexMode to false,
                        // causing fs.Select above in INFO case to return a list
                        // with Count == 0. One workaround is to set IndexMode
                        // back to true. This does cause all existing labels
                        // to disapper with refresh, but recreating label layer
                        // above fixed that. (Also tried InitializeVertices,
                        // InvalidateEnvelope, InvalidateVertices, UpdateExtents, etc.)
                        // Oops, setting IndexMode back to true corrupts shapes...
                    }
                }
            }
            break;
            }

            //ControlMap = m;
            System.Web.HttpContext.Current.Session[(string)ViewState[ClientID]] = m;

            if (returnCommand == "STRUCTURE")
            {
                returnValue = redraw(ref m);

                if (OnRedraw != null)
                {
                    OnRedraw(this);
                }
            }

            if (returnCommand == "REFRESH" | returnCommand == "REFRESHANDHIDEBUFFER")
            {
                returnValue = refresh(ref m);

                if (OnRedraw != null)
                {
                    OnRedraw(this);
                }
            }
        }
        private void map1_MouseDown(object sender, MouseEventArgs e)
        {
            switch (shapeType)
            {
            case "Point":
                if (e.Button == MouseButtons.Left)
                {
                    if ((pointmouseClick))
                    {
                        //This method is used to convert the screen cordinate to map coordinate
                        //e.location is the mouse click point on the map control
                        Coordinate coord = map1.PixelToProj(e.Location);

                        //Create a new point
                        //Input parameter is clicked point coordinate
                        DotSpatial.Topology.Point point = new DotSpatial.Topology.Point(coord);

                        //Add the point into the Point Feature
                        //assigning the point feature to IFeature because via it only we can set the attributes.
                        IFeature currentFeature = pointF.AddFeature(point);

                        //increase the point id
                        pointID = pointID + 1;

                        //set the ID attribute
                        currentFeature.DataRow["PointID"] = pointID;

                        //refresh the map
                        map1.ResetBuffer();
                    }
                }
                else
                {
                    //mouse right click
                    map1.Cursor     = Cursors.Default;
                    pointmouseClick = false;
                }

                break;

            case "line":
                if (e.Button == MouseButtons.Left)
                {
                    //left click - fill array of coordinates
                    //coordinate of clicked point
                    Coordinate coord = map1.PixelToProj(e.Location);
                    if (linemouseClick)
                    {
                        //first time left click - create empty line feature
                        if (firstClick)
                        {
                            //Create a new List called lineArray.
                            //This list will store the Coordinates
                            //We are going to store the mouse click coordinates into this array.
                            List <Coordinate> lineArray = new List <Coordinate>();

                            //Create an instance for LineString class.
                            //We need to pass collection of list coordinates
                            LineString lineGeometry = new LineString(lineArray);

                            //Add the linegeometry to line feature
                            IFeature lineFeature = lineF.AddFeature(lineGeometry);

                            //add first coordinate to the line feature
                            lineFeature.Coordinates.Add(coord);
                            //set the line feature attribute
                            lineID = lineID + 1;
                            lineFeature.DataRow["LineID"] = lineID;
                            firstClick = false;
                        }
                        else
                        {
                            //second or more clicks - add points to the existing feature
                            IFeature existingFeature = lineF.Features[lineF.Features.Count - 1];
                            existingFeature.Coordinates.Add(coord);

                            //refresh the map if line has 2 or more points
                            if (existingFeature.Coordinates.Count >= 2)
                            {
                                lineF.InitializeVertices();
                                map1.ResetBuffer();
                            }
                        }
                    }
                }
                else
                {
                    //right click - reset first mouse click
                    firstClick = true;
                    map1.ResetBuffer();
                }
                break;

            case "polygon":

                if (e.Button == MouseButtons.Left)
                {
                    //left click - fill array of coordinates
                    Coordinate coord = map1.PixelToProj(e.Location);

                    if (polygonmouseClick)
                    {
                        //first time left click - create empty line feature
                        if (firstClick)
                        {
                            //Create a new List called polygonArray.

                            //this list will store the Coordinates
                            //We are going to store the mouse click coordinates into this array.

                            List <Coordinate> polygonArray = new List <Coordinate>();

                            //Create an instance for LinearRing class.
                            //We pass the polygon List to the constructor of this class
                            LinearRing polygonGeometry = new LinearRing(polygonArray);

                            //Add the polygonGeometry instance to PolygonFeature
                            IFeature polygonFeature = polygonF.AddFeature(polygonGeometry);

                            //add first coordinate to the polygon feature
                            polygonFeature.Coordinates.Add(coord);

                            //set the polygon feature attribute
                            polygonID = polygonID + 1;
                            polygonFeature.DataRow["PolygonID"] = polygonID;
                            firstClick = false;
                        }
                        else
                        {
                            //second or more clicks - add points to the existing feature
                            IFeature existingFeature = (IFeature)polygonF.Features[polygonF.Features.Count - 1];

                            existingFeature.Coordinates.Add(coord);

                            //refresh the map if line has 2 or more points
                            if (existingFeature.Coordinates.Count >= 3)
                            {
                                //refresh the map
                                polygonF.InitializeVertices();
                                map1.ResetBuffer();
                            }
                        }
                    }
                }
                else
                {
                    //right click - reset first mouse click
                    firstClick = true;
                }
                break;
            }
        }