private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e) { try { // Clear existing callout and graphics. MyMapView.DismissCallout(); MyMapView.GraphicsOverlays[0].Graphics.Clear(); // Add a graphic for the tapped point. Graphic pinGraphic = await GraphicForPoint(e.Location); MyMapView.GraphicsOverlays[0].Graphics.Add(pinGraphic); // Reverse geocode to get addresses. ReverseGeocodeParameters parameters = new ReverseGeocodeParameters(); parameters.ResultAttributeNames.Add("*"); parameters.MaxResults = 1; IReadOnlyList <GeocodeResult> addresses = await _geocoder.ReverseGeocodeAsync(e.Location, parameters); // Skip if there are no results. if (!addresses.Any()) { await Application.Current.MainPage.DisplayAlert("No results", "No results found.", "OK"); return; } // Get the first result. GeocodeResult address = addresses.First(); // Use the address as the callout title. string calloutTitle = address.Attributes["Street"].ToString(); string calloutDetail = address.Attributes["City"] + ", " + address.Attributes["State"] + " " + address.Attributes["ZIP"]; // Define the callout. CalloutDefinition calloutBody = new CalloutDefinition(calloutTitle, calloutDetail); // Show the callout on the map at the tapped location. MyMapView.ShowCalloutForGeoElement(pinGraphic, e.Position, calloutBody); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.ToString(), "OK"); } }
private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { try { // Clear the existing graphics & callouts. MyMapView.DismissCallout(); MyMapView.GraphicsOverlays[0].Graphics.Clear(); // Add a graphic for the tapped point. Graphic pinGraphic = await GraphicForPoint(e.Location); MyMapView.GraphicsOverlays[0].Graphics.Add(pinGraphic); // Normalize the geometry - needed if the user crosses the international date line. MapPoint normalizedPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(e.Location); // Reverse geocode to get addresses. IReadOnlyList <GeocodeResult> addresses = await _geocoder.ReverseGeocodeAsync(normalizedPoint); // Get the first result. GeocodeResult address = addresses.First(); // Use the city and region for the Callout Title. string calloutTitle = address.Attributes["Address"].ToString(); // Use the metro area for the Callout Detail. string calloutDetail = address.Attributes["City"] + " " + address.Attributes["Region"] + " " + address.Attributes["CountryCode"]; // Define the callout. CalloutDefinition calloutBody = new CalloutDefinition(calloutTitle, calloutDetail); // Show the callout on the map at the tapped location. MyMapView.ShowCalloutForGeoElement(pinGraphic, e.Position, calloutBody); } catch (Exception ex) { Debug.WriteLine(ex); await new MessageDialog("No results found.", "No results").ShowAsync(); } }
private async void MyMapView_MouseMove(object sender, MouseEventArgs e)// GeoViewInputEventArgs e) { // Get the screen point var point = e.GetPosition(MyMapView); //e.Position; // Add a graphic to show screen point location //var mapPoint = MyMapView.ScreenToLocation(point); //MyMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(mapPoint)); // Use hit test to find feature var results = await MyMapView.IdentifyLayerAsync(MyMapView.Map.OperationalLayers[0], point, 0, false); // Show feature in callout if (results != null && results.GeoElements?.Count > 0) { var feature = results.GeoElements.FirstOrDefault(); MyMapView.ShowCalloutForGeoElement(feature, point, new CalloutDefinition("City: " + feature.Attributes["AREANAME"])); } else { MyMapView.DismissCallout(); } }
private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { try { // Clear existing callout and graphics. MyMapView.DismissCallout(); MyMapView.GraphicsOverlays[0].Graphics.Clear(); // Add a graphic for the tapped point. Graphic pinGraphic = await GraphicForPoint(e.Location); MyMapView.GraphicsOverlays[0].Graphics.Add(pinGraphic); // Reverse geocode to get addresses. ReverseGeocodeParameters parameters = new ReverseGeocodeParameters(); parameters.ResultAttributeNames.Add("*"); parameters.MaxResults = 1; IReadOnlyList <GeocodeResult> addresses = await _geocoder.ReverseGeocodeAsync(e.Location, parameters); // Get the first result. GeocodeResult address = addresses.First(); // Use the address as the callout title. string calloutTitle = address.Attributes["Street"].ToString(); string calloutDetail = address.Attributes["City"] + ", " + address.Attributes["State"] + " " + address.Attributes["ZIP"]; // Define the callout. CalloutDefinition calloutBody = new CalloutDefinition(calloutTitle, calloutDetail); // Show the callout on the map at the tapped location. MyMapView.ShowCalloutForGeoElement(pinGraphic, e.Position, calloutBody); } catch (Exception ex) { await new MessageDialog2(ex.ToString(), "Error").ShowAsync(); } }