Ejemplo n.º 1
0
        public void OnMouseClick(BMapControl c, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (IsCompleted)
                {
                    ReSet(c);
                }

                switch (DrawMode)
                {
                case EditMode.DrawLine:
                    if (LstMarkPoint.Count < 2)
                    {
                        LstMarkPoint.Add(c.PointToLatLng(e.Location));
                    }
                    else
                    {
                        LstMarkPoint.Add(c.PointToLatLng(e.Location));
                    }
                    if (LstMarkPoint.Count == 2)
                    {
                        IsCompleted = true;
                        var p1 = LstMarkPoint[0];
                        var p2 = LstMarkPoint[1];
                        //c.Invalidate(DrawHelper.GetLineRegion(c.LatLngToPoint(p1), c.LatLngToPoint(p2)));

                        _drawCompleteToolTip.Info = string.Format("距离:{0:0.00} 米\r\n正北角:{1:0.0} °"
                                                                  , MercatorHelper.GetDistance(p1, p2), MercatorHelper.GetBearing(p1, p2));
                    }
                    break;

                case EditMode.DrawLines:
                    PointLatLng lastP = null;
                    if (LstMarkPoint.Count > 0)
                    {
                        lastP = LstMarkPoint.Last();
                    }
                    var curP = c.PointToLatLng(e.Location);
                    LstMarkPoint.Add(curP);
                    //计算距离
                    if (lastP != null)
                    {
                        _linesDist += MercatorHelper.GetDistance(lastP, curP);
                    }
                    _drawCompleteToolTip.Info = string.Format("总距离:{0:0.00} 米", _linesDist);

                    break;

                case EditMode.DrawRect:
                    if (LstMarkPoint.Count < 2)
                    {
                        LstMarkPoint.Add(c.PointToLatLng(e.Location));
                    }
                    if (LstMarkPoint.Count == 2)
                    {
                        IsCompleted = true;
                        //var p1 = LstMarkPoint[0];
                        //var p2 = LstMarkPoint[1];
                        ////c.Invalidate(DrawHelper.GetLineRegion(c.LatLngToPoint(p1), c.LatLngToPoint(p2)));

                        //_drawCompleteToolTip.Info = string.Format("面积:{0:0.00} m²\r\n正北角:{1:0.0} °"
                        //    , MercatorHelper.GetDistance(p1, p2)* MercatorHelper.GetBearing(p1, p2));
                    }
                    break;

                case EditMode.DrawPolyon:
                    LstMarkPoint.Add(c.PointToLatLng(e.Location));
                    break;

                case EditMode.DrawCircle:
                    LstMarkPoint.Add(c.PointToLatLng(e.Location));
                    if (LstMarkPoint.Count == 2)
                    {
                        IsCompleted = true;
                        var p1 = LstMarkPoint[0];
                        var p2 = LstMarkPoint[1];
                        _drawCompleteToolTip.Info = string.Format("半径:{0:0.00}米", MercatorHelper.GetDistance(p1, p2));
                    }
                    break;

                case EditMode.DrawPie:
                    LstMarkPoint.Add(c.PointToLatLng(e.Location));
                    if (LstMarkPoint.Count == 3)
                    {
                        IsCompleted = true;
                        var p1 = c.LatLngToPoint(LstMarkPoint[0]);
                        var p2 = c.LatLngToPoint(LstMarkPoint[1]);
                        var p3 = c.LatLngToPoint(LstMarkPoint[2]);

                        _drawCompleteToolTip.Info = string.Format("坐标:{0}\r\n半径:{1:0.00}米\r\n中线方向:{2:0.00}°\r\n角度宽:{3:0.00}°",
                                                                  LstMarkPoint[0],
                                                                  MercatorHelper.GetDistance(LstMarkPoint[0], LstMarkPoint[1]),
                                                                  MercatorHelper.GetBearing(LstMarkPoint[0], LstMarkPoint[1]),
                                                                  2 * DrawHelper.GetAngle(p1, p2, p3));
                    }
                    break;

                case EditMode.None:
                default:

                    break;
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                IsCompleted = true;
            }

            if (DrawMode != EditMode.None)
            {
                c.Refresh();
            }

            if (IsCompleted)
            {
                if (DrawComplete != null)
                {
                    DrawComplete(LstMarkPoint);
                }
            }
        }
Ejemplo n.º 2
0
        public void Draw(BMapControl c, Graphics g)
        {
            if (DrawMode != EditMode.None)
            {
                Point lastPoint = Point.Empty;
                if (LstMarkPoint.Count > 0)
                {
                    lastPoint = c.LatLngToPoint(LstMarkPoint.Last());
                }

                string editModeMsg = string.Empty;

                switch (DrawMode)
                {
                case EditMode.None:
                    break;

                case EditMode.DrawLine:
                    if (LstMarkPoint.Count == 1)
                    {
                        var p1 = c.LatLngToPoint(LstMarkPoint[0]);
                        DrawDashLine(g, p1, _curMousePoint);
                    }
                    else if (LstMarkPoint.Count == 2)
                    {
                        var p1 = c.LatLngToPoint(LstMarkPoint[0]);
                        var p2 = c.LatLngToPoint(LstMarkPoint[1]);
                        g.DrawLine(DrawPen, p1, p2);
                        _drawCompleteToolTip.ShowPoint = p2;
                    }
                    editModeMsg = "画线模式(测距,测正北角)";
                    break;

                case EditMode.DrawLines:
                    if (LstMarkPoint.Count > 0)
                    {
                        var lst = new List <Point>();
                        //double dist = 0;
                        //var tempLatLng = new PointLatLng();
                        foreach (var item in LstMarkPoint)
                        {
                            lst.Add(c.LatLngToPoint(item));
                        }
                        if (lst.Count > 1)
                        {
                            g.DrawLines(DrawPen, lst.ToArray());
                        }
                    }
                    if (IsCompleted)
                    {
                        _drawCompleteToolTip.ShowPoint = lastPoint;
                    }
                    editModeMsg = "画折线模式(测距)";
                    break;

                case EditMode.DrawRect:
                    if (LstMarkPoint.Count == 1)
                    {
                        var p1 = c.LatLngToPoint(LstMarkPoint[0]);
                        DrawDashLine(g, p1, _curMousePoint);

                        DrawPen.DashStyle = DashStyle.Solid;
                    }
                    else if (LstMarkPoint.Count == 2)
                    {
                        var p1   = c.LatLngToPoint(LstMarkPoint[0]);
                        var p2   = c.LatLngToPoint(LstMarkPoint[1]);
                        var rect = DrawHelper.GetRect(p1, p2);
                        g.FillRectangle(FillBrush, rect);
                        g.DrawRectangle(DrawPen, rect);
                        //_drawCompleteToolTip.ShowPoint = p2;
                    }
                    editModeMsg = "画矩形模式";
                    break;

                case EditMode.DrawPolyon:

                    if (LstMarkPoint.Count > 1)
                    {
                        List <Point> lstp = new List <Point>();
                        foreach (var item in LstMarkPoint)
                        {
                            lstp.Add(c.LatLngToPoint(item));
                        }

                        PolyonPath = new GraphicsPath();
                        var ps = lstp.ToArray();

                        if (!IsCompleted)
                        {
                            g.DrawLines(DrawPen, ps);
                            //DrawDashLine(g, lastPoint, _curMousePoint);
                        }
                        else
                        {
                            if (ps.Length > 2)
                            {
                                g.DrawPolygon(DrawPen, ps);
                            }
                        }
                        if (ps.Length > 2)
                        {
                            PolyonPath.AddPolygon(ps);
                            PolyonPath.CloseFigure();
                            g.FillPolygon(FillBrush, ps);
                        }
                    }

                    editModeMsg = "画多边形模式";
                    break;

                case EditMode.DrawCircle:
                    if (LstMarkPoint.Count == 1)
                    {
                        var p1   = c.LatLngToPoint(LstMarkPoint[0]);
                        var rect = DrawHelper.GetEllipseRect(p1, _curMousePoint);

                        DrawPen.DashStyle   = DashStyle.DashDot;
                        DrawPen.DashPattern = new float[] { 5, 2 };
                        g.FillEllipse(FillBrush, rect);
                        g.DrawEllipse(DrawPen, rect);
                        DrawPen.DashStyle = DashStyle.Solid;
                    }
                    else if (LstMarkPoint.Count == 2)
                    {
                        var p1   = c.LatLngToPoint(LstMarkPoint[0]);
                        var p2   = c.LatLngToPoint(LstMarkPoint[1]);
                        var rect = DrawHelper.GetEllipseRect(p1, p2);
                        g.FillEllipse(FillBrush, rect);
                        g.DrawEllipse(DrawPen, rect);
                        //g.FillEllipse(DrawPen.Brush, new Rectangle(p1.GetOffSet(-5, -5), new Size(10, 10)));//画圆心
                        DrawDashLine(g, p1, p2);
                        _drawCompleteToolTip.ShowPoint = p2;
                    }
                    editModeMsg = "画圆模式";
                    break;

                case EditMode.DrawPie:
                    switch (LstMarkPoint.Count)
                    {
                    case 1:
                    {
                        var p1        = c.LatLngToPoint(LstMarkPoint[0]);
                        var curLatLng = c.MouseLatLng;
                        DrawPen.DashStyle   = DashStyle.DashDot;
                        DrawPen.DashPattern = new float[] { 5, 2 };
                        DrawPie(g, p1, _curMousePoint);
                        DrawDashLine(g, p1, _curMousePoint);
                        _curMouseToolTip.Info = string.Format("距离:{0:0.00}米\r\n正北角:{1:0.00}°", MercatorHelper.GetDistance(LstMarkPoint[0], curLatLng), MercatorHelper.GetBearing(LstMarkPoint[0], curLatLng));
                    }

                    break;

                    case 2:
                    {
                        var p1 = c.LatLngToPoint(LstMarkPoint[0]);
                        var p2 = c.LatLngToPoint(LstMarkPoint[1]);

                        var   angle      = DrawHelper.GetAngle(p1, p2, _curMousePoint);
                        float angleWidth = 2 * (float)angle;
                        DrawPen.DashStyle   = DashStyle.DashDot;
                        DrawPen.DashPattern = new float[] { 5, 2 };
                        DrawPie(g, p1, p2, angleWidth);

                        DrawDashLine(g, p1, p2);
                        //DrawDashLine(g, p1, _curMousePoint);

                        _curMouseToolTip.Info = string.Format("角度:{0:0.00}°", angleWidth);
                    }

                    break;

                    case 3:
                    {
                        var   p1         = c.LatLngToPoint(LstMarkPoint[0]);
                        var   p2         = c.LatLngToPoint(LstMarkPoint[1]);
                        var   p3         = c.LatLngToPoint(LstMarkPoint[2]);
                        var   angle      = DrawHelper.GetAngle(p1, p2, p3);
                        float angleWidth = 2 * (float)angle;
                        DrawPen.DashStyle = DashStyle.Solid;
                        DrawPie(g, p1, p2, angleWidth);
                        //g.DrawPie(DrawPen,)

                        _drawCompleteToolTip.ShowPoint = p1;
                    }
                    break;

                    default:
                        break;
                    }
                    editModeMsg = "画扇形模式";
                    break;

                default:
                    break;
                }

                //画坐标点信息
                _curMouseToolTip.Draw(c, g);

                if (IsCompleted)
                {
                    //_drawCompleteToolTip.ShowPoint = lastPoint;
                    _drawCompleteToolTip.Draw(c, g);//画完成信息
                }
                else if (!lastPoint.IsEmpty)
                {
                    switch (DrawMode)
                    {
                    case EditMode.None:
                        break;

                    case EditMode.DrawLine:
                    case EditMode.DrawLines:
                    case EditMode.DrawPolyon:
                    case EditMode.DrawCircle:
                        //case EditMode.DrawPie:
                        //画虚线
                        DrawDashLine(g, lastPoint, _curMousePoint);
                        break;

                    default:
                        break;
                    }
                }

                var pMode = new Point(c.Width / 2 - 50, 10);
                g.DrawString(editModeMsg, new Font("微软雅黑", 12, FontStyle.Bold), Brushes.White, pMode);//画模式
            }
        }
Ejemplo n.º 3
0
        private void DrawMapScale(Graphics g)
        {
            g.ResetTransform();
            int scaleLen = 50;
            int meter    = 0;

            switch (Zoom)
            {
            case 22:
                meter = 1;
                break;

            case 21:
            case 20:
                meter = 5;
                break;

            case 19:
                meter = 10;
                break;

            case 18:
                meter = 20;
                break;

            case 17:
                meter = 40;
                break;

            case 16:
                meter = 80;
                break;

            case 15:
                meter = 160;
                break;

            case 14:
                meter = 300;
                break;

            case 13:
                meter = 600;
                break;

            case 12:
                meter = 1000;
                break;

            case 11:
                meter = 2000;
                break;

            case 10:
                meter = 5000;
                break;

            case 9:
                meter = 10000;
                break;

            case 8:
                meter = 20000;
                break;

            case 7:
                meter = 40000;
                break;

            case 6:
                meter = 80000;
                break;

            case 5:
                meter = 150000;
                break;

            case 4:
                meter = 300000;
                break;

            case 3:
                meter = 600000;
                break;

            case 2:
                meter = 1000000;
                break;

            case 1:
                meter = 2000000;
                break;

            default:
                scaleLen = 50;
                break;
            }
            if (meter != 0)
            {
                scaleLen = (int)(meter / MercatorHelper.GetResolution(Zoom, MapCenter.LatY) + 0.5);
            }

            var dist = new Distance(meter);
            var str  = dist.ToString();
            //var str = distance.ToString("0.00") + "米";
            var font    = new Font("微软雅黑", 10, FontStyle.Bold);
            var strSize = g.MeasureString(str, font);
            var rect    = new Rectangle(new Point(5, this.Height - 30), new Size(scaleLen + 10 + (int)strSize.Width, (int)strSize.Height + 5));

            using (var gp = DrawHelper.GetRoundRect(rect, 5))
            {
                g.FillPath(new SolidBrush(Color.FromArgb(0x44, Color.Black)), gp);
            }

            Point p = new Point(10, this.Height - 20);

            Point[] ps = new Point[4];
            ps[0] = p;
            p.Offset(0, 5);
            ps[1] = p;
            p.Offset(scaleLen, 0);
            ps[2] = p;
            p.Offset(0, -5);
            ps[3] = p;
            var brush = new SolidBrush(Color.FromArgb(0xEE, Color.White));
            var pen   = new Pen(brush, 2);

            g.DrawLines(pen, ps);
            p.Offset(5, -10);
            g.DrawString(str, font, brush, p);
        }