/// <summary> /// 注意:要开启定位权限 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void LocateClick(object sender, RoutedEventArgs e) { var aMapGeolocator = new AMapGeolocator(); LngLat myLngLat = await aMapGeolocator.GetLngLatAsync(); var icon = new AMapIcon { Location = myLngLat }; baseLayer.Add(icon); await aMapControl.TrySetViewAsync(myLngLat, 15, 0, 0, AMapAnimationKind.Default); }
private void MapIcon_Click(object sender, RoutedEventArgs e) { aMapIcon = new AMapIcon { Image = RandomAccessStreamReference.CreateFromUri(new Uri( "ms-appx:///Assets/AZURE.png", UriKind.RelativeOrAbsolute)), Location = aMapControl.Center, NormalizedAnchorPoint = new Point(0.5, 1), }; baseLayer.Add(aMapIcon); }
private async void Walk_OnClick(object sender, RoutedEventArgs e) { baseLayer.Clear(); var man = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/man.png", UriKind.RelativeOrAbsolute)); AMapRouteResults rts = await AMapNavigationSearch.WalkingNavigation(start.Longitude, start.Latitude, end.Longitude, end.Latitude, 0); if (rts.Erro == null) { if (rts.Count == 0) { Debug.WriteLine("无查询结果"); return; } AMapRoute route = rts.Route; List <AMapPath> paths = route.Paths.ToList(); foreach (AMapPath item in paths) { Debug.WriteLine("起点终点距离:" + item.Distance); Debug.WriteLine("预计耗时:" + item.Duration / 60 + "分钟"); Debug.WriteLine("导航策略:" + item.Strategy); //画路线 List <AMapStep> steps = item.Steps.ToList(); foreach (AMapStep st in steps) { var icon = new AMapIcon { Location = LngLatsFromString(st.Polyline).FirstOrDefault(), Image = man }; Debug.WriteLine(st.Instruction); var polyline = new AMapPolyline { Path = new AGeopath(LngLatsFromString(st.Polyline)) }; await baseLayer.Add(icon); await baseLayer.Add(polyline); } } } else { Debug.WriteLine(rts.Erro.Message); } }
private async void AddLayerContainIcons(object sender, RoutedEventArgs e) { var layer = new AMapLayer(); RandomAccessStreamReference rsa = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/man.png", UriKind.RelativeOrAbsolute)); for (int i = 0; i < 1000; i++) { var icon = new AMapIcon { //Image = // RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/man.png", // UriKind.RelativeOrAbsolute)), Image = rsa, Location = new LngLat(116.394653 + i * 0.01, 39.911843 + i * 0.01), }; await layer.Add(icon); } aMapControl.Layers.Add(layer); }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { AMapPolyline line = new AMapPolyline(); pointsOfLine = new[] { new LngLat(116.48236, 39.987326), new LngLat(116.450712, 39.93041) }; line.Path = new AGeopath(pointsOfLine); line.StrokeColor = Colors.Red; baseLayer.Add(line); AMapPolygon rectRectangle = new AMapPolygon(); pointsOfRect = new[] { new LngLat(116.438764, 39.96041), new LngLat(116.438764, 39.963728), new LngLat(116.453712, 39.963728), new LngLat(116.453712, 39.96041) }; rectRectangle.Path = new AGeopath(pointsOfRect); baseLayer.Add(rectRectangle); }
private async void IdSearch_OnClick(object sender, RoutedEventArgs e) { baselayer.Clear(); aMapControl.HideInfoWindow(); string id = "B000A07060"; AMapPOIResults results = await AMapPOISearch.POIID(id); if (results.Erro == null) { if (results.POIList == null || results.POIList.Count == 0) { Debug.WriteLine("无查询结果"); return; } foreach (AMapPOI item in results.POIList) { var icon = new AMapIcon { Location = new LngLat(item.Location.Lon, item.Location.Lat) }; icon.Tapped += icon_Tapped; icon.Data = item.Address; await baselayer.Add(icon); } aMapControl.TrySetViewAsync( new LngLat(results.POIList[0].Location.Lon, results.POIList[0].Location.Lat), null, null, null, AMapAnimationKind.Default); } else { Debug.WriteLine(results.Erro.Message); } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { var layer1 = new AMapLayer(); var layer2 = new AMapLayer(); var layer3 = new AMapLayer(); double interval = 0.1; var icon1 = new AMapIcon { Image = RandomAccessStreamReference.CreateFromUri(new Uri( "ms-appx:///Assets/YELLOW.png", UriKind.RelativeOrAbsolute)), Location = aMapControl.Center, Data = "1" }; icon1.Tapped += icon1_Tapped; var icon2 = new AMapIcon { Image = RandomAccessStreamReference.CreateFromUri(new Uri( "ms-appx:///Assets/CYAN.png", UriKind.RelativeOrAbsolute)), Location = new LngLat(icon1.Location.Longitude + interval, icon1.Location.Latitude + interval), Data = "2" }; icon2.Tapped += icon2_Tapped; var icon3 = new AMapIcon { Image = RandomAccessStreamReference.CreateFromUri(new Uri( "ms-appx:///Assets/GREEN.png", UriKind.RelativeOrAbsolute)), Location = new LngLat(icon2.Location.Longitude + interval, icon2.Location.Latitude + interval), Data = "3" }; icon3.Tapped += icon3_Tapped; layer1.Add(icon1); layer2.Add(icon2); layer3.Add(icon3); aMapControl.Layers.Add(layer1); aMapControl.Layers.Add(layer2); aMapControl.Layers.Add(layer3); aMapControl.MapHolding += aMapControl_Holding; }
public MapEvent() { this.InitializeComponent(); ContentGrid.Children.Add(aMapControl); aMapControl.MapTapped += aMapControl_MapTapped; aMapControl.MapDoubleTapped += aMapControl_MapDoubleTapped; aMapControl.MapHolding += aMapControl_MapHolding; var icon = new AMapIcon(); icon.Location = aMapControl.Center; aMapControl.Layers.Add(baselayer); baselayer.Add(icon); }
public LayerManagement() { this.InitializeComponent(); ContentGrid.Children.Add(aMapControl); aMapControl.Layers.Add(baseLayer); aMapControl.ZoomLevel = 9; var icon = new AMapIcon { Location = aMapControl.Center, Data = "1" }; baseLayer.Add(icon); }
/// <summary> /// 在不同的层上加入不同的marker /// 来测试层的功能是否实现 /// </summary> private async void AddMarkersAtDifferentLayer() { var layer1 = new AMapLayer(); var layer2 = new AMapLayer(); var layer3 = new AMapLayer(); double interval = 0.1; var icon1 = new AMapIcon { Image = RandomAccessStreamReference.CreateFromUri(new Uri( "ms-appx:///Assets/YELLOW.png", UriKind.RelativeOrAbsolute)), Location = aMapControl.Center, Data = "1" }; var icon2 = new AMapIcon { Image = RandomAccessStreamReference.CreateFromUri(new Uri( "ms-appx:///Assets/CYAN.png", UriKind.RelativeOrAbsolute)), Location = new LngLat(icon1.Location.Longitude + interval, icon1.Location.Latitude + interval), Data = "2" }; var icon3 = new AMapIcon { Image = RandomAccessStreamReference.CreateFromUri(new Uri( "ms-appx:///Assets/GREEN.png", UriKind.RelativeOrAbsolute)), Location = new LngLat(icon2.Location.Longitude + interval, icon2.Location.Latitude + interval), Data = "3" }; layer1.Add(icon1); layer2.Add(icon2); layer3.Add(icon3); aMapControl.Layers.Add(layer1); aMapControl.Layers.Add(layer2); aMapControl.Layers.Add(layer3); }
private async Task AddressToGeoCode(string address) { var azure = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/AZURE.png")); AMapGeoCodeResults result = await AMapGeoCodeSearch.AddressToGeoCode(address); if (result.Erro == null) { if (result.GeoCodeList == null || !result.GeoCodeList.Any()) { Debug.WriteLine("无查询结果"); return; } IEnumerable <AMapGeoCode> geocode = result.GeoCodeList; int i = 0; IList <AMapGeoCode> aMapGeoCodes = geocode as IList <AMapGeoCode> ?? geocode.ToList(); foreach (AMapGeoCode gcs in aMapGeoCodes) { i++; Debug.WriteLine(gcs.Adcode); Debug.WriteLine(gcs.Building); Debug.WriteLine(gcs.City); Debug.WriteLine(gcs.District); Debug.WriteLine(gcs.FormattedAddress); Debug.WriteLine(gcs.Province); //todo township //Debug.WriteLine(gcs.Township); Debug.WriteLine(gcs.Location.Lon); Debug.WriteLine(gcs.Location.Lat); Debug.WriteLine(gcs.LevelList[0]); var icon = new AMapIcon { Location = new LngLat(gcs.Location.Lon, gcs.Location.Lat), Data = new { A = gcs.FormattedAddress, B = gcs.District }, Image = azure }; await baseLayer.Add(icon); } //如果返回的geocode数大于1个,调整视图 if (aMapGeoCodes.Count() > 1) { var builder = new LngLatBoundingBoxBuilder(); foreach (IAMapOverLay overlay in baseLayer.OverLays) { if (overlay as AMapIcon != null) { builder.Include((overlay as AMapIcon).Location); } } aMapControl.TrySetViewBoundsAsync(builder.Build(), AMapAnimationKind.Default); } else { aMapControl.TrySetViewAsync(new LngLat(aMapGeoCodes.FirstOrDefault().Location.Lon, aMapGeoCodes.FirstOrDefault().Location.Lat), null, null, null, AMapAnimationKind.Default); } Debug.WriteLine(i); } else { addressOutputTextblock.Text = result.Erro.Message; } }
private async void LineIdSearch_OnClick(object sender, RoutedEventArgs e) { baseLayer.Clear(); string crashid = " 440100014234"; string id = "110100013752"; AMapBusLineResults busLines = await AMapBusSearch.BusLineIDSearch(id); if (busLines.Erro == null) { if (busLines.BusLineList == null || busLines.BusLineList.Count == 0) { Debug.WriteLine("无查询结果"); return; } List <AMapBusLine> busLine = busLines.BusLineList.ToList(); //Id 搜索 只会搜索到一个 AMapBusLine bl = busLine.FirstOrDefault(); Debug.WriteLine(bl.Name); List <LngLat> latlng = LngLatsFromString(bl.Polyline); AMapPolyline polyline = new AMapPolyline { Path = new AGeopath(latlng), StrokeColor = Colors.Blue, StrokeThickness = 10 }; AMapIcon start = new AMapIcon { Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/bus_start_pic.png", UriKind.RelativeOrAbsolute)), Location = latlng.FirstOrDefault() }; AMapIcon end = new AMapIcon { Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/bus_end_pic.png", UriKind.RelativeOrAbsolute)), Location = latlng.LastOrDefault() }; await baseLayer.Add(start); await baseLayer.Add(end); //todo 纹理已经录入,但是为什么会crash await baseLayer.Add(polyline); } else { Debug.WriteLine(busLines.Erro.Message); } }