示例#1
0
 /// <summary>
 /// POI信息显示控件关闭
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void _bPOITipControl_VisibleChanged(object sender, EventArgs e)
 {
     if (!_bPOITipControl.Visible)
     {
         _current_selected_poi = null;
         //取消选择
     }
 }
示例#2
0
        /// <summary>
        /// 鼠标在地图上按下
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Button == System.Windows.Forms.MouseButtons.Left) //左键
            {
                //检查设置鼠标工作方式
                if (new Rectangle(Width - 384 + 26 * 8, 10, 26, 26).Contains(PointToClient(Cursor.Position))) //鼠标定位
                {
                    _cursor_located = !_cursor_located;
                    Invalidate();
                    return;
                }
                else if (new Rectangle(Width - 384 + 26 * 7, 10, 26, 26).Contains(PointToClient(Cursor.Position))) //绘制多边形
                {
                    if (_mouse_type == MouseType.DrawPolygon)
                    {
                        _mouse_type = MouseType.None;
                        _current_cursor_cache = Cursor = Cursors.Arrow;
                    }
                    else
                    {
                        _mouse_type = MouseType.DrawPolygon;
                        _current_cursor_cache = Cursor = Cursors.Cross;  //特定光标
                        _current_drawing = null;
                        _bScreenshotMenu.Visible = false;
                    }
                    Invalidate();
                    return;
                }
                else if (new Rectangle(Width - 384 + 26 * 6, 10, 26, 26).Contains(PointToClient(Cursor.Position))) //绘制直线
                {
                    if (_mouse_type == MouseType.DrawLine)
                    {
                        _mouse_type = MouseType.None;
                        _current_cursor_cache = Cursor = Cursors.Arrow;
                    }
                    else
                    {
                        _mouse_type = MouseType.DrawLine;
                        _current_cursor_cache = Cursor = Cursors.Cross;  //特定光标
                        _current_drawing = null;
                        _bScreenshotMenu.Visible = false;
                    }
                    Invalidate();
                    return;
                }
                else if (new Rectangle(Width - 384 + 26 * 5, 10, 26, 26).Contains(PointToClient(Cursor.Position))) //绘制椭圆
                {
                    if (_mouse_type == MouseType.DrawCircle)
                    {
                        _mouse_type = MouseType.None;
                        _current_cursor_cache = Cursor = Cursors.Arrow;
                    }
                    else
                    {
                        _mouse_type = MouseType.DrawCircle;
                        _current_cursor_cache = Cursor = Cursors.Cross;  //特定光标
                        _current_drawing = null;
                        _bScreenshotMenu.Visible = false;
                    }
                    Invalidate();
                    return;
                }
                else if (new Rectangle(Width - 384 + 26 * 4, 10, 26, 26).Contains(PointToClient(Cursor.Position))) //绘制矩形
                {
                    if (_mouse_type == MouseType.DrawRectange)
                    {
                        _mouse_type = MouseType.None;
                        _current_cursor_cache = Cursor = Cursors.Arrow;
                    }
                    else
                    {
                        _mouse_type = MouseType.DrawRectange;
                        _current_cursor_cache = Cursor = Cursors.Cross;  //特定光标
                        _current_drawing = null;
                        _bScreenshotMenu.Visible = false;
                    }
                    Invalidate();
                    return;
                }
                else if (new Rectangle(Width - 384 + 26 * 3, 10, 26, 26).Contains(PointToClient(Cursor.Position))) //添加标记点
                {
                    if (_mouse_type == MouseType.DrawMarker)
                    {
                        _mouse_type = MouseType.None;
                        _current_cursor_cache = Cursor = Cursors.Arrow;
                    }
                    else
                    {
                        _mouse_type = MouseType.DrawMarker;
                        _current_drawing = null;
                        _bScreenshotMenu.Visible = false;
                    }
                    Invalidate();
                    return;
                }
                else if (new Rectangle(Width - 384 + 26 * 2, 10, 26, 26).Contains(PointToClient(Cursor.Position))) //截图
                {
                    if (_current_drawing as BScreenShotRectangle == null)
                    {
                        if (_mouse_type == MouseType.DrawScreenshotArea)
                        {
                            _mouse_type = MouseType.None;
                            _current_cursor_cache = Cursor = Cursors.Arrow;
                        }
                        else
                        {
                            _mouse_type = MouseType.DrawScreenshotArea;
                            _current_cursor_cache = Cursor = Cursors.Cross;  //特定光标
                        }
                        Invalidate();
                    }
                    return;
                }
                else if (new Rectangle(Width - 384 + 26 * 1, 10, 26, 26).Contains(PointToClient(Cursor.Position))) //测量距离
                {
                    if (_b_distance == null)
                    {
                        if (_mouse_type == MouseType.DrawDistance)
                        {
                            _mouse_type = MouseType.None;
                            _current_cursor_cache = Cursor = Cursors.Arrow;
                        }
                        else
                        {
                            _mouse_type = MouseType.DrawDistance;
                            _current_cursor_cache = Cursor = Cursors.Cross;  //特定光标
                            _current_drawing = null;
                            _bScreenshotMenu.Visible = false;
                        }
                        Invalidate();
                    }
                    else
                    {
                        _b_distance = null;
                    }
                    return;
                }
                else if (new Rectangle(Width - 384, 10, 26, 26).Contains(PointToClient(Cursor.Position))) //矩形区域搜索
                {
                    if (_b_bound == null)
                    {
                        if (_mouse_type == MouseType.DrawBound)
                        {
                            _mouse_type = MouseType.None;
                            _current_cursor_cache = Cursor = Cursors.Arrow;
                        }
                        else
                        {
                            _mouse_type = MouseType.DrawBound;
                            _current_cursor_cache = Cursor = Cursors.Cross;  //特定光标
                            _current_drawing = null;
                            _bScreenshotMenu.Visible = false;
                        }
                        Invalidate();
                    }
                    else
                    {
                        _b_bound = null;
                        _bQuickSearchControl.Visible = false;
                    }
                    return;
                }
                if (new Rectangle(10, 10, 90, 25).Contains(e.Location))  //打开城市切换窗体
                {
                    if (_bCityControl.Visible)
                    {
                        _bCityControl.Visible = false;
                    }
                    else
                    {
                        _bCityControl.Location = new Point(10, 38);
                        _bCityControl.Visible = true;
                        _bCityControl.CurrentCity = _currentCity;
                    }
                    Invalidate();
                    return;
                }
                else if (new Rectangle(Width - 124, 10, 52, 52).Contains(e.Location)) //打开地图加载模式窗体
                {
                    if (_bLoadMapModeControl.Visible)
                    {
                        _bLoadMapModeControl.Visible = false;
                    }
                    else
                    {
                        _bLoadMapModeControl.Location = new Point(Width - 124 + 52 - _bLoadMapModeControl.Width, 10 + 55);
                        _bLoadMapModeControl.LoadMode = _loadmode;
                        _bLoadMapModeControl.Visible = true;
                    }
                    Invalidate();
                    return;
                }
                else if (new Rectangle(Width - 62, 10, 52, 52).Contains(e.Location)) //切换地图模式
                {
                    if (_mode == MapMode.Normal)
                    {
                        if (_chkShowRoadNet.Checked)
                        {
                            Mode = MapMode.Sate_RoadNet;
                        }
                        else
                        {
                            Mode = MapMode.Satellite;
                        }
                        _chkShowRoadNet.Location = new Point(Width - 62, 65);
                        _chkShowRoadNet.Visible = true;
                    }
                    else
                    {
                        Mode = MapMode.Normal;
                        _chkShowRoadNet.Visible = false;
                    }
                    return;
                }


                if (_mouse_type == MouseType.None)  //拖拽地图
                {
                    //判断是否拖拽其他物体 地图优先级最低
                    if (_current_drawing as BScreenShotRectangle != null)  //拖拽截图矩形
                    {
                        if ((_current_drawing as BScreenShotRectangle).Rect.Contains(e.Location))
                        {
                            _mouse_type = MouseType.DragScreenshotArea;
                            _current_cursor_cache = Cursor = Cursors.SizeAll;
                            _previous_point_cache = e.Location;
                            return;
                        }
                    }
                    if (_theStrangePoint != null && _theStrangePoint.Rect.Contains(e.Location)) //是否点击未知点
                    {
                        _current_selected_point = _theStrangePoint;
                        Point point = MapHelper.GetScreenLocationByLatLng(_current_selected_point.Location, _center, _zoom, ClientSize);
                        //信息显示控件
                        _bPointTipControl.BPoint = _current_selected_point;
                        _bPointTipControl.Location = new Point(point.X - _bPointTipControl.Width / 3 + 35, point.Y - _bPointTipControl.Height - _current_selected_point.Rect.Height);
                        _bPointTipControl.Visible = true;
                        return;
                    }
                    if (_theRouteStart !=null && _theRouteStart.Rect.Contains(e.Location)) //是否点击路线起点
                    {
                        _current_selected_point = _theRouteStart;
                        Point point = MapHelper.GetScreenLocationByLatLng(_current_selected_point.Location, _center, _zoom, ClientSize);
                        //信息显示控件
                        _bPointTipControl.BPoint = _current_selected_point;
                        _bPointTipControl.Location = new Point(point.X - _bPointTipControl.Width / 3 + 35, point.Y - _bPointTipControl.Height - _current_selected_point.Rect.Height);
                        _bPointTipControl.Visible = true;                     
                        return;
                    }
                    if (_theRouteEnd != null && _theRouteEnd.Rect.Contains(e.Location)) //是否点击路线终点
                    {
                        _current_selected_point = _theRouteEnd;
                        Point point = MapHelper.GetScreenLocationByLatLng(_current_selected_point.Location, _center, _zoom, ClientSize);
                        //信息显示控件
                        _bPointTipControl.BPoint = _current_selected_point;
                        _bPointTipControl.Location = new Point(point.X - _bPointTipControl.Width / 3 + 35, point.Y - _bPointTipControl.Height - _current_selected_point.Rect.Height);
                        _bPointTipControl.Visible = true;
                        return;
                    }
                    foreach (KeyValuePair<string,BPOI> p in _pois) //是否点击POI点
                    {
                        if (p.Value.Rect.Contains(e.Location))
                        {
                            _current_selected_poi = p.Value;
                            //显示信息控件
                            p.Value.Selected = true;
                            Point point = MapHelper.GetScreenLocationByLatLng(p.Value.Location, _center, _zoom, ClientSize);
                            _bPOITipControl.POI = _current_selected_poi;
                            _bPOITipControl.Location = new Point(point.X - _bPOITipControl.Width / 3 + 35, point.Y - _bPOITipControl.Height - _current_selected_poi.Rect.Height - 5);
                            _bPOITipControl.Visible = true;

                            foreach (KeyValuePair<string, BPOI> pp in _pois)
                            {
                                if (pp.Value != p.Value)
                                {
                                    pp.Value.Selected = false;
                                }
                            }
                            Invalidate();
                            //通知BPlacesBoard  同步选择
                            if (BPlacesBoard != null)
                            {
                                BPlacesBoard.SelectPlace(p.Value);
                            }
                            return;
                        }
                    }
                    foreach (KeyValuePair<string, BMarker> p in _markers) //是否点击标记点
                    {
                        if (p.Value.Rect.Contains(e.Location))
                        {
                            _current_selected_marker = p.Value;
                            //显示标记信息控件
                            Point point = MapHelper.GetScreenLocationByLatLng(p.Value.Location, _center, _zoom, ClientSize);
                            _bMarkerTipControl.Deleted = false;
                            _bMarkerTipControl.Edited = false;
                            _bMarkerTipControl.Marker = _current_selected_marker;
                            _bMarkerTipControl.Location = new Point(point.X - _bMarkerTipControl.Width / 3 + 37, point.Y - _bMarkerTipControl.Height - p.Value.Rect.Height);
                            _bMarkerTipControl.Visible = true;
                            return;
                        }
                    }
                    _bCityControl.Visible = false;
                    _bLoadMapModeControl.Visible = false;
                    _mouse_type = MouseType.DragMap;
                    _current_cursor_cache = Cursor = Cursors.SizeAll;
                    _previous_point_cache = e.Location;
                }
                else if (_mouse_type == MouseType.DrawCircle)  //绘制椭圆
                {
                    LatLngPoint theCenter = MapHelper.GetLatLngByScreenLocation(e.Location, _center, _zoom, ClientSize);
                    _current_drawing = new BCircle { Center = theCenter, RightBottom = theCenter };
                }
                else if (_mouse_type == MouseType.DrawRectange) //绘制矩形
                {
                    LatLngPoint leftTop = MapHelper.GetLatLngByScreenLocation(e.Location, _center, _zoom, ClientSize);
                    _current_drawing = new BRectangle { LeftTop = leftTop, RightBottom = leftTop };
                }
                else if (_mouse_type == MouseType.DrawLine)  //绘制直线
                {
                    LatLngPoint p = MapHelper.GetLatLngByScreenLocation(e.Location, _center, _zoom, ClientSize);
                    if (_current_drawing == null)
                    {
                        _current_drawing = new BLine { Points = new List<LatLngPoint> { p, p } };
                    }
                    (_current_drawing as BLine).Points.Add(p);
                }
                else if (_mouse_type == MouseType.DrawPolygon)  //绘制多边形
                {
                    LatLngPoint p = MapHelper.GetLatLngByScreenLocation(e.Location, _center, _zoom, ClientSize);
                    if (_current_drawing == null)
                    {
                        _current_drawing = new BPolygon { Points = new List<LatLngPoint> { p, p } };
                    }
                    (_current_drawing as BPolygon).Points.Add(p);
                }
                else if (_mouse_type == MouseType.DrawScreenshotArea)  //绘制截图区域
                {
                    _current_drawing = new BScreenShotRectangle { LeftTop = e.Location, Width = 0, Height = 0 };
                }
                else if (_mouse_type == MouseType.DrawBound)  //矩形搜索开始
                {
                    LatLngPoint leftTop = MapHelper.GetLatLngByScreenLocation(e.Location, _center, _zoom, ClientSize);
                    _b_bound = new BBound { LeftTop = leftTop, RightBottom = leftTop };
                }
                else if (_mouse_type == MouseType.DrawDistance) //距离测量
                {
                    LatLngPoint p = MapHelper.GetLatLngByScreenLocation(e.Location, _center, _zoom, ClientSize);
                    if (_b_distance == null)
                    {
                        _b_distance = new BDistance { Points = new List<LatLngPoint> { p, p } };
                    }
                    _b_distance.Points.Add(p);
                }
                else if (_mouse_type == MouseType.DrawMarker) //添加标记
                {
                    LatLngPoint p = MapHelper.GetLatLngByScreenLocation(e.Location, _center, _zoom, ClientSize);
                    ((Action)delegate()
                    {
                        GeocodingService gs = new GeocodingService();
                        JObject place = gs.DeGeocoding(p.Lat + "," + p.Lng);
                        if (place != null)
                        {
                            this.Invoke((Action)delegate()
                            {
                                BMarker marker = new BMarker { Index = _markers.Count, Location = p, Name = (string)place["result"]["formatted_address"], Remarks = "我的备注", Selected = false, Address = (string)place["result"]["formatted_address"] };
                                _markers.Add(marker.Index.ToString(), marker);
                                _bMarkerEditorControl.Saved = false;
                                _bMarkerEditorControl.Marker = marker;
                                _bMarkerEditorControl.Location = new Point(e.Location.X - _bMarkerEditorControl.Width / 3 + 37, e.Location.Y - _bMarkerEditorControl.Height - 22);
                                _bMarkerEditorControl.Visible = true;
                                _current_selected_marker = marker;
                            });
                        }
                    }).BeginInvoke(null, null);
                }
            }
            if (e.Button == System.Windows.Forms.MouseButtons.Right)  //右键弹菜单
            {
                _right_mouse_point_cache = e.Location;
                cm_popup.Show(PointToScreen(e.Location));
            }
        }
示例#3
0
        /// <summary>
        /// 选中地图中的POI
        /// </summary>
        /// <param name="poi"></param>
        internal void SelectBPOI(BPOI poi)
        {
            foreach (KeyValuePair<string, BPOI> p in _pois)
            {
                if (p.Value == poi)
                {
                    p.Value.Selected = true;
                    _current_selected_poi = p.Value;
                    //显示信息控件
                    Point point = MapHelper.GetScreenLocationByLatLng(p.Value.Location, _center, _zoom, ClientSize);
                    _bPOITipControl.POI = _current_selected_poi;
                    _bPOITipControl.Location = new Point(point.X - _bPOITipControl.Width / 3 + 35, point.Y - _bPOITipControl.Height - _current_selected_poi.Rect.Height);
                    _bPOITipControl.Visible = true;

                    //显示在屏幕区域
                    if (!ClientRectangle.Contains(new Rectangle(_bPOITipControl.Left, _bPOITipControl.Top, _bPOITipControl.Width, _bPOITipControl.Height)))
                    {
                        Center = p.Value.Location;
                        Zoom = 13;
                        Locate(false);
                        SyncControlsLocation();
                    }
                }
                else
                {
                    p.Value.Selected = false;
                }
            }
            Invalidate();
        }