/// <summary> /// 添加线 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void AddPolyline(object sender, RoutedEventArgs e) { map.Children.Clear(); APolyline pol = new APolyline(); ObservableCollection <ALngLat> lnglats = new ObservableCollection <ALngLat>(); lnglats.Add(map.Center); lnglats.Add(new ALngLat(map.Center.LngX + 0.02, map.Center.LatY + 0.03)); lnglats.Add(new ALngLat(map.Center.LngX + 0.05, map.Center.LatY + 0.03)); pol.LngLats = lnglats; map.Children.Add(pol); }
private async void BusLineSearchTest(string ids, string cityCode) { BusLineSearchOption rgo = new BusLineSearchOption(); rgo.Ids = ids; rgo.CityCode = cityCode; BusLineSearchResult rgcs = await BusLineSearch.BusLineSearchWithOption(rgo); this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { IEnumerable <BusLine> bl = rgcs.BusLineList; if (rgcs.Erro == null && bl != null) { SearchTextGrid.Visibility = Visibility.Collapsed; ObservableCollection <ALngLat> lnglatRoute = new ObservableCollection <ALngLat>(); //线路坐标 IEnumerable <String> lnglatstring; foreach (BusLine bs in bl) { IEnumerable <Station> ss = bs.StationList; foreach (Station s in ss) { s.Name = s.StationNum + " " + s.Name; } PoiListView.DataContext = ss; lnglatstring = bs.XYs.Split(new Char[] { ';' }); foreach (String ssss in lnglatstring) { String[] lnglatds = ssss.Split(new Char[] { ',' }); lnglatRoute.Add(new ALngLat(Double.Parse(lnglatds[0]), Double.Parse(lnglatds[1]))); } int i = 0; foreach (Station st in ss) { i++; String[] lnglatds = st.XY.Split(new Char[] { ',' }); ALngLat markerlnglat = new ALngLat(Double.Parse(lnglatds[0]), Double.Parse(lnglatds[1])); AMarker poiMarker = new AMarker(); poiMarker.Anchor = new Point(0.5, 0.5); poiMarker.LngLat = markerlnglat; ATip tip = new ATip(); tip.Title = st.Name; tip.ContentText = "站点序号: " + st.StationNum; poiMarker.TipFrameworkElement = tip; markerList.Add(poiMarker); } PoiListView.Visibility = Visible; APolyline pol = new APolyline(); pol.LineThickness = 5; pol.LngLats = lnglatRoute; markLayer.Children.Add(pol); markLayer.SetOverlaysFitView(); try { PoiListView.SelectedIndex = 0; } catch { } } } else { MessageDialog msd = new MessageDialog(rgcs.Erro.Message); this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { msd.ShowAsync(); }); Debug.WriteLine(rgcs.Erro.Message); } }); }
private async void DriveRouteSearchTest(string cityCode, string searchName, string searchEndName) { POISearchOption pst = new POISearchOption(); pst.SearchName = searchName; pst.CityCode = cityCode; POISearchOption ped = new POISearchOption(); ped.SearchName = searchEndName; ped.CityCode = cityCode; POISearchResult iopStart = await POISearch.PoiSearchWithOption(pst); //查起点坐标 POISearchResult iopEnd = await POISearch.PoiSearchWithOption(ped); //查终点坐标 if (iopStart.Erro != null || iopStart.POIs == null) { MessageDialog msd = new MessageDialog(iopStart.Erro.Message); this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { msd.ShowAsync(); }); return; } if (iopEnd.Erro != null || iopEnd.POIs == null) { MessageDialog msd = new MessageDialog(iopStart.Erro.Message); this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { msd.ShowAsync(); }); return; } POI poist = Enumerable.First <POI>(iopStart.POIs); POI poied = Enumerable.First <POI>(iopEnd.POIs); RouteSearchOption rgo = new RouteSearchOption(); rgo.X1 = poist.X; rgo.Y1 = poist.Y; rgo.X2 = poied.X; rgo.Y2 = poied.Y; RouteSearchResult rgcs = await RouteSearch.RouteSearchWithOption(rgo); if (rgcs.Erro != null) { MessageDialog msd = new MessageDialog("查询公交失败!" + rgcs.Erro.Message, "提示"); this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { msd.ShowAsync(); }); return; } else { this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { ALngLat lnglatst = new ALngLat(poist.X, poist.Y); AMarker poiMarkerst = new AMarker(); poiMarkerst.IconURI = new Uri("/Samples/qd.png", UriKind.Relative); poiMarkerst.LngLat = lnglatst; ATip tipst = new ATip(); tipst.Title = poist.Name; tipst.ContentText = poist.Address; poiMarkerst.TipFrameworkElement = tipst; map.Children.Add(poiMarkerst); ALngLat lnglated = new ALngLat(poied.X, poied.Y); AMarker poiMarkered = new AMarker(); poiMarkered.IconURI = new Uri("/Samples/zd.png", UriKind.Relative); poiMarkered.LngLat = lnglated; ATip tiped = new ATip(); tiped.Title = poied.Name; tiped.ContentText = poied.Address; poiMarkered.TipFrameworkElement = tiped; map.Children.Add(poiMarkered); APolyline pol = new APolyline(); pol.LineThickness = 5; ObservableCollection <ALngLat> lnglatRoute = new ObservableCollection <ALngLat>(); //线路坐标 IEnumerable <String> lnglatstring; IEnumerable <RouteSegment> rsegment = rgcs.Segment; foreach (RouteSegment rs in rsegment) { lnglatstring = rs.Coor.Split(new Char[] { ';' }); foreach (String ss in lnglatstring) { String[] lnglatds = ss.Split(new Char[] { ',' }); lnglatRoute.Add(new ALngLat(Double.Parse(lnglatds[0]), Double.Parse(lnglatds[1]))); } } pol.LngLats = lnglatRoute; markLayer.Children.Add(pol); map.SetOverlaysFitView(); }); } }
private async void busroute() { markLayer.Children.Clear(); BusRouteSearchOption rgo = new BusRouteSearchOption(); rgo.X1 = marker.LngLat.LngX; rgo.Y1 = marker.LngLat.LatY; rgo.X2 = marker2.LngLat.LngX; rgo.Y2 = marker2.LngLat.LatY; rgo.CityCode = "010"; APolyline pol = new APolyline(); pol.LineThickness = 5; ObservableCollection<ALngLat> lnglatRoute = new ObservableCollection<ALngLat>(); //线路坐标 lnglatRoute.Add(new ALngLat(marker.LngLat.LngX, marker.LngLat.LatY)); BusRouteSearchResult rgcs = await BusRouteSearch.BusRouteSearchWithOption(rgo); if (rgcs.Erro != null) { MessageDialog msd = new MessageDialog("查询公交失败!" + rgcs.Erro.Message, "提示"); this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { msd.ShowAsync(); }); return; } else { this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { ALngLat lnglat = new ALngLat(marker.LngLat.LngX, marker.LngLat.LatY); AMarker poiMarker = new AMarker(); poiMarker.IconURI = new Uri("/Samples/qd.png", UriKind.Relative); poiMarker.LngLat = lnglat; //ATip tip = new ATip(); //tip.Title = poist.Name; //tip.ContentText = poist.Address; //poiMarker.TipFrameworkElement = tip; markLayer.Children.Add(poiMarker); ALngLat lnglated = new ALngLat(marker2.LngLat.LngX, marker2.LngLat.LatY); AMarker poiMarkered = new AMarker(); poiMarkered.IconURI = new Uri("/Samples/zd.png", UriKind.Relative); poiMarkered.LngLat = lnglated; //ATip tiped = new ATip(); /*tiped.Title = poied.Name; tiped.ContentText = poied.Address;*/ //poiMarkered.TipFrameworkElement = tiped; markLayer.Children.Add(poiMarkered); //ObservableCollection<ALngLat> lnglatRoute = new ObservableCollection<ALngLat>(); //线路坐标 //APolyline pol = new APolyline(); //pol.LineThickness = 5; IEnumerable<Bus> busInfo = rgcs.Routes; IEnumerable<String> lnglatstring; IEnumerable<String> passdeportstring; //画公交线路和公交站点 foreach (Bus bus in busInfo) { IEnumerable<BusSegment> bussegmentInfo = bus.SegmentArray; foreach (BusSegment bs in bussegmentInfo) { lnglatstring = bs.CoordinateList.Split(new Char[] { ';' }); passdeportstring = bs.PassDeportCoordinate.Split(new Char[] { ';' }); String[] passport = bs.PassDeportName.Split(' '); int i = 0; foreach (String ss in lnglatstring) { String[] lnglatds = ss.Split(new Char[] { ',' }); lnglatRoute.Add(new ALngLat(Double.Parse(lnglatds[0]), Double.Parse(lnglatds[1]))); } foreach (String ss in passdeportstring) { String[] lnglatds = ss.Split(new Char[] { ',' }); try { ALngLat lnglatpassdeport = new ALngLat(Double.Parse(lnglatds[0]), Double.Parse(lnglatds[1])); ATip tipStart = new ATip(); //tipStart.Anchor = new Point(0,1); tipStart.Title = passport[i]; AMarker marker3 = new AMarker(); marker3.Anchor = new Point(0.46, 1); marker3.IconURI = new Uri("http://api.amap.com/webapi/static/Images/bx11.png"); marker3.LngLat = lnglatpassdeport; marker3.TipFrameworkElement = tipStart; markLayer.Children.Add(marker3); // Canvas.SetTop(marker,100); marker3.TipAnchor = new Point(0.35, 1); } catch (Exception e) { MessageDialog msg = new MessageDialog("无法找到站牌"); msg.ShowAsync(); } } } break; } pol.LngLats = lnglatRoute; markLayer.Children.Insert(0, pol); map.SetOverlaysFitView(); }); } }
private async void driveroute() { RouteSearchOption rgo = new RouteSearchOption(); rgo.X1 = marker.LngLat.LngX; rgo.Y1 = marker.LngLat.LatY; rgo.X2 = marker2.LngLat.LngX; rgo.Y2 = marker2.LngLat.LatY; APolyline pol = new APolyline(); pol.LineThickness = 5; ObservableCollection<ALngLat> lnglatRoute = new ObservableCollection<ALngLat>(); //线路坐标 lnglatRoute.Add(new ALngLat(marker.LngLat.LngX, marker.LngLat.LatY)); RouteSearchResult rgcs = await RouteSearch.RouteSearchWithOption(rgo); IEnumerable<String> lnglatstring; IEnumerable<RouteSegment> rsegment = rgcs.Segment; foreach (RouteSegment rs in rsegment) { lnglatstring = rs.Coor.Split(new Char[] { ';' }); foreach (String ss in lnglatstring) { String[] lnglatds = ss.Split(new Char[] { ',' }); lnglatRoute.Add(new ALngLat(Double.Parse(lnglatds[0]), Double.Parse(lnglatds[1]))); } } pol.LngLats = lnglatRoute; markLayer.Children.Clear(); markLayer.Children.Add(pol); map.SetOverlaysFitView(); //map.SetZoomAndCenter(Convert.ToInt32(marker2.LngLat.LngX-marker.LngLat.LngX),map.Center); }
private async void BusRouteSearchTest(string cityCode, string searchName, string searchEndName) { POISearchOption ps = new POISearchOption(); ps.SearchName = searchName; ps.CityCode = cityCode; POISearchOption pe = new POISearchOption(); pe.SearchName = searchEndName; pe.CityCode = cityCode; POISearchResult iopStart = await POISearch.PoiSearchWithOption(ps); //查询起点坐标 POISearchResult iopEnd = await POISearch.PoiSearchWithOption(pe); //查询终点坐标 if (iopEnd.Erro != null || iopEnd.POIs == null) { MessageDialog msd = new MessageDialog(iopStart.Erro.Message); this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { msd.ShowAsync(); }); return; } POI poist = Enumerable.First <POI>(iopStart.POIs); POI poied = Enumerable.First <POI>(iopEnd.POIs); BusRouteSearchOption rgo = new BusRouteSearchOption(); rgo.X1 = poist.X; rgo.Y1 = poist.Y; rgo.X2 = poied.X; rgo.Y2 = poied.Y; rgo.CityCode = cityCode; BusRouteSearchResult rgcs = await BusRouteSearch.BusRouteSearchWithOption(rgo);//根据起点重点坐标查公交 if (rgcs.Erro != null) { MessageDialog msd = new MessageDialog("查询公交失败!" + rgcs.Erro.Message, "提示"); this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { msd.ShowAsync(); }); return; } else { this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { markLayer.Children.Clear(); ALngLat lnglat = new ALngLat(poist.X, poist.Y); AMarker poiMarker = new AMarker(); poiMarker.IconURI = new Uri("/Samples/qd.png", UriKind.Relative); poiMarker.LngLat = lnglat; ATip tip = new ATip(); tip.Title = poist.Name; tip.ContentText = poist.Address; poiMarker.TipFrameworkElement = tip; markLayer.Children.Add(poiMarker); ALngLat lnglated = new ALngLat(poied.X, poied.Y); AMarker poiMarkered = new AMarker(); poiMarkered.IconURI = new Uri("/Samples/zd.png", UriKind.Relative); poiMarkered.LngLat = lnglated; ATip tiped = new ATip(); tiped.Title = poied.Name; tiped.ContentText = poied.Address; poiMarkered.TipFrameworkElement = tiped; markLayer.Children.Add(poiMarkered); ObservableCollection <ALngLat> lnglatRoute = new ObservableCollection <ALngLat>(); //线路坐标 APolyline pol = new APolyline(); pol.LineThickness = 5; IEnumerable <Bus> busInfo = rgcs.Routes; IEnumerable <String> lnglatstring; IEnumerable <String> passdeportstring; //画公交线路和公交站点 foreach (Bus bus in busInfo) { IEnumerable <BusSegment> bussegmentInfo = bus.SegmentArray; foreach (BusSegment bs in bussegmentInfo) { lnglatstring = bs.CoordinateList.Split(new Char[] { ';' }); passdeportstring = bs.PassDeportCoordinate.Split(new Char[] { ';' }); String[] passport = bs.PassDeportName.Split(' '); int i = 0; foreach (String ss in lnglatstring) { String[] lnglatds = ss.Split(new Char[] { ',' }); lnglatRoute.Add(new ALngLat(Double.Parse(lnglatds[0]), Double.Parse(lnglatds[1]))); } foreach (String ss in passdeportstring) { String[] lnglatds = ss.Split(new Char[] { ',' }); ALngLat lnglatpassdeport = new ALngLat(Double.Parse(lnglatds[0]), Double.Parse(lnglatds[1])); ATip tipStart = new ATip(); // tipStart.Anchor = new Point(0,1); tipStart.Title = passport[i]; AMarker marker = new AMarker(); marker.Anchor = new Point(0.46, 1); marker.IconURI = new Uri("http://api.amap.com/webapi/static/Images/bx11.png"); marker.LngLat = lnglatpassdeport; marker.TipFrameworkElement = tipStart; markLayer.Children.Add(marker); // Canvas.SetTop(marker,100); marker.TipAnchor = new Point(0.35, 1); } } break; } pol.LngLats = lnglatRoute; markLayer.Children.Insert(0, pol); map.SetOverlaysFitView(); }); } }