Exemplo n.º 1
0
 /// <summary>
 /// 位置点信息显示控件关闭
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void _bPointTipControl_VisibleChanged(object sender, EventArgs e)
 {
     if (!_bPointTipControl.Visible)
     {
         _current_selected_point = _theStrangePoint = null;
     }
 }
Exemplo n.º 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));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 选中地图中的位置点
        /// </summary>
        /// <param name="bpoint"></param>
        internal void SelectBPoint(BPoint bpoint)
        {
            if (_theRouteEnd == bpoint)
            {
                _theRouteEnd.Selected = true;
                //
                _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;

                if (!ClientRectangle.Contains(new Rectangle(_bPointTipControl.Left, _bPointTipControl.Top, _bPointTipControl.Width, _bPointTipControl.Height)))
                {
                    Center = _theRouteEnd.Location;
                    Zoom = 15;
                    Locate(false);
                    SyncControlsLocation();
                }
            }
            else if (_theRouteStart == bpoint)
            {
                _theRouteStart.Selected = true;
                //
                _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;

                if (!ClientRectangle.Contains(new Rectangle(_bPointTipControl.Left, _bPointTipControl.Top, _bPointTipControl.Width, _bPointTipControl.Height)))
                {
                    Center = _theRouteStart.Location;
                    Zoom = 15;
                    Locate(false);
                    SyncControlsLocation();
                }
            }
            Invalidate();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 右键菜单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cm_popup_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item = sender as ToolStripMenuItem;
            if(item.Name == "cmsWhere")  //这是哪里
            {
                LatLngPoint location = MapHelper.GetLatLngByScreenLocation(_right_mouse_point_cache, _center, _zoom, ClientSize);
                ((Action)delegate()
                {
                    GeocodingService gs = new GeocodingService();
                    JObject point = gs.DeGeocoding(location.Lat + "," + location.Lng); 
                    if (point != null) //具体json格式参见api文档
                    {
                        this.Invoke((Action)delegate()
                        {
                            _current_selected_point = _theStrangePoint = new BPoint { Type = PointType.Strange, Selected = true, Address = (string)point["result"]["formatted_address"], Location = location };
                            _bPointTipControl.BPoint = _theStrangePoint;
                            _bPointTipControl.Location = new Point(_right_mouse_point_cache.X - _bPointTipControl.Width / 3 + 37, _right_mouse_point_cache.Y - _bPointTipControl.Height - 34);
                            _bPointTipControl.Visible = true;
                        });
                    }
                }).BeginInvoke(null, null);
            }
            else if (item.Name == "cmsSetStart")  //设为起点
            {
                LatLngPoint location = MapHelper.GetLatLngByScreenLocation(_right_mouse_point_cache, _center, _zoom, ClientSize);
                ((Action)delegate()
                {
                    GeocodingService gs = new GeocodingService();
                    JObject point = gs.DeGeocoding(location.Lat + "," + location.Lng);
                    if (point != null) //具体json格式参见api文档
                    {
                        this.Invoke((Action)delegate()
                        {
                            _current_selected_point = _theRouteStart = new BPoint { Type = PointType.RouteStart, Selected = true, Address = (string)point["result"]["formatted_address"], Location = location };
                            _bPointTipControl.BPoint = _theRouteStart;
                            _bPointTipControl.Location = new Point(_right_mouse_point_cache.X - _bPointTipControl.Width / 3 + 37, _right_mouse_point_cache.Y - _bPointTipControl.Height - 34);
                            _bPointTipControl.Visible = true;

                            BDirectionBoard.SourcePlace = _theRouteStart.Address;
                        });
                    }
                }).BeginInvoke(null, null);
            }
            else if (item.Name == "cmsSetEnd")  //设为终点
            {
                LatLngPoint location = MapHelper.GetLatLngByScreenLocation(_right_mouse_point_cache, _center, _zoom, ClientSize);
                ((Action)delegate()
                {
                    GeocodingService gs = new GeocodingService();
                    JObject point = gs.DeGeocoding(location.Lat + "," + location.Lng);
                    if (point != null) //具体json格式参见api文档
                    {
                        this.Invoke((Action)delegate()
                        {
                            _current_selected_point = _theRouteEnd = new BPoint { Type = PointType.RouteEnd, Selected = true, Address = (string)point["result"]["formatted_address"], Location = location };
                            _bPointTipControl.BPoint = _theRouteEnd;
                            _bPointTipControl.Location = new Point(_right_mouse_point_cache.X - _bPointTipControl.Width / 3 + 37, _right_mouse_point_cache.Y - _bPointTipControl.Height - 34);
                            _bPointTipControl.Visible = true;

                            BDirectionBoard.DestinationPlace = _theRouteEnd.Address;
                        });
                    }
                }).BeginInvoke(null, null);
            }
            else if (item.Name == "cmsCenter") //居中
            {
                LatLngPoint lp = MapHelper.GetLatLngByScreenLocation(PointToClient(Cursor.Position), _center, _zoom, ClientSize);
                Center = lp;
                Locate(false);
                SyncControlsLocation();
            }
            else if (item.Name == "cmsLarge") //放大
            {
                int z = _zoom + 1;
                if (z >= 3 && z <= 19)
                {
                    Zoom = z;
                    Locate(false);
                    SyncControlsLocation();
                }
            }
            else if (item.Name == "cmsSmall") //缩小
            {
                int z = _zoom - 1;
                if (z >= 3 && z <= 19)
                {
                    Zoom = z;
                    Locate(false);
                    SyncControlsLocation();
                }
            }
            else if (item.Name == "cmsClearDrawings") //清空绘图
            {
                _drawingObjects.Clear();
            }
            else if (item.Name == "cmsClearMarkers") //清空标记
            {
                _markers.Clear();
            }
            else if (item.Name == "cmsRegionSaveAs") //可视区域另存为
            {
                using (SaveFileDialog sf = new SaveFileDialog())
                {
                    sf.CheckPathExists = true;
                    sf.Filter = "PNG文件(*.png)|*.png";
                    sf.DefaultExt = ".png";
                    if (sf.ShowDialog() == DialogResult.OK)
                    {
                        Bitmap b = new Bitmap(Width, Height);
                        this.DrawToBitmap(b, ClientRectangle);
                        b.Save(sf.FileName);
                    }
                }
            }
            Invalidate();
        }
Exemplo n.º 5
0
 /// <summary>
 /// 设置地图中路线起点、终点(可以设为null表示清空)
 /// </summary>
 /// <param name="start"></param>
 /// <param name="end"></param>
 internal void SetRouteStartAndEnd(BPoint start, BPoint end)
 {
     _theRouteStart = start;
     _theRouteEnd = end;
     Invalidate();
 }
Exemplo n.º 6
0
 /// <summary>
 /// 起点选中
 /// </summary>
 /// <param name="bPoint"></param>
 void Origin_StepEndPointSelected(BPoint bPoint)
 {
     if (StepEndPointSelected != null)
     {
         StepEndPointSelected(bPoint);
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// 终点选中
 /// </summary>
 /// <param name="bPoint"></param>
 void Destination_StepEndPointSelected(BPoint bPoint)
 {
     if (StepEndPointSelected != null)
     {
         StepEndPointSelected(bPoint);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// 开启搜索
        /// </summary>
        internal void StartSearch()
        {
            flpRoutes.Controls.Clear();
            if (BMapControl != null)
            {
                BMapControl.SetRoute(null); //
                BMapControl.SetRouteStartAndEnd(null, null);
            }
            if (BPlacesBoard != null) //位置列表初始化
            {
                BPlacesBoard.Clear();
            }
            _wait.Visible = true; //等待
            ((Action)delegate()
            {
                JObject routes;
                DirectionService ds = new DirectionService();
                if (_current_method == 0) //公交
                {
                    if (bPlaceBoxSource.City != "" && bPlaceBoxDestination.City != "" && bPlaceBoxSource.City != bPlaceBoxDestination.City)
                    {
                        MessageBox.Show("公交导航时,两地城市必须一致!");
                        return;
                    }
                    routes = ds.DirectionByTransit(bPlaceBoxSource.QueryText, bPlaceBoxDestination.QueryText, _currentCity);
                }
                else if (_current_method == 1) //驾车
                {
                    routes = ds.DirectionByDriving(bPlaceBoxSource.QueryText, bPlaceBoxDestination.QueryText, bPlaceBoxSource.City == "" ? bPlaceBoxSource.CurrentCity : bPlaceBoxSource.City
                        , bPlaceBoxDestination.City == "" ? bPlaceBoxDestination.CurrentCity : bPlaceBoxDestination.City);
                }
                else //步行
                {
                    if (bPlaceBoxSource.City != "" && bPlaceBoxDestination.City != "" && bPlaceBoxSource.City != bPlaceBoxDestination.City)
                    {
                        MessageBox.Show("步行导航时,两地城市必须一致!");
                        return;
                    }
                    routes = ds.DirectionByWalking(bPlaceBoxSource.QueryText, bPlaceBoxDestination.QueryText, _currentCity);
                }
                if (routes != null && (string)routes["status"] == "0") //搜索成功
                {
                    this.Invoke((Action)delegate()
                    {
                        _wait.Visible = false;
                        if ((string)routes["type"] == "2") //正常结果
                        {
                            //生成起点终点
                            BPoint start = new BPoint { Type = PointType.RouteStart, Selected = false, Address = bPlaceBoxSource.QueryText, Location = new LatLngPoint(double.Parse((string)routes["result"]["origin"]["originPt"]["lng"]), double.Parse((string)routes["result"]["origin"]["originPt"]["lat"])) };
                            BPoint end = new BPoint { Type = PointType.RouteEnd, Selected = false, Address = bPlaceBoxDestination.QueryText, Location = new LatLngPoint(double.Parse((string)routes["result"]["destination"]["destinationPt"]["lng"]), double.Parse((string)routes["result"]["destination"]["destinationPt"]["lat"])) };
                            if (BMapControl != null)
                            {
                                BMapControl.SetRouteStartAndEnd(start, end); //设置地图中对应的起点 终点
                            } 
                            if (_current_method == 0) //公交
                            {
                                BTaxiTipControl taxi = new BTaxiTipControl();
                                taxi.DataSource = routes["result"]["taxi"]; //打车信息
                                taxi.Width = flpRoutes.Width - 25;
                                flpRoutes.Controls.Add(taxi);
                                foreach (JObject route in routes["result"]["routes"])
                                {
                                    BTransitRouteItem item = new BTransitRouteItem();

                                    BStepStartAndEndItem origin = new BStepStartAndEndItem();
                                    origin.EndPoint = start;                             
                                    item.Origin = origin; //起点

                                    BStepStartAndEndItem destination = new BStepStartAndEndItem();
                                    destination.EndPoint = end;
                                    item.Destination = destination; //终点

                                    item.DataSource = new BRoute { Type = RouteType.Transit, DataSource = route };
                                    flpRoutes.Controls.Add(item);
                                    item.Width = flpRoutes.Width - 25;

                                    item.StepEndPointSelected += new StepEndPointSelectedEventHandler(item_StepEndPointSelected);
                                    item.StepSelected += new StepSelectedEventHandler(item_StepSelected);
                                    item.RouteSelected += new RouteSelectedEventHandler(item_RouteSelected);
                                }
                            }
                            else if (_current_method == 1) //驾车
                            {
                                BTaxiTipControl taxi = new BTaxiTipControl();
                                taxi.DataSource = routes["result"]["taxi"]; //打车信息
                                taxi.Width = flpRoutes.Width - 25;
                                flpRoutes.Controls.Add(taxi);
                                foreach (JObject route in routes["result"]["routes"])
                                {
                                    BDrivingRouteItem item = new BDrivingRouteItem();

                                    BStepStartAndEndItem origin = new BStepStartAndEndItem();
                                    origin.EndPoint = start;
                                    item.Origin = origin; //起点

                                    BStepStartAndEndItem destination = new BStepStartAndEndItem();
                                    destination.EndPoint = end;
                                    item.Destination = destination; //终点

                                    item.DataSource = new BRoute { DataSource = route, Type = RouteType.Driving };
                                    flpRoutes.Controls.Add(item);
                                    item.Width = flpRoutes.Width - 25;

                                    item.StepEndPointSelected += new StepEndPointSelectedEventHandler(item_StepEndPointSelected);
                                    item.StepSelected += new StepSelectedEventHandler(item_StepSelected);
                                    item.RouteSelected += new RouteSelectedEventHandler(item_RouteSelected);
                                }
                            }
                            else  //步行
                            {
                                //步行没有打车信息
                                foreach (JObject route in routes["result"]["routes"])
                                {
                                    BWalkingRouteItem item = new BWalkingRouteItem();

                                    BStepStartAndEndItem origin = new BStepStartAndEndItem();
                                    origin.EndPoint = start;
                                    item.Origin = origin; //起点

                                    BStepStartAndEndItem destination = new BStepStartAndEndItem();
                                    destination.EndPoint = end;
                                    item.Destination = destination; //终点

                                    item.DataSource = new BRoute { DataSource = route, Type = RouteType.Walking };
                                    flpRoutes.Controls.Add(item);
                                    item.Width = flpRoutes.Width - 25;

                                    item.StepEndPointSelected += new StepEndPointSelectedEventHandler(item_StepEndPointSelected);
                                    item.StepSelected += new StepSelectedEventHandler(item_StepSelected);
                                    item.RouteSelected += new RouteSelectedEventHandler(item_RouteSelected);
                                }
                            }
                        }
                        else //地址模糊 需重新选择  具体json格式参见api文档
                        {
                            //
                            string start_keyword = (string)routes["result"]["originInfo"]["wd"];
                            string end_keyword = (string)routes["result"]["destinationInfo"]["wd"];
                            Label l = new Label();
                            l.AutoSize = false;
                            l.ForeColor = Color.Red;
                            l.Width = flpRoutes.Width - 25; l.Height = 20;
                            l.TextAlign = ContentAlignment.MiddleCenter;
                            l.Text = "请选择准确的位置";
                            flpRoutes.Controls.Add(l);
                            if (routes["result"]["origin"] != null) //起点模糊
                            {
                                if (routes["result"]["origin"] is JArray) //公交
                                {
                                    BPlacesSuggestionControl sugg_start = new BPlacesSuggestionControl();
                                    sugg_start.Type = PointType.RouteStart;
                                    sugg_start.KeyWord = start_keyword;
                                    sugg_start.Content = routes["result"]["origin"];
                                    sugg_start.Width = flpRoutes.Width - 25;
                                    sugg_start.EndPointSelected += new EndPointSelectedEventHandler(sugg_start_EndPointSelected);
                                    flpRoutes.Controls.Add(sugg_start);
                                }
                                else //驾车 步行
                                {
                                    BPlacesSuggestionControl sugg_start = new BPlacesSuggestionControl();
                                    sugg_start.Type = PointType.RouteStart;
                                    sugg_start.KeyWord = start_keyword;
                                    sugg_start.Content = routes["result"]["origin"]["content"];
                                    sugg_start.Width = flpRoutes.Width - 25;
                                    sugg_start.EndPointSelected += new EndPointSelectedEventHandler(sugg_start_EndPointSelected);
                                    flpRoutes.Controls.Add(sugg_start);
                                }
                            }
                            if (routes["result"]["destination"] != null) //终点模糊
                            {
                                if (routes["result"]["destination"] is JArray) //公交
                                {
                                    BPlacesSuggestionControl sugg_end = new BPlacesSuggestionControl();
                                    sugg_end.Type = PointType.RouteEnd;
                                    sugg_end.KeyWord = end_keyword;
                                    sugg_end.Content = routes["result"]["destination"];
                                    sugg_end.Width = flpRoutes.Width - 25;
                                    sugg_end.EndPointSelected += new EndPointSelectedEventHandler(sugg_end_EndPointSelected);
                                    flpRoutes.Controls.Add(sugg_end);
                                }
                                else
                                {
                                    BPlacesSuggestionControl sugg_end = new BPlacesSuggestionControl();
                                    sugg_end.Type = PointType.RouteEnd;
                                    sugg_end.KeyWord = end_keyword;
                                    sugg_end.Content = routes["result"]["destination"]["content"];
                                    sugg_end.Width = flpRoutes.Width - 25;
                                    sugg_end.EndPointSelected += new EndPointSelectedEventHandler(sugg_end_EndPointSelected);
                                    flpRoutes.Controls.Add(sugg_end);
                                }
                            }
                        }
                    });
                }
            }).BeginInvoke(null, null);
        }
Exemplo n.º 9
0
 /// <summary>
 /// 路线起点终点选中
 /// </summary>
 /// <param name="bPoint"></param>
 void item_StepEndPointSelected(BPoint bPoint)
 {
     //
     if (BMapControl != null)
     {
         BMapControl.SelectBPoint(bPoint);
     }
 }