Exemple #1
0
 public override void OnMouseMove(int x, int y)
 {
     if (n < 1)
     {
     }
     else
     {
         lastPoint1 = mScreenDisplay.DisplayTransformation.ToScreen(lastPoint1Unit);
         double    xmin           = Math.Min(lastPoint1.X, lastPoint2.X);
         double    ymin           = Math.Min(lastPoint1.Y, lastPoint2.Y);
         double    w              = Math.Abs(lastPoint1.X - lastPoint2.X);
         double    h              = Math.Abs(lastPoint1.Y - lastPoint2.Y);
         Rectangle invalidaterect = new Rectangle((int)xmin, (int)ymin, (int)w, (int)h);
         invalidaterect.Inflate(2, 2);
         //擦除上次的范围
         (mScreenDisplay as ScreenDisplay).RepaintStatic(invalidaterect);
         lastPoint2 = new PointF(x, y);
         RgPoint p1 = lastPoint1Unit;
         RgPoint p2 = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(x, y));
         mScreenDisplay.StartDrawing(mMapCtrl.CreateGraphics(), 1);
         mScreenDisplayDraw.DrawLine(p1, p2, Pens.Blue);
         mScreenDisplay.FinishDrawing();
     }
 }
Exemple #2
0
        public override void OnMouseDown(int x, int y, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                n++;
                if (n == 1)
                {
                    RGeos.Geometries.RgPoint pt = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(x, y));
                    RGeos.Geometries.RgPoint P0 = new RGeos.Geometries.RgPoint(pt.X, pt.Y);
                    RGeos.Geometries.RgPoint P1 = new RGeos.Geometries.RgPoint(pt.X, pt.Y);
                    RGeos.Geometries.RgPoint P2 = new RGeos.Geometries.RgPoint(pt.X, pt.Y);
                    vertices.Add(P0);
                    vertices.Add(P1);
                    vertices.Add(P2);
                    line = new LinearRing(vertices);
                }
                else if (n == 2)
                {
                    PointF p2 = new PointF(x, y);
                    RGeos.Geometries.RgPoint pt1 = vertices[0];
                    RGeos.Geometries.RgPoint pt2 = mScreenDisplay.DisplayTransformation.ToUnit(p2);
                    vertices[1] = pt2;
                    mScreenDisplay.StartDrawing(mMapCtrl.CreateGraphics(), 1);
                    mScreenDisplayDraw.DrawLine(pt1, pt2, Pens.Blue);
                    mScreenDisplay.FinishDrawing();
                    //n = 0;
                }
                else if (n == 3)
                {
                    PointF p1 = new PointF(x, y);
                    RGeos.Geometries.RgPoint pt = mScreenDisplay.DisplayTransformation.ToUnit(p1);
                    vertices[2]          = pt;
                    polygon.ExteriorRing = line;
                    if (line != null)
                    {
                        SolidBrush brush = new SolidBrush(Color.Blue);
                        Pen        pen   = new Pen(brush);
                        mScreenDisplay.NewObject = polygon;
                        mMapCtrl.Refresh();
                    }
                }
                else
                {
                    PointF p1 = new PointF(x, y);
                    RGeos.Geometries.RgPoint pt = mScreenDisplay.DisplayTransformation.ToUnit(p1);
                    RGeos.Geometries.RgPoint P4 = pt;
                    vertices.Add(P4);
                    SolidBrush brush = new SolidBrush(Color.Blue);
                    Pen        pen   = new Pen(brush);
                    mScreenDisplay.NewObject = polygon;
                    mMapCtrl.Refresh();
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                Carto.FetureLayer featurelyr = mMapCtrl.Map.CurrentLayer as Carto.FetureLayer;
                if (featurelyr != null && featurelyr.ShapeType == RgEnumShapeType.RgPolygon)
                {
                    featurelyr.AddFeature(polygon);
                }

                vertices    = new List <RGeos.Geometries.RgPoint>();
                polygon     = new Polygon();
                tempPolygon = new Polygon();
                mScreenDisplay.NewObject = null;
                n = 0;
                mMapCtrl.Refresh();
            }
        }