Example #1
0
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            try
            {
                // Perform the identify operation
                IdentifyLayerResult myIdentifyResult = await MyMapView.IdentifyLayerAsync(_wmsLayer, e.Position, 20, false);

                // Return if there's nothing to show
                if (myIdentifyResult.GeoElements.Count < 1)
                {
                    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 result
                    return;
                }

                // Show a page with the HTML content
                await Navigation.PushAsync(new WmsIdentifyResultDisplayPage(htmlContent));
            }
            catch (Exception ex)
            {
                await((Page)Parent).DisplayAlert("Error", ex.ToString(), "OK");
            }
        }
        private async void MapViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Get the feature layer from the map.
                FeatureLayer incidentLayer = MyMapView.Map.OperationalLayers.First() as FeatureLayer;

                // Identify the tapped on feature.
                IdentifyLayerResult result = await MyMapView.IdentifyLayerAsync(incidentLayer, e.Position, 12, true);

                if (result?.Popups?.FirstOrDefault() is Popup popup)
                {
                    // Remove the instructions label.
                    InstructionsLabel.Visibility = System.Windows.Visibility.Hidden;

                    // Create a new popup manager for the popup.
                    MyPopupViewer.PopupManager = new PopupManager(popup);

                    QueryParameters queryParams = new QueryParameters
                    {
                        // Set the geometry to selection envelope for selection by geometry.
                        Geometry = new Envelope((MapPoint)popup.GeoElement.Geometry, 6, 6)
                    };

                    // Select the features based on query parameters defined above.
                    await incidentLayer.SelectFeaturesAsync(queryParams, SelectionMode.New);
                }
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
            }
        }
Example #3
0
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs mapClickPoint)
        {
            IdentifyLayerResult idResult = await MyMapView.IdentifyLayerAsync(serviceRequestLayer, mapClickPoint.Position, 5, false);

            ArcGISFeature serviceRequestFeature = idResult.GeoElements.FirstOrDefault() as ArcGISFeature;

            if (serviceRequestFeature == null)
            {
                return;
            }

            // Create a new feature in the comments table
            ArcGISFeature newComment = relatedTable.CreateFeature() as ArcGISFeature;


            // Add comment text to the 'comments' attribute
            newComment.Attributes["comments"] = "Please show up on time!";


            // Relate the selected service request to the new comment
            serviceRequestFeature.RelateFeature(newComment);
            await relatedTable.AddFeatureAsync(newComment);

            var results = await relatedTable.ApplyEditsAsync();
        }
Example #4
0
        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)
        {
            // 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);
        }
Example #6
0
        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 MyMapViewOnGeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Clear any existing feature selection and results list
            _myFeatureLayer.ClearSelection();
            MyResultsView.ItemsSource = null;

            // Identify the tapped feature
            IdentifyLayerResult results = await MyMapView.IdentifyLayerAsync(_myFeatureLayer, e.Position, 10, false);

            // Return if there are no results
            if (results.GeoElements.Count < 1)
            {
                return;
            }

            // Get the first result
            ArcGISFeature myFeature = (ArcGISFeature)results.GeoElements.First();

            // Select the feature
            _myFeatureLayer.SelectFeature(myFeature);

            // Get the feature table for the feature
            ArcGISFeatureTable myFeatureTable = (ArcGISFeatureTable)myFeature.FeatureTable;

            // Query related features
            IReadOnlyList <RelatedFeatureQueryResult> relatedFeaturesResult = await myFeatureTable.QueryRelatedFeaturesAsync(myFeature);

            // Create a list to hold the formatted results of the query
            List <String> queryResultsForUi = new List <string>();

            // For each query result
            foreach (RelatedFeatureQueryResult result in relatedFeaturesResult)
            {
                // And then for each feature in the result
                foreach (Feature resultFeature in result)
                {
                    // Get a reference to the feature's table
                    ArcGISFeatureTable relatedTable = (ArcGISFeatureTable)resultFeature.FeatureTable;

                    // Get the display field name - this is the name of the field that is intended for display
                    string displayFieldName = relatedTable.LayerInfo.DisplayFieldName;

                    // Get the name of the feature's table
                    string tableName = relatedTable.TableName;

                    // Get the display name for the feature
                    string featureDisplayname = resultFeature.Attributes[displayFieldName].ToString();

                    // Create a formatted result string
                    string formattedResult = $"{tableName} - {featureDisplayname}";

                    // Add the result to the list
                    queryResultsForUi.Add(formattedResult);
                }
            }

            // Update the UI with the result list
            MyResultsView.ItemsSource = queryResultsForUi;
        }
        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 async void OnMapViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            try
            {
                IdentifyLayerResult idResult = await MyMapView.IdentifyLayerAsync(relauteFeatureLayer, e.Position, 5, false);

                ArcGISFeature serviceRequestFeature = idResult.GeoElements.FirstOrDefault() as ArcGISFeature;

                if (serviceRequestFeature == null)
                {
                    return;
                }

                ArcGISFeatureTable serviceRequestTable = serviceRequestFeature.FeatureTable as ArcGISFeatureTable;

                IReadOnlyList <ArcGISFeatureTable> relatedTables = serviceRequestTable.GetRelatedTables();

                if (relatedTables.Count > 0)
                {
                    // Get the comments from the relationship results
                    ArcGISFeatureTable relatedComments = relatedTables.FirstOrDefault();

                    await relatedComments.LoadAsync();

                    if (relatedComments.LoadStatus == LoadStatus.Loaded)
                    {
                        ArcGISFeature newComment = relatedComments.CreateFeature() as ArcGISFeature;

                        newComment.Attributes["鷗_FLN_TEXT_須"] = "Please show up on time!";

                        // Relate the selected service request to the new comment
                        serviceRequestFeature.RelateFeature(newComment);


                        /*
                         * var getUpdatedFeature = await relatedComments.GetUpdatedFeaturesAsync();
                         * ArcGISFeature test = (ArcGISFeature)getUpdatedFeature.FirstOrDefault();
                         *
                         * await test.LoadAsync();
                         * test.Attributes["鷗_FLN_TEXT_須"] = "鷗_JPSTRING_須 | 神谷";
                         *
                         * await relatedComments.UpdateFeatureAsync(test);
                         * serviceRequestFeature.RelateFeature(test);
                         *
                         * ArcGISFeature newComment = relatedComments.CreateFeature() as ArcGISFeature;
                         */
                        //serviceRequestFeature.RelateFeature(f);
                    }
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("検索のエラー", ex.ToString(), "OK");
            }
        }
Example #10
0
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            try
            {
                // Perform the identify operation
                IdentifyLayerResult myIdentifyResult = await MyMapView.IdentifyLayerAsync(_wmsLayer, e.Position, 20, false);

                // Return if there's nothing to show
                if (myIdentifyResult.SublayerResults[1].GeoElements.Count < 1)
                {
                    return;
                }

                // Retrieve the identified feature, which is always a WmsFeature for WMS layers
                //WmsFeature identifiedFeature = (WmsFeature)myIdentifyResult.SublayerResults[0].GeoElements[0].Attributes.Values;
                var identifiedFeature = myIdentifyResult.SublayerResults
                                        .Select(x => x.GeoElements.Where(y => y.Attributes.Values.Contains("РГО")).FirstOrDefault().Attributes);

                var identifiedFeature2 = myIdentifyResult.SublayerResults[1].GeoElements.Where(x => x.Attributes.Count == 17).FirstOrDefault().Attributes;
                var identifiedFeature3 = myIdentifyResult.SublayerResults.Select(x => x.GeoElements.Where(y => y.Attributes.Count == 17).FirstOrDefault().Attributes);
                var coordinateX        = identifiedFeature2.Where(x => x.Key == "x").FirstOrDefault().Value.ToString();
                var coordinateY        = identifiedFeature2.Where(x => x.Key == "y").FirstOrDefault().Value.ToString();
                var pointNumber        = identifiedFeature2.Where(x => x.Key == "geoptnum").FirstOrDefault().Value.ToString();

                var clickedPoint = new Point();
                clickedPoint.CoordinateX = coordinateX;
                clickedPoint.CoordinateY = coordinateY;
                clickedPoint.Number      = pointNumber;

                var StakeOutViewModel = new StakeOutViewModel(clickedPoint);
                await Navigation.PushAsync(new StakeOutPage(StakeOutViewModel));

                // 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 result
                    //await Navigation.PushAsync(new WmsIdentifyResultDisplayPage(htmlContent)
                }

                // Show a page with the HTML content
                // await Navigation.PushAsync(new WmsIdentifyResultDisplayPage(htmlContent));
            }
            catch (Exception ex)
            {
                //await Application.Current.MainPage.DisplayAlert("Error", ex.ToString(), "OK");
            }
        }
Example #11
0
        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");
            }
        }
Example #13
0
        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();
            }
        }
Example #15
0
        private async void MapView_Tapped(object sender, GeoViewInputEventArgs e)
        {
            // Clear any existing selection.
            _damageLayer.ClearSelection();
            _selectedFeature = null;

            // Reset the UI.
            AttachmentsListBox.IsEnabled   = false;
            AttachmentsListBox.ItemsSource = null;
            AddAttachmentButton.IsEnabled  = false;

            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 selected feature as an ArcGISFeature. It is assumed that all GeoElements in the result are of type ArcGISFeature.
                GeoElement    tappedElement = identifyResult.GeoElements.First();
                ArcGISFeature tappedFeature = (ArcGISFeature)tappedElement;

                // Select the feature in the UI and hold a reference to the tapped feature in a field.
                _damageLayer.SelectFeature(tappedFeature);
                _selectedFeature = tappedFeature;

                // Load the feature.
                await tappedFeature.LoadAsync();

                // Get the attachments.
                IReadOnlyList <Attachment> attachments = await tappedFeature.GetAttachmentsAsync();

                // Populate the UI with a list of attachments that have a content type of image/jpeg.
                AttachmentsListBox.ItemsSource = attachments.Where(attachment => attachment.ContentType == "image/jpeg");
                AttachmentsListBox.IsEnabled   = true;
                AddAttachmentButton.IsEnabled  = true;
            }
            catch (Exception ex)
            {
                await new MessageDialog2(ex.ToString(), "Error loading feature").ShowAsync();
            }
        }
        private async void MapView_Tapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            // Clear any existing selection.
            _damageLayer.ClearSelection();

            // Reconfigure the button.
            DeleteButton.IsEnabled = false;
            DeleteButton.Text      = "Delete feature";

            try
            {
                // Perform an identify to determine if a user tapped on a feature.
                IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_damageLayer, e.Position, 5, 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);

                _tappedFeature = queryResult.First();

                // Select the feature.
                _damageLayer.SelectFeature(_tappedFeature);

                // Update the button to allow deleting the feature.
                ConfigureDeletionButton(_tappedFeature);
            }
            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.");
            }
        }
Example #18
0
        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_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
        {
            // Clear any existing result.
            ResultWebView.Visibility = Visibility.Collapsed;

            try
            {
                // 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 the result.
                ResultWebView.NavigateToString(htmlContent);
                ResultWebView.Visibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.ToString(), "Error").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();
            }
        }
Example #21
0
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            // Perform the identify operation
            IdentifyLayerResult myIdentifyResult = await MyMapView.IdentifyLayerAsync(_wmsLayer, e.Position, 20, false);

            // Return if there's nothing to show
            if (myIdentifyResult.GeoElements.Count < 1)
            {
                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;
            //    here might be a good place to check for that and filter out spurious results

            // Show a page with the HTML content
            await Navigation.PushAsync(new WmsIdentifyResultDisplayPage(htmlContent));
        }
        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 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");
            }
        }
Example #24
0
        private async void TrySelectFeature(GeoViewInputEventArgs tapEventDetails)
        {
            try
            {
                // Perform an identify to determine if a user tapped on a feature.
                IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_damageLayer, tapEventDetails.Position, 10, 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);
            }
            catch (Exception ex)
            {
                await new MessageDialog2(ex.ToString(), "There was a problem.").ShowAsync();
            }
        }
        private async void TrySelectFeature(Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs tapEventDetails)
        {
            try
            {
                // Perform an identify to determine if a user tapped on a feature.
                IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_damageLayer, tapEventDetails.Position, 10, 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);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Problem selecting feature", ex.ToString(), "OK");
            }
        }
Example #26
0
        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();
            }
        }
Example #27
0
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            // Check if a feature is selected and the service geodatabase is not on the default version.
            if (_selectedFeature is ArcGISFeature && _serviceGeodatabase.VersionName != _serviceGeodatabase.DefaultVersionName)
            {
                try
                {
                    // Load the feature.
                    await _selectedFeature.LoadAsync();

                    // Update the feature geometry.
                    _selectedFeature.Geometry = e.Location;

                    // Update the table.
                    await _selectedFeature.FeatureTable.UpdateFeatureAsync(_selectedFeature);

                    // Update the service.
                    await((ServiceFeatureTable)_selectedFeature.FeatureTable).ApplyEditsAsync();

                    ShowAlert("Moved feature " + _selectedFeature.Attributes["objectid"]);
                }
                catch (Exception ex)
                {
                    ShowAlert(ex.Message, "Failed to edit feature");
                }
            }
            else
            {
                try
                {
                    // Perform an identify to determine if a user tapped on a feature.
                    IdentifyLayerResult identifyResult = await MyMapView.IdentifyLayerAsync(_featureLayer, 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.
                    _featureLayer.SelectFeature(_selectedFeature);

                    // Get the current value.
                    string currentAttributeValue = _selectedFeature.Attributes[_attributeFieldName].ToString();

                    // Update the combobox selection without triggering the event.
                    DamageBox.SelectedItem = currentAttributeValue;

                    MoveText.IsVisible = DamageBox.IsEnabled = _serviceGeodatabase.VersionName != _serviceGeodatabase.DefaultVersionName;
                }
                catch (Exception ex)
                {
                    ShowAlert(ex.Message, ex.GetType().Name);
                }
                finally
                {
                    // Update the UI for the selection.
                    SwitchView(AttributeView);
                }
            }
        }
        private async void MyMapViewOnGeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Clear any existing feature selection and results list.
                _myFeatureLayer.ClearSelection();
                MyResultsView.ItemsSource = null;

                // Identify the tapped feature.
                IdentifyLayerResult results = await MyMapView.IdentifyLayerAsync(_myFeatureLayer, e.Position, 10, false);

                // Return if there are no results.
                if (results.GeoElements.Count < 1)
                {
                    return;
                }

                // Show the loading indicator (this can take a while).
                LoadingProgress.Visibility = Visibility.Visible;

                // Get the first result.
                ArcGISFeature myFeature = (ArcGISFeature)results.GeoElements.First();

                // Select the feature.
                _myFeatureLayer.SelectFeature(myFeature);

                // Get the feature table for the feature.
                ArcGISFeatureTable myFeatureTable = (ArcGISFeatureTable)myFeature.FeatureTable;

                // Query related features.
                IReadOnlyList <RelatedFeatureQueryResult> relatedFeaturesResult =
                    await myFeatureTable.QueryRelatedFeaturesAsync(myFeature);

                // Create a list to hold the formatted results of the query.
                List <string> queryResultsForUi = new List <string>();

                // For each query result.
                foreach (RelatedFeatureQueryResult result in relatedFeaturesResult)
                {
                    // And then for each feature in the result.
                    foreach (Feature resultFeature in result)
                    {
                        // Get a reference to the feature's table.
                        ArcGISFeatureTable relatedTable = (ArcGISFeatureTable)resultFeature.FeatureTable;

                        // Get the display field name - this is the name of the field that is intended for display.
                        string displayFieldName = relatedTable.LayerInfo.DisplayFieldName;

                        // Get the name of the feature's table.
                        string tableName = relatedTable.TableName;

                        // Get the display name for the feature.
                        string featureDisplayname = resultFeature.Attributes[displayFieldName].ToString();

                        // Create a formatted result string.
                        string formattedResult = $"{tableName} - {featureDisplayname}";

                        // Add the result to the list.
                        queryResultsForUi.Add(formattedResult);
                    }
                }

                // Update the UI with the result list.
                MyResultsView.ItemsSource = queryResultsForUi;

                // Hide the loading indicator.
                LoadingProgress.Visibility = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                await new MessageDialog2(ex.ToString(), "Error").ShowAsync();
            }
        }