private async void DeleteButton_Click(object sender, RoutedEventArgs e) { // Dismiss the callout. MyMapView.DismissCallout(); try { // Get the feature to delete from the layer. Button deleteButton = (Button)sender; Feature featureToDelete = (Feature)deleteButton.Tag; // Delete the feature. await _damageLayer.FeatureTable.DeleteFeatureAsync(featureToDelete); // Sync the change with the service. ServiceFeatureTable serviceTable = (ServiceFeatureTable)_damageLayer.FeatureTable; await serviceTable.ApplyEditsAsync(); // Show a message confirming the deletion. MessageBox.Show("Deleted feature with ID " + featureToDelete.Attributes["objectid"], "Success!"); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Couldn't delete feature"); } }
private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e) { // Clear any existing popups. MyMapView.DismissCallout(); try { // Perform identify on the KML layer and get the results. IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_forecastLayer, e.Position, 2, false); // Return if there are no results that are KML placemarks. if (!identifyResult.GeoElements.OfType <KmlGeoElement>().Any()) { return; } // Get the first identified feature that is a KML placemark KmlNode firstIdentifiedPlacemark = identifyResult.GeoElements.OfType <KmlGeoElement>().First().KmlNode; // Show a page with the HTML content await Navigation.PushAsync(new KmlIdentifyResultDisplayPage(firstIdentifiedPlacemark.BalloonContent)); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", ex.ToString(), "OK"); } }
private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e) { // Hide any existing callout. MyMapView.DismissCallout(); // Perform the identify operation. IdentifyLayerResult myIdentifyResult = await MyMapView.IdentifyLayerAsync(_wmsLayer, e.Position, 20, false); // Return if there's nothing to show. if (!myIdentifyResult.GeoElements.Any()) { return; } // Retrieve the identified feature, which is always a WmsFeature for WMS layers. WmsFeature identifiedFeature = (WmsFeature)myIdentifyResult.GeoElements[0]; // Retrieve the WmsFeature's HTML content. string htmlContent = identifiedFeature.Attributes["HTML"].ToString(); // Note that the service returns a boilerplate HTML result if there is no feature found. // This test should work for most arcGIS-based WMS services, but results may vary. if (!htmlContent.Contains("OBJECTID")) { // Return without showing the callout. return; } // Show a callout with the HTML content. ShowHtmlCallout(htmlContent, e.Location); }
/// <summary> /// Shows a callout for any tapped graphics. /// </summary> private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { // Search for the graphics underneath the user's tap. IReadOnlyList <IdentifyGraphicsOverlayResult> results = await MyMapView.IdentifyGraphicsOverlaysAsync(e.Position, 12, false); // Clear callouts and return if there was no result. if (results.Count < 1 || results.First().Graphics.Count < 1) { MyMapView.DismissCallout(); return; } // Get the first graphic from the first result. Graphic matchingGraphic = results.First().Graphics.First(); // Get the title; manually added to the point's attributes in UpdateSearch. string title = matchingGraphic.Attributes["Match_Title"].ToString(); // Get the address; manually added to the point's attributes in UpdateSearch. string address = matchingGraphic.Attributes["Match_Address"].ToString(); // Define the callout. CalloutDefinition calloutBody = new CalloutDefinition(title, address); // Show the callout on the map at the tapped location. MyMapView.ShowCalloutAt(e.Location, calloutBody); }
private async void Map_Selected(object sender, EventArgs e) { // Clear existing overlays. MyMapView.DismissCallout(); _waypointOverlay.Graphics.Clear(); _routeOverlay.Graphics.Clear(); try { ListView sendingList = (ListView)sender; // Get the selected map. Map selectedMap = sendingList.SelectedItem as Map; // Show the map in the view. MyMapView.Map = selectedMap; // Get the transportation network if there is one. Will be set to null otherwise. _networkDataset = selectedMap.TransportationNetworks.FirstOrDefault(); } catch (Exception exception) { Debug.WriteLine(exception); await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK"); } }
/// <summary> /// Method used to keep the suggestions up-to-date for the location box. /// </summary> private async void MyLocationBox_TextChanged(object sender, TextChangedEventArgs e) { // Don't update results immediately; makes search-as-you-type more comfortable if (_waitFlag) { return; } _waitFlag = true; await Task.Delay(150); _waitFlag = false; // Dismiss callout, if any. MyMapView.DismissCallout(); // Get the current text. string searchText = MyLocationBox.Text; // Get the results. List <string> results = await GetSuggestResults(searchText); // Quit if there are no results. if (!results.Any()) { return; } // Add a 'current location' option to the list. results.Insert(0, "Current Location"); // Update the list of options. MyLocationBox.ItemsSource = results; }
/// <summary> /// Method used to keep the suggestions up-to-date for the search box. /// </summary> private async void MySearchBox_TextChanged(object sender, TextChangedEventArgs e) { // Don't update results immediately; makes search-as-you-type more comfortable if (_waitFlag) { return; } _waitFlag = true; await Task.Delay(150); _waitFlag = false; // Dismiss callout, if any. MyMapView.DismissCallout(); // Get the current text. string searchText = MySearchBox.Text; // Get the current search location. string locationText = MyLocationBox.Text; // Convert the list into a usable format for the suggest box. IEnumerable <string> results = await GetSuggestResults(searchText, locationText, true); // Quit if there are no results. if (results == null || !results.Any()) { return; } // Update the list of options. MySearchBox.ItemsSource = results; }
private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { // Clear any existing popups. MyMapView.DismissCallout(); try { // Perform identify on the KML layer and get the results. IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_forecastLayer, e.Position, 2, false); // Return if there are no results that are KML placemarks. if (!identifyResult.GeoElements.OfType <KmlGeoElement>().Any()) { return; } // Get the first identified feature that is a KML placemark KmlNode firstIdentifiedPlacemark = identifyResult.GeoElements.OfType <KmlGeoElement>().First().KmlNode; // Create a browser to show the feature popup HTML. WebView browser = new WebView { Width = 400, Height = 100 }; browser.NavigateToString(firstIdentifiedPlacemark.BalloonContent); // Create and show the callout. MyMapView.ShowCalloutAt(e.Location, browser); } catch (Exception ex) { await new MessageDialog(ex.ToString(), "Error").ShowAsync(); } }
private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e) { //var CemLot = new Uri("http://apexgis:6080/arcgis/rest/services/CemeteryHost/CEMTESTSERV/FeatureServer/0"); // FeatureLayer LotLayer = new FeatureLayer(CemLot); //await LotLayer.LoadAsync(); // NEED TO ACCESS LAYERS AND ADD TO OPERATION MAPPP!!!!!!!!! // Perform the identify operation MapPoint tapScreenPoint = e.Location; var layer = MyMapView.Map.OperationalLayers[1]; var pixelTolerance = 10; var returnPopupsOnly = false; var maxResults = 200; MyMapView.DismissCallout(); //IdentifyLayerResult myIdentifyResult = await MyMapView.IdentifyLayerAsync(layer, e.Position, pixelTolerance, returnPopupsOnly, maxResults); IdentifyLayerResult myIdentifyResult = await MyMapView.IdentifyLayerAsync(layer, e.Position, pixelTolerance, returnPopupsOnly, maxResults); //IReadOnlyList<IdentifyLayerResult> myIdentifyResult = await MyMapView.IdentifyLayersAsync(e.Position, pixelTolerance, returnPopupsOnly, maxResults); // Return if there's nothing to show if (myIdentifyResult.GeoElements.Count() < 1) { return; } FeatureLayer idLayer = myIdentifyResult.LayerContent as FeatureLayer; // Retrieve the identified feature, which is always a WmsFeature for WMS layers Feature idFeature = (Feature)myIdentifyResult.GeoElements[0]; //foreach (GeoElement idElement in myIdentifyResult.GeoElements) // { // cast the result GeoElement to Feature // Feature idFeature = idElement as Feature; try { string content = string.Format("{0} {1} {2} {3} {4}", idFeature.Attributes["name_FIRST"].ToString(), idFeature.Attributes["name_LAST"].ToString(), idFeature.Attributes["plot"].ToString(), idFeature.Attributes["lot"].ToString(), idFeature.Attributes["PLOT_ID"].ToString()); CalloutDefinition myCalloutDefinition = new CalloutDefinition("Plot Attributes", content); MyMapView.ShowCalloutAt(tapScreenPoint, myCalloutDefinition); } catch { MessageBox.Show("Not an Identifeable Layer"); } }
private void ClearAllSelections() { // For each layer in the operational layers that is an ENC layer foreach (EncLayer layer in MyMapView.Map.OperationalLayers.OfType <EncLayer>()) { // Clear the layer's selection layer.ClearSelection(); } // Clear the callout MyMapView.DismissCallout(); }
private async void updateSearch() { // Get the text in the search bar. string enteredText = MySearchBar.Text; // Clear existing marker. MyMapView.GraphicsOverlays[0].Graphics.Clear(); MyMapView.DismissCallout(); // Return if the textbox is empty or the geocoder isn't ready. if (String.IsNullOrWhiteSpace(enteredText) || _geocoder == null) { return; } try { // Get suggestions based on the input text. IReadOnlyList <GeocodeResult> geocodeResults = await _geocoder.GeocodeAsync(enteredText); // Stop if there are no suggestions. if (!geocodeResults.Any()) { await Application.Current.MainPage.DisplayAlert("No results", "No results found.", "OK"); return; } // Get the full address for the first suggestion. GeocodeResult firstSuggestion = geocodeResults.First(); IReadOnlyList <GeocodeResult> addresses = await _geocoder.GeocodeAsync(firstSuggestion.Label); // Stop if the geocoder does not return a result. if (addresses.Count < 1) { return; } // Show a graphic for the address. Graphic point = await GraphicForPoint(addresses.First().DisplayLocation); MyMapView.GraphicsOverlays[0].Graphics.Add(point); // Update the map extent to show the marker. MyMapView.SetViewpoint(new Viewpoint(addresses.First().Extent)); } catch (Exception e) { await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK"); } }
//===================更新MyScene视点位置============ private async void Map_Tapped(object sender, GeoViewInputEventArgs e) { // Dismiss any existing callouts. MyMapView.DismissCallout(); // Get the normalized geometry for the tapped location and use it as the feature's geometry. MapPoint tappedPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(e.Location); // Set the viewpoint with a new camera focused on the castle in Brest observerCamera = new Camera(new MapPoint(Mlon(tappedPoint.X), Mlat(tappedPoint.Y), 100, SpatialReferences.Wgs84), heading, 74.1212, 0.0); // MapPoint p = observerCamera.Location; await MySceneView.SetViewpointCameraAsync(observerCamera); }
/// <summary> /// Method called to start an unrestricted search. /// </summary> private void MySearchButton_Click(object sender, RoutedEventArgs e) { // Dismiss callout, if any. MyMapView.DismissCallout(); // Get the search text. string searchText = MySearchBox.Text; // Get the location text. string locationText = MyLocationBox.Text; // Run the search. UpdateSearch(searchText, locationText); }
private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { // 識別対象のレイヤーを取得 var layer = MyMapView.Map.OperationalLayers[0] as FeatureLayer; // フィーチャのハイライトをクリア layer.ClearSelection(); // コールアウトを非表示 MyMapView.DismissCallout(); // タップした地点のスクリーン ポイントを取得 Point tapScreenPoint = e.Position; // タップした地点の許容範囲 var pixelTolerance = 1; // ポップアップ オブジェクト作成の有無 var returnPopupsOnly = false; // タップ地点に含まれるレイヤーを識別し、結果を取得 IdentifyLayerResult idLayerResults = await MyMapView.IdentifyLayerAsync(layer, tapScreenPoint, pixelTolerance, returnPopupsOnly); if (idLayerResults.GeoElements.Count > 0) { // 選択したフィーチャをハイライト Feature idFeature = idLayerResults.GeoElements[0] as Feature; layer.SelectFeature(idFeature); // コールアウトのコンテンツを作成 var layerName = layer.Name; var attributes = new System.Text.StringBuilder(); if (idFeature.Attributes.Count > 0) { foreach (var attribute in idFeature.Attributes) { // フィーチャの属性(key:属性のフィールド名、value:属性のフィールド値のペア)を取得 var fieldName = attribute.Key; var fieldValue = attribute.Value; attributes.AppendLine(fieldName + ": " + fieldValue); } attributes.AppendLine(); } // コールアウトのコンテンツを定義 CalloutDefinition myCalloutDefinition = new CalloutDefinition(layerName, attributes.ToString()); // コールアウトを表示 MyMapView.ShowCalloutAt(e.Location, myCalloutDefinition); } }
private async void MapTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e) { try { // Get the result for where the user tapped on the raster layer. IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_rasterLayer, e.Position, 1, false, 1); // If no cell was identified, dismiss the callout. if (!identifyResult.GeoElements.Any()) { MyMapView.DismissCallout(); return; } // Create a StringBuilder to display information to the user. var stringBuilder = new StringBuilder(); // Get the identified raster cell. GeoElement cell = identifyResult.GeoElements.First(); // Loop through the attributes (key/value pairs). foreach (KeyValuePair <string, object> keyValuePair in cell.Attributes) { // Add the key/value pair to the string builder. stringBuilder.AppendLine($"{keyValuePair.Key}: {keyValuePair.Value}"); } // Get the x and y values of the cell. double x = cell.Geometry.Extent.XMin; double y = cell.Geometry.Extent.YMin; // Add the X & Y coordinates where the user clicked raster cell to the string builder. stringBuilder.AppendLine($"X: {Math.Round(x, 4)}\nY: {Math.Round(y, 4)}"); // Create a callout using the string. #if __IOS__ var definition = new CalloutDefinition(string.Empty, stringBuilder.ToString().Replace("\n", " ")); #else var definition = new CalloutDefinition(string.Empty, stringBuilder.ToString()); #endif // Display the call out in the map view. MyMapView.ShowCalloutAt(e.Location, definition); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert(ex.GetType().Name, ex.Message, "OK"); } }
async void MyMapView_GeoViewTapped(System.Object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e) { // Clear any currently visible callouts, route graphics, or selections MyMapView.DismissCallout(); _routeGraphicsOverlay.Graphics.Clear(); _placesGraphicsOverlay.ClearSelection(); // Get the place under the tap IdentifyGraphicsOverlayResult idResult = await MyMapView.IdentifyGraphicsOverlayAsync(_placesGraphicsOverlay, e.Position, 12, false); Graphic clickedElement = idResult.Graphics.FirstOrDefault(); if (clickedElement != null) { // Select the place to highlight it; get name and address clickedElement.IsSelected = true; string name = clickedElement.Attributes["Name"].ToString(); string address = clickedElement.Attributes["Address"].ToString(); // Create a callout definition that shows the name and address for the place; set the element as a tag CalloutDefinition definition = new CalloutDefinition(name, address); definition.Tag = clickedElement; // Handle button clicks for the button on the callout // This event receives the value assigned as the CalloutDefinition.Tag // ** Fix API ref for this! // https://developers.arcgis.com/net/latest/wpf/api-reference/html/P_Esri_ArcGISRuntime_UI_CalloutDefinition_OnButtonClick.htm definition.OnButtonClick = new Action <object>(async(tag) => { // Get the geoelement that represents the place GeoElement poiElement = tag as GeoElement; if (poiElement == null) { return; } // Call a function in the viewmodel that will route to this location var routeGraphic = await _viewModel.RouteToPoiAsync(_deviceLocation, poiElement.Geometry as MapPoint, MyMapView.SpatialReference); // Add the route graphic to the map view and zoom to its extent _routeGraphicsOverlay.Graphics.Add(routeGraphic); await MyMapView.SetViewpointGeometryAsync(routeGraphic.Geometry, 30); }); // Set the button icon and show the callout at the click location definition.ButtonImage = WalkIcon; MyMapView.ShowCalloutAt(e.Location, definition); } }
private async void MouseMoved(object sender, PointerRoutedEventArgs e) { try { // Get the curent mouse position. Point position = e.GetCurrentPoint(MyMapView).Position; // Get the result for where the user hovered on the raster layer. IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_rasterLayer, position, 1, false, 1); // If no cell was identified, dismiss the callout. if (!identifyResult.GeoElements.Any()) { MyMapView.DismissCallout(); return; } // Create a StringBuilder to display information to the user. var stringBuilder = new StringBuilder(); // Get the identified raster cell. GeoElement cell = identifyResult.GeoElements.First(); // Loop through the attributes (key/value pairs). foreach (KeyValuePair <string, object> keyValuePair in cell.Attributes) { // Add the key/value pair to the string builder. stringBuilder.AppendLine($"{keyValuePair.Key}: {keyValuePair.Value}"); } // Get the x and y values of the cell. double x = cell.Geometry.Extent.XMin; double y = cell.Geometry.Extent.YMin; // Add the X & Y coordinates where the user clicked raster cell to the string builder. stringBuilder.AppendLine($"X: {Math.Round(x, 4)}\nY: {Math.Round(y, 4)}"); // Create a callout using the string. var definition = new CalloutDefinition(stringBuilder.ToString()); // Display the call out in the map view. MyMapView.ShowCalloutAt(MyMapView.ScreenToLocation(position), definition); } catch (Exception ex) { await new MessageDialog(ex.Message, ex.GetType().Name).ShowAsync(); } }
private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { // Clear any existing popups. MyMapView.DismissCallout(); try { // Perform identify on the KML layer and get the results. IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_forecastLayer, e.Position, 2, false); // Return if there are no results that are KML placemarks. if (!identifyResult.GeoElements.OfType <KmlGeoElement>().Any()) { return; } // Get the first identified feature that is a KML placemark. KmlNode firstIdentifiedPlacemark = identifyResult.GeoElements.OfType <KmlGeoElement>().First().KmlNode; // Populate the Description if empty. if (string.IsNullOrEmpty(firstIdentifiedPlacemark.Description)) { firstIdentifiedPlacemark.Description = "Weather condition"; } // Create a browser to show the feature popup HTML. WebView2 browser = new WebView2 { Width = 400, Height = 100 }; // Ensure the CoreWebView2 has been created. await browser.EnsureCoreWebView2Async(); // Initiate the navigation to the BalloonContent HTML. browser.NavigateToString(firstIdentifiedPlacemark.BalloonContent); // Create and show the callout. MyMapView.ShowCalloutAt(e.Location, browser); } catch (Exception ex) { await new MessageDialog2(ex.ToString(), "Error").ShowAsync(); } }
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 MapView_Tapped(object sender, GeoViewInputEventArgs e) { // Clear any existing selection. _damageLayer.ClearSelection(); // Dismiss any existing callouts. MyMapView.DismissCallout(); try { // Perform an identify to determine if a user tapped on a feature. IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_damageLayer, e.Position, 2, false); // Do nothing if there are no results. if (!identifyResult.GeoElements.Any()) { return; } // Otherwise, get the ID of the first result. long featureId = (long)identifyResult.GeoElements.First().Attributes["objectid"]; // Get the feature by constructing a query and running it. QueryParameters qp = new QueryParameters(); qp.ObjectIds.Add(featureId); FeatureQueryResult queryResult = await _damageLayer.FeatureTable.QueryFeaturesAsync(qp); Feature tappedFeature = queryResult.First(); // Select the feature. _damageLayer.SelectFeature(tappedFeature); // Show the callout. ShowDeletionCallout(tappedFeature); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "There was a problem."); } }
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(); } }
private async void MapView_Tapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e) { // Clear any existing selection. _damageLayer.ClearSelection(); // Dismiss any existing callouts. MyMapView.DismissCallout(); // Reset the picker. DamageTypePicker.IsEnabled = false; DamageTypePicker.SelectedIndex = -1; try { // Perform an identify to determine if a user tapped on a feature. IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_damageLayer, e.Position, 8, false); // Do nothing if there are no results. if (!identifyResult.GeoElements.Any()) { return; } // Get the tapped feature. _selectedFeature = (ArcGISFeature)identifyResult.GeoElements.First(); // Select the feature. _damageLayer.SelectFeature(_selectedFeature); // Update the UI for the selection. UpdateUiForSelectedFeature(); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error selecting feature.", ex.ToString(), "OK"); } }
private async void MapView_Tapped(object sender, GeoViewInputEventArgs e) { // Clear any existing selection. _damageLayer.ClearSelection(); // Dismiss any existing callouts. MyMapView.DismissCallout(); // Reset the dropdown. DamageTypeDropDown.IsEnabled = false; DamageTypeDropDown.SelectedIndex = -1; try { // Perform an identify to determine if a user tapped on a feature. IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_damageLayer, e.Position, 2, false); // Do nothing if there are no results. if (!identifyResult.GeoElements.Any()) { return; } // Get the tapped feature. _selectedFeature = (ArcGISFeature)identifyResult.GeoElements.First(); // Select the feature. _damageLayer.SelectFeature(_selectedFeature); // Update the UI for the selection. UpdateUiForSelectedFeature(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "There was a problem."); } }
private void Map_Selected(object sender, SelectionChangedEventArgs e) { // Clear existing overlays. MyMapView.DismissCallout(); _waypointOverlay.Graphics.Clear(); _routeOverlay.Graphics.Clear(); try { // Get the selected map. Map selectedMap = e.AddedItems[0] as Map; // Show the map in the view. MyMapView.Map = selectedMap; // Get the transportation network if there is one. Will be set to null otherwise. _networkDataset = selectedMap.TransportationNetworks.FirstOrDefault(); } catch (Exception exception) { Console.WriteLine(exception); MessageBox.Show(exception.ToString()); } }
/// <summary> /// Method to handle hiding the callout, should be called by all UI event handlers /// </summary> private void UserInteracted() { // Hide the callout MyMapView.DismissCallout(); }
private async void IdentifyCell(Point position) { // Check if a cell is already being identified if (_isIdentifying) { _nextIdentifyAction = () => IdentifyCell(position); return; } // Set variable to true to prevent concurrent identify calls. _isIdentifying = true; try { // Get the result for where the user hovered on the raster layer. IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_rasterLayer, position, 1, false, 1); // If no cell was identified, dismiss the callout. if (!identifyResult.GeoElements.Any()) { MyMapView.DismissCallout(); return; } // Create a StringBuilder to display information to the user. var stringBuilder = new StringBuilder(); // Get the identified raster cell. GeoElement cell = identifyResult.GeoElements.First(); // Loop through the attributes (key/value pairs). foreach (KeyValuePair <string, object> keyValuePair in cell.Attributes) { // Add the key/value pair to the string builder. stringBuilder.AppendLine($"{keyValuePair.Key}: {keyValuePair.Value}"); } // Get the x and y values of the cell. double x = cell.Geometry.Extent.XMin; double y = cell.Geometry.Extent.YMin; // Add the X & Y coordinates where the user clicked raster cell to the string builder. stringBuilder.AppendLine($"X: {Math.Round(x, 4)}\nY: {Math.Round(y, 4)}"); // Create a callout using the string. var definition = new CalloutDefinition(stringBuilder.ToString()); // Display the call out in the map view. MyMapView.ShowCalloutAt(MyMapView.ScreenToLocation(position), definition); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } finally { _isIdentifying = false; } // Check if there is a new position to identify. if (_nextIdentifyAction != null) { Action action = _nextIdentifyAction; // Clear the queued identify action. _nextIdentifyAction = null; // Run the next action. action(); } }
private async Task ProcessRouteRequest(MapPoint tappedPoint) { // Clear any existing overlays. _routeOverlay.Graphics.Clear(); MyMapView.DismissCallout(); // Return if there is no network available for routing. if (_networkDataset == null) { await ShowGeocodeResult(tappedPoint); return; } // Set the start point if it hasn't been set. if (_startPoint == null) { _startPoint = tappedPoint; await ShowGeocodeResult(tappedPoint); // Show the start point. _waypointOverlay.Graphics.Add(await GraphicForPoint(_startPoint)); return; } if (_endPoint == null) { await ShowGeocodeResult(tappedPoint); // Show the end point. _endPoint = tappedPoint; _waypointOverlay.Graphics.Add(await GraphicForPoint(_endPoint)); // Create the route task from the local network dataset. RouteTask routingTask = await RouteTask.CreateAsync(_networkDataset); // Configure route parameters for the route between the two tapped points. RouteParameters routingParameters = await routingTask.CreateDefaultParametersAsync(); List <Stop> stops = new List <Stop> { new Stop(_startPoint), new Stop(_endPoint) }; routingParameters.SetStops(stops); // Get the first route result. RouteResult result = await routingTask.SolveRouteAsync(routingParameters); Route firstRoute = result.Routes.First(); // Show the route on the map. Note that symbology for the graphics overlay is defined in Initialize(). Polyline routeLine = firstRoute.RouteGeometry; _routeOverlay.Graphics.Add(new Graphic(routeLine)); return; } // Reset graphics and route. _routeOverlay.Graphics.Clear(); _waypointOverlay.Graphics.Clear(); _startPoint = null; _endPoint = null; }