Example #1
0
        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Clear any existing feature selection and results list.
            _myFeatureLayer.ClearSelection();
            _tableView.Source = null;
            _tableView.ReloadData();

            try
            {
                // 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);
                    }
                }

                // Create the source for the display list.
                _layerListSource = new LayerListSource(queryResultsForUi);

                // Assign the source to the display view.
                _tableView.Source = _layerListSource;

                // Force the table view to refresh its data.
                _tableView.ReloadData();
            }
            catch (Exception ex)
            {
                new UIAlertView("Error", ex.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show();
            }
        }
        private async void MyMapViewOnGeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Clear any existing feature selection and results list
            _myFeatureLayer.ClearSelection();
            _myDisplayList.Source = null;
            _myDisplayList.ReloadData();

            // 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 = String.Format("{0} - {1}", tableName, featureDisplayname);

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

            // Create the source for the display list
            _layerListSource = new LayerListSource(queryResultsForUi);

            // Assign the source to the display view
            _myDisplayList.Source = _layerListSource;

            // Force the table view to refresh its data
            _myDisplayList.ReloadData();
        }