示例#1
0
 /// <summary>
 /// 路线步骤选中
 /// </summary>
 /// <param name="stepPath"></param>
 /// <param name="enlarge"></param>
 void item_StepSelected(string stepPath, bool enlarge)
 {
     if (BMapControl != null)
     {
         BMapControl.SetHighlightPath(stepPath, enlarge); //高亮设置
     }
 }
示例#2
0
 /// <summary>
 /// 路线起点终点选中
 /// </summary>
 /// <param name="bPoint"></param>
 void item_StepEndPointSelected(BPoint bPoint)
 {
     //
     if (BMapControl != null)
     {
         BMapControl.SelectBPoint(bPoint);
     }
 }
示例#3
0
 /// <summary>
 /// 清空所有位置(初始化控件)
 /// </summary>
 public void Clear()
 {
     flpPlaces.Controls.Clear();           //清空所有位置
     flpPlaces.Controls.Add(bQuickSearch); //重新加载快速搜索控件
     if (BMapControl != null)
     {
         BMapControl.ClearPlaces();
     }
 }
示例#4
0
 /// <summary>
 /// 清空导航控件(初始化)
 /// </summary>
 public void Clear()
 {
     flpRoutes.Controls.Clear();
     if (BMapControl != null)
     {
         BMapControl.SetRoute(null); //
         BMapControl.SetRouteStartAndEnd(null, null);
     }
 }
示例#5
0
 /// <summary>
 /// 选中位置改变
 /// </summary>
 /// <param name="poi"></param>
 void item_PlaceSelectedChanged(BPOI poi)
 {
     //BMapControl
     foreach (Control c in flpPlaces.Controls)
     {
         if (c is BPlaceItem && (c as BPlaceItem).POI != poi)
         {
             (c as BPlaceItem).Selected = false;
         }
     }
     if (BMapControl != null)
     {
         BMapControl.SelectBPOI(poi);
     }
 }
示例#6
0
        /// <summary>
        /// 将位置显示在列表中
        /// </summary>
        /// <param name="places"></param>
        internal void AddPlaces(JToken places)
        {
            flpPlaces.Controls.Clear();              //清空原来所有位置
            if (Parent != null && Parent is TabPage) //如果父控件是tabpage 则选中
            {
                ((Parent as TabPage).Parent as TabControl).SelectedTab = (Parent as TabPage);
            }
            if (BDirectionBoard != null) //导航控件初始化
            {
                BDirectionBoard.Clear();
            }

            //加载位置项
            int index = 0; List <BPOI> _list = new List <BPOI>();

            foreach (JObject place in places)
            {
                if (place["location"] != null && place["location"]["lng"] != null && (string)place["location"]["lng"] != "")
                {
                    LatLngPoint location = new LatLngPoint(double.Parse((string)place["location"]["lng"]), double.Parse((string)place["location"]["lat"]));
                    BPOI        poi      = new BPOI {
                        DataSource = place, Index = index, Selected = false, Location = location
                    };
                    _list.Add(poi);

                    BPlaceItem item = new BPlaceItem();
                    item.Index = index++;
                    item.POI   = poi;
                    item.SetDestinationPlace  += new SetDestinationPlaceEventHandler(item_SetDestinationPlace);
                    item.SetSourcePlace       += new SetSourcePlaceEventHandler(item_SetSourcePlace);
                    item.PlaceSelectedChanged += new PlaceSelectedChangedEventHandler(item_PlaceSelectedChanged);
                    item.Height = 104;
                    flpPlaces.Controls.Add(item);
                }
            }
            if (BMapControl != null)
            {
                BMapControl.AddPlaces(_list);
            }
        }
示例#7
0
 /// <summary>
 /// 路线选中
 /// </summary>
 /// <param name="bRoute"></param>
 void item_RouteSelected(BRoute bRoute)
 {
     foreach (Control c in flpRoutes.Controls)
     {
         if (c as BTransitRouteItem != null && (c as BTransitRouteItem).DataSource != bRoute)
         {
             (c as BTransitRouteItem).Selected = false;
         }
         if (c as BWalkingRouteItem != null && (c as BWalkingRouteItem).DataSource != bRoute)
         {
             (c as BWalkingRouteItem).Selected = false;
         }
         if (c as BDrivingRouteItem != null && (c as BDrivingRouteItem).DataSource != bRoute)
         {
             (c as BDrivingRouteItem).Selected = false;
         }
     }
     if (BMapControl != null)
     {
         BMapControl.SetRoute(bRoute); //更新地图中的路线
     }
 }
示例#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;
                DirectionV1Service ds = new DirectionV1Service();
                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);
        }