public void StartDrawing(Graphics dc, int drawBuffer) { mDc = dc; DrawBufferFlag = drawBuffer; IsStartDrawing = true; if (DrawBufferFlag == 0) { Control mapCtrl = Control.FromHandle(Handle); if (mStaticImage == null) { mClipRectangle = mapCtrl.ClientRectangle; mStaticImage = new Bitmap(mClipRectangle.Width, mClipRectangle.Height); m_staticDirty = true; } System.Drawing.Drawing2D.SmoothingMode m_smoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; //绘制在背景图片上 mBitMapGc = Graphics.FromImage(mStaticImage); mBitMapGc.SmoothingMode = m_smoothingMode; mBitMapGc.Clear(Color.White); //m_model.BackgroundLayer.Draw(dcStatic, r); //if (m_model.GridLayer.Enabled) // m_model.GridLayer.Draw(dcStatic, r); //绘制十字丝 RgPoint rCenterPoint = new RgPoint(0, 0); PointF nullPoint = DisplayTransformation.ToScreen(rCenterPoint); mBitMapGc.DrawLine(Pens.Blue, nullPoint.X - 10, nullPoint.Y, nullPoint.X + 10, nullPoint.Y); mBitMapGc.DrawLine(Pens.Blue, nullPoint.X, nullPoint.Y - 10, nullPoint.X, nullPoint.Y + 10); } }
public void DrawPoint(RgPoint pt, Pen pen) { if (IsStartDrawing == false) { return; } PointF ptscreen = mDisplayTransformation.ToScreen(pt); if (DrawBufferFlag == 0) { if (mBitMapGc != null) { // mBitMapGc.DrawEllipse(pen, ptscreen.X, ptscreen.Y, 2, 2); mBitMapGc.DrawRectangle(pen, ptscreen.X, ptscreen.Y, 3, 3); //SizeF size = new SizeF(4f, 4f); //RectangleF rect = new RectangleF(ptscreen, size); //mBitMapGc.DrawEllipse(pen, rect); } } else { if (mDc != null) { mDc.DrawEllipse(pen, ptscreen.X, ptscreen.Y, 1, 1); } } }
void mMapControl_MouseMove(object sender, MouseEventArgs e) { RgPoint pt = mMapControl.ScreenDisplay.DisplayTransformation.ToUnit(new PointF(e.X, e.Y)); x = Math.Round(pt.X * MillmeteresPerInch, 3); y = Math.Round(pt.Y * MillmeteresPerInch, 3); }
/// <summary> /// 设置画布到屏幕的中心 /// </summary> /// <param name="rPoint">直角坐标系坐标</param> public void SetCenter(RgPoint unitPoint) { //将unitPoint点对应到屏幕上point PointF point = mScreenDisplay.DisplayTransformation.ToScreen(unitPoint); m_lastCenterPoint = unitPoint; //将unitPoint偏移到屏幕中心 SetCenterScreen(point, false); }
void mPanel_MouseMove(object sender, MouseEventArgs e) { if (CurrentTool != null) { CurrentTool.OnMouseMove(e.X, e.Y); } RgPoint pt = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(e.X, e.Y)); Debug.Write(string.Format("X:{0}mm Y:{1}mm", pt.X * 25.4, pt.Y * 25.4)); }
public RgPoint CenterPointUnit() { RgPoint p1 = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(0, 0)); RgPoint p2 = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(this.ClientRectangle.Width, this.ClientRectangle.Height)); RgPoint center = new RgPoint(); center.X = (p1.X + p2.X) / 2; center.Y = (p1.Y + p2.Y) / 2; return(center); }
private void UcMapControl_Resize(object sender, EventArgs e) { if (m_lastCenterPoint != null && Width != 0) { SetCenterScreen(mScreenDisplay.DisplayTransformation.ToScreen(m_lastCenterPoint), false); } m_lastCenterPoint = CenterPointUnit(); (mScreenDisplay as RGeos.Display.ScreenDisplay).UpdateWindow(); Invalidate(); }
public override void Draw(IScreenDisplay display) { IScreenDisplayDraw displayDraw = display as IScreenDisplayDraw; if (ShapeType == RgEnumShapeType.RgPoint) { for (int i = 0; i < mGeometries.Count; i++) { RGeos.Geometries.Point pt = mGeometries[i] as RGeos.Geometries.Point; if (pt != null) { displayDraw.DrawPoint(pt, new Pen(Color.Red)); } } } if (ShapeType == RgEnumShapeType.RgLineString) { for (int i = 0; i < mGeometries.Count; i++) { LineString pt = mGeometries[i] as LineString; if (pt != null) { displayDraw.DrawLineString(pt, new Pen(Color.Red)); // display as r } } } if (ShapeType == RgEnumShapeType.RgMultiLineString) { for (int i = 0; i < mGeometries.Count; i++) { MultiLineString pt = mGeometries[i] as MultiLineString; if (pt != null) { displayDraw.DrawMultiLineString(pt, new Pen(Color.Red)); } } } if (ShapeType == RgEnumShapeType.RgPolygon) { for (int i = 0; i < mGeometries.Count; i++) { Polygon pt = mGeometries[i] as Polygon; if (pt != null) { Pen mPen = new Pen(Color.Red); Brush brush = new SolidBrush(Color.Blue); displayDraw.DrawPolygon(pt, brush, mPen, false); } } } }
protected override void OnMouseWheel(MouseEventArgs e) { System.Drawing.Point point = this.PointToClient(Control.MousePosition); //放大中心点屏幕坐标 RgPoint p = mScreenDisplay.DisplayTransformation.ToUnit(point); //对应的当前Zoom下的世界坐标 float wheeldeltatick = 120; float zoomdelta = (1.25f * (Math.Abs(e.Delta) / wheeldeltatick)); if (e.Delta < 0) { mScreenDisplay.DisplayTransformation.Zoom = mScreenDisplay.DisplayTransformation.Zoom / zoomdelta; } else { mScreenDisplay.DisplayTransformation.Zoom = mScreenDisplay.DisplayTransformation.Zoom * zoomdelta; } SetCenterScreen(mScreenDisplay.DisplayTransformation.ToScreen(p), false);//放大后,得到同一个世界坐标对应的屏幕坐标 Invalidate(true); base.OnMouseWheel(e); }
public void DrawLine(RGeos.Geometries.Point p1, RGeos.Geometries.Point p2, Pen pen) { if (IsStartDrawing == false) { return; } if (DrawBufferFlag == 0) { PointF v1 = mDisplayTransformation.ToScreen(p1); PointF v2 = mDisplayTransformation.ToScreen(p2); if (mBitMapGc != null) { mBitMapGc.DrawLine(pen, v1, v2); } } else { PointF v1 = mDisplayTransformation.ToScreen(p1); PointF v2 = mDisplayTransformation.ToScreen(p2); mDc.DrawLine(pen, v1, v2); } }
public override void OnMouseDown(int x, int y, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { n++; if (n <= 1) { line = new LineString(); RgPoint pt = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(x, y)); line.Vertices.Add(pt); lastPoint1Unit = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(x, y)); lastPoint2 = new PointF(x, y); } else { RgPoint ptNext = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(x, y)); line.Vertices.Add(ptNext); lastPoint1Unit = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(x, y)); lastPoint2 = new PointF(x, y); mScreenDisplay.NewObject = line; mMapCtrl.Refresh(); } } else { Carto.FetureLayer featurelyr = mMapCtrl.Map.CurrentLayer as Carto.FetureLayer; if (featurelyr != null && featurelyr.ShapeType == RgEnumShapeType.RgLineString) { featurelyr.mGeometries.Add(line); } n = 0; mScreenDisplay.NewObject = null; mMapCtrl.Refresh(); } }
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(); } }
public override void OnMouseMove(int x, int y) { if (n == 1) { } if (n == 2) { j++; tmpVertices = new List <RGeos.Geometries.Point>(); RGeos.Geometries.Point P0 = vertices[0]; RGeos.Geometries.Point P1 = vertices[1]; RGeos.Geometries.Point pt = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(x, y)); RGeos.Geometries.Point P2 = pt; tmpVertices.Add(P0); tmpVertices.Add(P1); tmpVertices.Add(P2); LinearRing tmpLine = new LinearRing(tmpVertices); tempPolygon.ExteriorRing = tmpLine; if (j == 1) { BoundingBox box = tempPolygon.GetBoundingBox(); PointF lowLeft = mScreenDisplay.DisplayTransformation.ToScreen(box.TopLeft); PointF topRight = mScreenDisplay.DisplayTransformation.ToScreen(box.BottomRight); double xmin = lowLeft.X; double ymin = lowLeft.Y; double w = Math.Abs(topRight.X - lowLeft.X); double h = Math.Abs(topRight.Y - lowLeft.Y); Rectangle invalidaterect = new Rectangle((int)xmin, (int)ymin, (int)w, (int)h); invalidaterect.Inflate(2, 2); (mScreenDisplay as ScreenDisplay).RepaintStatic(invalidaterect); j = 0; } SolidBrush brush = new SolidBrush(Color.Blue); Pen pen = new Pen(brush); mScreenDisplay.StartDrawing(mMapCtrl.CreateGraphics(), 1); mScreenDisplayDraw.DrawPolygon(tempPolygon, brush, pen, false); mScreenDisplay.FinishDrawing(); } else if (n > 2) { BoundingBox box = tempPolygon.GetBoundingBox(); PointF lowLeft = mScreenDisplay.DisplayTransformation.ToScreen(box.TopLeft); PointF topRight = mScreenDisplay.DisplayTransformation.ToScreen(box.BottomRight); double xmin = lowLeft.X; double ymin = lowLeft.Y; double w = Math.Abs(topRight.X - lowLeft.X); double h = Math.Abs(topRight.Y - lowLeft.Y); Rectangle invalidaterect = new Rectangle((int)xmin, (int)ymin, (int)w, (int)h); invalidaterect.Inflate(2, 2); (mScreenDisplay as ScreenDisplay).RepaintStatic(invalidaterect); tmpVertices = new List <RGeos.Geometries.Point>(); RGeos.Geometries.Point P0 = vertices[0]; RGeos.Geometries.Point P1 = vertices[n - 1]; RGeos.Geometries.Point pt = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(x, y)); RGeos.Geometries.Point P2 = pt; tmpVertices.Add(P0); tmpVertices.Add(P1); tmpVertices.Add(P2); LinearRing tmpLine = new LinearRing(tmpVertices); tempPolygon.ExteriorRing = tmpLine; SolidBrush brush = new SolidBrush(Color.Blue); SolidBrush brush2 = new SolidBrush(Color.Pink); Pen pen = new Pen(brush2); mScreenDisplay.StartDrawing(mMapCtrl.CreateGraphics(), 1); mScreenDisplayDraw.DrawPolygon(tempPolygon, brush, pen, false); mScreenDisplay.FinishDrawing(); } }
public override void OnMouseDown(int x, int y, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { n++; if (n == 1) { RGeos.Geometries.Point pt = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(x, y)); RGeos.Geometries.Point P0 = new RGeos.Geometries.Point(pt.X, pt.Y); RGeos.Geometries.Point P1 = new RGeos.Geometries.Point(pt.X, pt.Y); RGeos.Geometries.Point P2 = new RGeos.Geometries.Point(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.Point pt1 = vertices[0]; RGeos.Geometries.Point 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.Point 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.Point pt = mScreenDisplay.DisplayTransformation.ToUnit(p1); RGeos.Geometries.Point 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.mGeometries.Add(polygon); } vertices = new List <RGeos.Geometries.Point>(); polygon = new Polygon(); tempPolygon = new Polygon(); mScreenDisplay.NewObject = null; n = 0; mMapCtrl.Refresh(); } }