private async void GeoViewTappedHandler(object sender, GeoViewInputEventArgs e) { // get the tap location in screen units var pixelTolerance = 50; var returnPopupsOnly = false; var maxLayerResults = 5; // identify all layers in the MapView, passing the tap point, tolerance, types to return, and max results IReadOnlyList <IdentifyLayerResult> idLayerResults = await MyMapView.IdentifyLayersAsync(e.Position, pixelTolerance, returnPopupsOnly, maxLayerResults); // iterate the results for each layer foreach (IdentifyLayerResult idResults in idLayerResults) { // get the layer identified and cast it to FeatureLayer FeatureLayer idLayer = idResults.LayerContent as FeatureLayer; // iterate each identified GeoElement in the results for this layer foreach (GeoElement idElement in idResults.GeoElements) { // cast the result GeoElement to Feature Feature idFeature = idElement as Feature; // select this feature in the feature layer idLayer.SelectFeature(idFeature); } } }
private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e) { try { // Perform an identify across all layers, taking up to 10 results per layer. IReadOnlyList <IdentifyLayerResult> identifyResults = await MyMapView.IdentifyLayersAsync(e.Position, 15, false, 10); // Add a line to the output for each layer, with a count of features in the layer. string result = ""; foreach (IdentifyLayerResult layerResult in identifyResults) { // Note: because some layers have sublayers, a recursive function is required to count results. result = result + layerResult.LayerContent.Name + ": " + recursivelyCountIdentifyResultsForSublayers(layerResult) + "\n"; } if (!String.IsNullOrEmpty(result)) { await new MessageDialog(result).ShowAsync(); } } catch (Exception ex) { await new MessageDialog(ex.ToString(), "Error").ShowAsync(); } }
/// <summary> /// this method display the value of country name region name and its population when a location is tapped on the map. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void MyMap_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e) { try { //identify all layers in the MapView, passing the tap point, tolerance, //types to return, and max results IReadOnlyList <IdentifyLayerResult> idlayerResults = await MyMapView.IdentifyLayersAsync(e.Position, 10, false, 5); if (idlayerResults.Count > 0) { IdentifyLayerResult idResults = idlayerResults.FirstOrDefault(); FeatureLayer idLayer = idResults.LayerContent as FeatureLayer; idLayer.ClearSelection(); CountryTitleLabel.Content = "Country"; RegionTitleLabel.Content = "Region"; PopulationTitleLabel.Content = "2015 Population"; foreach (GeoElement idElement in idResults.GeoElements) { Feature idFeature = idElement as Feature; idLayer.SelectFeature(idFeature); IDictionary <string, object> attributes = idFeature.Attributes; string attKey = string.Empty; object attVal1 = new object(); foreach (var attribute in attributes) { attKey = attribute.Key; attVal1 = attribute.Value; if (string.Compare(attKey, "Country") == 0) { CountryValueLabel.Content = attVal1; } if (string.Compare(attKey, "Major_Region") == 0) { RegionValueLabel.Content = attVal1; } if (string.Compare(attKey, "pop2015") == 0) { string pop = attVal1 + "000"; int.TryParse(pop, out int result); string formatString = String.Format("{0:n0}", result); PopulationValueLabel.Content = formatString; } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e) { // First clear any existing selections ClearAllSelections(); try { // Perform the identify operation IReadOnlyList <IdentifyLayerResult> results = await MyMapView.IdentifyLayersAsync(e.Position, 5, false); // Return if there are no results if (results.Count < 1) { return; } // Get the results that are from ENC layers IEnumerable <IdentifyLayerResult> encResults = results.Where(result => result.LayerContent is EncLayer); // Get the ENC results that have features IEnumerable <IdentifyLayerResult> encResultsWithFeatures = encResults.Where(result => result.GeoElements.Count > 0); // Get the first result with ENC features IdentifyLayerResult firstResult = encResultsWithFeatures.First(); // Get the layer associated with this set of results EncLayer containingLayer = (EncLayer)firstResult.LayerContent; // Select the smallest (area) feature in the layer. EncFeature smallestFeature = (EncFeature)firstResult.GeoElements.OrderBy(f => GeometryEngine.Area(f.Geometry)).First(); // Select the feature. containingLayer.SelectFeature(smallestFeature); // Create the callout definition. CalloutDefinition definition = new CalloutDefinition(smallestFeature.Acronym, smallestFeature.Description); // Show the callout MyMapView.ShowCalloutAt(e.Location, definition); } catch (Exception ex) { await((Page)Parent).DisplayAlert("Error", ex.ToString(), "OK"); } }
private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e) { // First clear any existing selections ClearAllSelections(); try { // Perform the identify operation. IReadOnlyList <IdentifyLayerResult> results = await MyMapView.IdentifyLayersAsync(e.Position, 10, false); // Return if there are no results. if (results.Count < 1) { return; } // Get the results that are from ENC layers. IEnumerable <IdentifyLayerResult> encResults = results.Where(result => result.LayerContent is EncLayer); // Get the first result with ENC features. (Depending on the data, there may be more than one IdentifyLayerResult that contains ENC features.) IdentifyLayerResult firstResult = encResults.First(); // Get the layer associated with this set of results. EncLayer containingLayer = (EncLayer)firstResult.LayerContent; // Get the GeoElement identified in this layer. EncFeature encFeature = (EncFeature)firstResult.GeoElements.First(); // Select the feature. containingLayer.SelectFeature(encFeature); // Create the callout definition. CalloutDefinition definition = new CalloutDefinition(encFeature.Acronym, encFeature.Description); // Show the callout. MyMapView.ShowCalloutAt(e.Location, definition); } 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) { var point = e.Position; var watch = new Stopwatch(); if (_allLayers == false) { //IReadOnlyList<IdentifyLayerResult> idLayersResult = await MyMapView.IdentifyLayersAsync(point, 20, false, 5); IReadOnlyList <Layer> layers = MyMapView.Map.AllLayers; watch.Start(); int count = 0; foreach (var layer in layers) { System.Threading.Thread.Sleep(500); System.Diagnostics.Debug.WriteLine(layer.Name); if (layer is FeatureLayer) { System.Diagnostics.Debug.WriteLine("Feature layer: " + layer.Name); //Determine the feature layer that the tapPoint was on when clicked var idLayerResults = await MyMapView.IdentifyLayerAsync(layer, point, 0, false); } count++; } watch.Stop(); MessageBox.Show("It took " + watch.Elapsed.Seconds.ToString("N2") + " seconds to go through " + count.ToString() + " layers."); } else { watch.Start(); System.Threading.Thread.Sleep(1500); var idLayerResults = await MyMapView.IdentifyLayersAsync(point, 0, false); var x = idLayerResults.ToList(); watch.Stop(); MessageBox.Show("It took " + watch.Elapsed.Seconds.ToString() + " seconds to go through all layers."); } }
private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e) { // First clear any existing selections ClearAllSelections(); // Perform the identify operation IReadOnlyList <IdentifyLayerResult> results = await MyMapView.IdentifyLayersAsync(e.Position, 5, false); // Return if there are no results if (results.Count < 1) { return; } // Get the results that are from ENC layers IEnumerable <IdentifyLayerResult> encResults = results.Where(result => result.LayerContent is EncLayer); // Get the ENC results that have features IEnumerable <IdentifyLayerResult> encResultsWithFeatures = encResults.Where(result => result.GeoElements.Count > 0); // Get the first result with ENC features IdentifyLayerResult firstResult = encResultsWithFeatures.First(); // Get the layer associated with this set of results EncLayer containingLayer = firstResult.LayerContent as EncLayer; // Get the first identified ENC feature EncFeature firstFeature = firstResult.GeoElements.First() as EncFeature; // Select the feature containingLayer.SelectFeature(firstFeature); // Create the callout definition CalloutDefinition definition = new CalloutDefinition(firstFeature.Acronym, firstFeature.Description); // Show the callout MyMapView.ShowCalloutAt(e.Location, definition); }
private async Task SelectFeature(Point clickedPoint) { try { // Identify across all layers. IReadOnlyList <IdentifyLayerResult> identifyResults = await MyMapView.IdentifyLayersAsync(clickedPoint, 10.0, false); foreach (IdentifyLayerResult result in identifyResults) { if (result.LayerContent is FeatureLayer layer) { _selectedFeature = result.GeoElements.First() as Feature; if (_selectedFeature.Geometry is Polyline line) { // No support for curved lines. if (line.Parts.Count > 1) { _selectedFeature = null; return; } } else if (_selectedFeature.Geometry is MapPoint) { // Open attribute editor for point features. ShowEditableAttributes(); } // Select the feature. layer.SelectFeature(_selectedFeature); break; } } } catch (Exception ex) { await new MessageDialog2(ex.Message, "Error").ShowAsync(); } }
private async void OnGeoViewTapped(object sender, GeoViewInputEventArgs e) { try { IsBusy.Visibility = Visibility.Visible; Status.Text = "Identifying trace locations..."; // Identify the feature to be used. IEnumerable <IdentifyLayerResult> identifyResult = await MyMapView.IdentifyLayersAsync(e.Position, 10.0, false); ArcGISFeature feature = identifyResult?.FirstOrDefault()?.GeoElements?.FirstOrDefault() as ArcGISFeature; if (feature == null) { return; } // Create element from the identified feature. UtilityElement element = _utilityNetwork.CreateElement(feature); if (element.NetworkSource.SourceType == UtilityNetworkSourceType.Junction) { // Select terminal for junction feature. IEnumerable <UtilityTerminal> terminals = element.AssetType.TerminalConfiguration?.Terminals; if (terminals?.Count() > 1) { element.Terminal = await GetTerminalAsync(terminals); } Status.Text = $"Terminal: {element.Terminal?.Name ?? "default"}"; } else if (element.NetworkSource.SourceType == UtilityNetworkSourceType.Edge) { // Compute how far tapped location is along the edge feature. if (feature.Geometry is Polyline line) { line = GeometryEngine.RemoveZ(line) as Polyline; double fraction = GeometryEngine.FractionAlong(line, e.Location, -1); if (double.IsNaN(fraction)) { return; } element.FractionAlongEdge = fraction; Status.Text = $"Fraction along edge: {element.FractionAlongEdge}"; } } // Check whether starting location or barrier is added to update the right collection and symbology. Symbol symbol = null; if (IsAddingStartingLocations.IsChecked.Value == true) { _startingLocations.Add(element); symbol = _startingPointSymbol; } else { _barriers.Add(element); symbol = _barrierPointSymbol; } // Add a graphic for the new utility element. Graphic traceLocationGraphic = new Graphic(feature.Geometry as MapPoint ?? e.Location, symbol); MyMapView.GraphicsOverlays.FirstOrDefault()?.Graphics.Add(traceLocationGraphic); } catch (Exception ex) { Status.Text = "Identifying locations failed."; MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error); } finally { if (Status.Text.Equals("Identifying trace locations...")) { Status.Text = "Could not identify location."; } IsBusy.Visibility = Visibility.Hidden; } }
private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e) { try { // Perform an identify across all layers, taking up to 10 results per layer. IReadOnlyList <IdentifyLayerResult> myIdentifyLayerResults = await MyMapView.IdentifyLayersAsync(e.Position, 15, false, 10); // Loop through each layer result in the collection of identify layer results. foreach (IdentifyLayerResult layerResult in myIdentifyLayerResults) { // Get the layer content from the layer result. ILayerContent myLayerContent = layerResult.LayerContent; // Get the name of the layer content (i.e. the name of the layer). string lc_Name = myLayerContent.Name; // We are only interested in the identify layer results for the created feature collection layer that // was generated from the NY Times articles. if (lc_Name == "JoinedFCL") { // Get the sub layer results for the NY Times generated feature collection layer. IReadOnlyList <IdentifyLayerResult> myIdentifyLayerResultsSubLayer = layerResult.SublayerResults; // Get the first result found from identify operation on the NY Times generated feature collection layer. IdentifyLayerResult myIdentifyLayerResultNYTimesFeatureCollectionTable = myIdentifyLayerResultsSubLayer.First(); // Get the geo-element collection from the first result. IReadOnlyList <GeoElement> myGeoElements = myIdentifyLayerResultNYTimesFeatureCollectionTable.GeoElements; // Get the first geo-element in the geo-element collection. This is the identified country (via the mouse click/tap) // in the NY Times feature collection layer. GeoElement myGeoElement = myGeoElements.First(); // Loop through key/value pair of the features attributes in the NY Times feature collection layer. foreach (KeyValuePair <string, object> myKeyValuePair in myGeoElement.Attributes) { // Get the key (aka. field name). var myKey = myKeyValuePair.Key; // Get the value (aka. the text for the record of a specific field). var myValue = myKeyValuePair.Value; // Check is the name of the field in the NY Times feature collection layer 'AreaName'. This represents the country name. if (myKey == "AreaName") { // Read the NY Times data from the text file and get back a list of each article. // The format of each record/article will look like: // [Article summary]~[Article abstract]~[Country name]~[Url to the NY times article]~[Url to an image about the NY times article]~[Date of NY Times news article] // Ex: // Netanyahu not happy with Cohen~A spokesman for Prime Minister Benjamin Netanyahu disagrees with Roger Cohen’s “pessimism.”~Israel~https://www.nytimes.com/2018/01/02/opinion/israel-future.html~https://www.nytimes.com/images/2017/12/29/opinion/29cohenWeb/29cohenWeb-thumbLarge.jpg~20180102 List <string> myNYTimesArticles = ReadTextFile3(_NEWSFILE); // Create a FlowDocument to contain content for the RichTextBox. FlowDocument myFlowDoc = new FlowDocument(); // Loop through each NY Times article. foreach (var oneNYTimesArticle in myNYTimesArticles) { // Char array to remove embedded double quotes from various NT Times strings. char[] charsToTrim = { '"' }; // Get various sub-parts of the records for each NY Times article. string title = oneNYTimesArticle.Split('~')[0].Trim(charsToTrim); string absrtact = oneNYTimesArticle.Split('~')[1].Trim(charsToTrim); string country = oneNYTimesArticle.Split('~')[2].Trim(charsToTrim); string newsurl = oneNYTimesArticle.Split('~')[3].Trim(charsToTrim); string imageurl = oneNYTimesArticle.Split('~')[4].Trim(charsToTrim); string date = oneNYTimesArticle.Split('~')[5].Trim(charsToTrim); // Find a match from the NY Times feature collection layer feature country name and the NY // Times country name in the article. if (myValue.ToString() == country) { // Create a paragraph. Paragraph myParagraph = new Paragraph(); myParagraph.FontSize = 18; // Create a run that contains the country and a new line. Run myRun = new Run(myValue.ToString() + System.Environment.NewLine); // Create a bold that contains short title (aka news headline) of the NY Times article. Bold myBold = new Bold(new Run(title)); // Create a run that contains a new line. Run myRun2 = new Run(System.Environment.NewLine); // Create a new run that contains the hyperlink to the NY Times article. Run myRun7 = new Run(newsurl); // Create a new hyperlink based on the run. Hyperlink myHP = new Hyperlink(myRun7); // Set the hyperlink to the uri of the NY Times news article. myHP.NavigateUri = new Uri(newsurl); // Wire up the event handler when the user holds down the CTRL key and presses on the hyperlink for // the NY Times article shown in the rich text box. myHP.Click += MyHP_Click; // Add all of the sub components of the paragraph that make up what will be displayed for each NY // Times article in the rich text box. myParagraph.Inlines.Add(myRun); myParagraph.Inlines.Add(myBold); myParagraph.Inlines.Add(myRun2); myParagraph.Inlines.Add(myHP); // Add the paragraph to the flow document's block collection. myFlowDoc.Blocks.Add(myParagraph); } } // Make sure that the user is able to click on hyper links in the rick text box. Requires that the .IsDocumentEnabled be true. MyRichTextBox.IsDocumentEnabled = true; // Add initial content to the RichTextBox. MyRichTextBox.Document = myFlowDoc; } } } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error"); } }
private async void OnGeoViewTapped(object sender, GeoViewInputEventArgs e) { try { IsBusy.Visibility = Visibility.Visible; Status.Text = "Identifying trace locations..."; // Set whether the user is adding a starting point or a barrier. bool isAddingStart = IsAddingStartingLocations.IsChecked.Value; // Identify the feature to be used. IEnumerable <IdentifyLayerResult> identifyResult = await MyMapView.IdentifyLayersAsync(e.Position, 10.0, false); // Check that a results from a layer were identified from the user input. if (!identifyResult.Any()) { return; } // Identify the selected feature. IdentifyLayerResult layerResult = identifyResult?.FirstOrDefault(); ArcGISFeature feature = layerResult?.GeoElements?.FirstOrDefault() as ArcGISFeature; // Check that a feature was identified from the layer. if (feature == null) { return; } // Create element with `terminal` for junction feature or with `fractionAlong` for edge feature. UtilityElement element = null; // Select default terminal or display possible terminals for the junction feature. UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(feature.FeatureTable.TableName); // Check if the network source is a junction or an edge. if (networkSource.SourceType == UtilityNetworkSourceType.Junction) { // Get the UtilityAssetGroup from the feature. string assetGroupFieldName = ((ArcGISFeatureTable)feature.FeatureTable).SubtypeField ?? "ASSETGROUP"; int assetGroupCode = Convert.ToInt32(feature.Attributes[assetGroupFieldName]); UtilityAssetGroup assetGroup = networkSource?.AssetGroups?.FirstOrDefault(g => g.Code == assetGroupCode); // Get the UtilityAssetType from the feature. int assetTypeCode = Convert.ToInt32(feature.Attributes["ASSETTYPE"]); UtilityAssetType assetType = assetGroup?.AssetTypes?.FirstOrDefault(t => t.Code == assetTypeCode); // Get the list of terminals for the feature. IEnumerable <UtilityTerminal> terminals = assetType?.TerminalConfiguration?.Terminals; // If there is more than one terminal, prompt the user to select a terminal. if (terminals.Count() > 1) { // Ask the user to choose the terminal. UtilityTerminal terminal = await WaitForTerminal(terminals); // Create a UtilityElement with the terminal. element = _utilityNetwork.CreateElement(feature, terminal); Status.Text = $"Terminal: {terminal?.Name ?? "default"}"; } else { element = _utilityNetwork.CreateElement(feature, terminals.FirstOrDefault()); Status.Text = $"Terminal: {element.Terminal?.Name ?? "default"}"; } } else if (networkSource.SourceType == UtilityNetworkSourceType.Edge) { element = _utilityNetwork.CreateElement(feature); // Compute how far tapped location is along the edge feature. if (feature.Geometry is Polyline line) { line = GeometryEngine.RemoveZ(line) as Polyline; // Set how far the element is along the edge. element.FractionAlongEdge = GeometryEngine.FractionAlong(line, e.Location, -1); Status.Text = $"Fraction along edge: {element.FractionAlongEdge}"; } } // Check that the element can be added to the parameters. if (element == null) { return; } // Build the utility trace parameters. if (_parameters == null) { IEnumerable <UtilityElement> startingLocations = Enumerable.Empty <UtilityElement>(); _parameters = new UtilityTraceParameters(UtilityTraceType.Connected, startingLocations); } if (isAddingStart) { _parameters.StartingLocations.Add(element); } else { _parameters.Barriers.Add(element); } // Add a graphic for the new utility element. Graphic traceLocationGraphic = new Graphic(feature.Geometry as MapPoint ?? e.Location, isAddingStart ? _startingPointSymbol : _barrierPointSymbol); MyMapView.GraphicsOverlays.FirstOrDefault()?.Graphics.Add(traceLocationGraphic); } catch (Exception ex) { Status.Text = "Identifying locations failed..."; MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { if (Status.Text.Equals("Identifying trace locations...")) { Status.Text = "Could not identify location."; } IsBusy.Visibility = Visibility.Hidden; } }