// Handle a new selected comment record in the table view.
        private async void CommentsTableSource_ServiceRequestCommentSelected(object sender, ServiceRequestCommentSelectedEventArgs e)
        {
            // Clear selected features from the graphics overlay.
            _selectedFeaturesOverlay.Graphics.Clear();

            // Get the map image layer that contains the service request sublayer and the service request comments table.
            ArcGISMapImageLayer serviceRequestsMapImageLayer = (ArcGISMapImageLayer)_myMapView.Map.OperationalLayers[0];

            // Get the (non-spatial) table that contains the service request comments.
            ServiceFeatureTable commentsTable = serviceRequestsMapImageLayer.Tables[0];

            // Get the relationship that defines related service request features for features in the comments table (this is the first and only relationship).
            RelationshipInfo commentsRelationshipInfo = commentsTable.LayerInfo.RelationshipInfos.FirstOrDefault();

            // Create query parameters to get the related service request for features in the comments table.
            RelatedQueryParameters relatedQueryParams = new RelatedQueryParameters(commentsRelationshipInfo)
            {
                ReturnGeometry = true
            };

            try
            {
                // Query the comments table to get the related service request feature for the selected comment.
                IReadOnlyList <RelatedFeatureQueryResult> relatedRequestsResult = await commentsTable.QueryRelatedFeaturesAsync(e.SelectedComment, relatedQueryParams);

                // Get the first result.
                RelatedFeatureQueryResult result = relatedRequestsResult.FirstOrDefault();

                // Get the first feature from the result. If it's null, warn the user and return.
                ArcGISFeature serviceRequestFeature = result.FirstOrDefault() as ArcGISFeature;
                if (serviceRequestFeature == null)
                {
                    UIAlertController alert = UIAlertController.Create("No Feature", "Related feature not found.", UIAlertControllerStyle.Alert);
                    alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                    PresentViewController(alert, true, null);

                    return;
                }

                // Load the related service request feature (so its geometry is available).
                await serviceRequestFeature.LoadAsync();

                // Get the service request geometry (point).
                MapPoint serviceRequestPoint = serviceRequestFeature.Geometry as MapPoint;

                // Create a cyan marker symbol to display the related feature.
                Symbol selectedRequestSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Cyan, 14);

                // Create a graphic using the service request point and marker symbol.
                Graphic requestGraphic = new Graphic(serviceRequestPoint, selectedRequestSymbol);

                // Add the graphic to the graphics overlay and zoom the map view to its extent.
                _selectedFeaturesOverlay.Graphics.Add(requestGraphic);
                await _myMapView.SetViewpointCenterAsync(serviceRequestPoint, 150000);
            }
            catch (Exception ex)
            {
                new UIAlertView("Error", ex.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show();
            }
        }
Пример #2
0
        // Handle a new selected comment record in the table view.
        private async void CommentsListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            // Clear selected features from the graphics overlay.
            _selectedFeaturesOverlay.Graphics.Clear();

            // Get the selected comment feature. If there is no selection, return.
            ArcGISFeature selectedComment = e.AddedItems[0] as ArcGISFeature;

            if (selectedComment == null)
            {
                return;
            }

            // Get the map image layer that contains the service request sublayer and the service request comments table.
            ArcGISMapImageLayer serviceRequestsMapImageLayer = MyMapView.Map.OperationalLayers[0] as ArcGISMapImageLayer;

            // Get the (non-spatial) table that contains the service request comments.
            ServiceFeatureTable commentsTable = serviceRequestsMapImageLayer.Tables[0];

            // Get the relationship that defines related service request features for features in the comments table (this is the first and only relationship).
            RelationshipInfo commentsRelationshipInfo = commentsTable.LayerInfo.RelationshipInfos.FirstOrDefault();

            // Create query parameters to get the related service request for features in the comments table.
            RelatedQueryParameters relatedQueryParams = new RelatedQueryParameters(commentsRelationshipInfo)
            {
                ReturnGeometry = true
            };

            // Query the comments table to get the related service request feature for the selected comment.
            IReadOnlyList <RelatedFeatureQueryResult> relatedRequestsResult = await commentsTable.QueryRelatedFeaturesAsync(selectedComment, relatedQueryParams);

            // Get the first result.
            RelatedFeatureQueryResult result = relatedRequestsResult.FirstOrDefault();

            // Get the first feature from the result. If it's null, warn the user and return.
            ArcGISFeature serviceRequestFeature = result.FirstOrDefault() as ArcGISFeature;

            if (serviceRequestFeature == null)
            {
                MessageBox.Show("Related feature not found.", "No Feature");
                return;
            }

            // Load the related service request feature (so its geometry is available).
            await serviceRequestFeature.LoadAsync();

            // Get the service request geometry (point).
            MapPoint serviceRequestPoint = serviceRequestFeature.Geometry as MapPoint;

            // Create a cyan marker symbol to display the related feature.
            Symbol selectedRequestSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Cyan, 14);

            // Create a graphic using the service request point and marker symbol.
            Graphic requestGraphic = new Graphic(serviceRequestPoint, selectedRequestSymbol);

            // Add the graphic to the graphics overlay and zoom the map view to its extent.
            _selectedFeaturesOverlay.Graphics.Add(requestGraphic);
            await MyMapView.SetViewpointCenterAsync(serviceRequestPoint, 150000);
        }
Пример #3
0
        /// <summary>
        /// Retrieves records related to a feature based on information from the relationship info
        /// </summary>
        internal static async Task <IReadOnlyList <RelatedFeatureQueryResult> > GetRelatedRecords(this FeatureTable featureTable, Feature feature, RelationshipInfo relationshipInfo)
        {
            var parameters = new RelatedQueryParameters(relationshipInfo);

            if (featureTable is ServiceFeatureTable serviceFeatureTable)
            {
                return(await serviceFeatureTable.QueryRelatedFeaturesAsync((ArcGISFeature)feature, parameters, QueryFeatureFields.LoadAll));
            }
            else if (featureTable is GeodatabaseFeatureTable geodatabaseFeatureTable)
            {
                return(await geodatabaseFeatureTable.QueryRelatedFeaturesAsync((ArcGISFeature)feature, parameters));
            }
            return(null);
        }
Пример #4
0
        // When a comment is clicked, get the related feature (service request) and select it on the map.
        private async void CommentsListBox_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            // Clear selected features from the graphics overlay.
            _selectedFeaturesOverlay.Graphics.Clear();

            // Get the clicked record (ArcGISFeature) using the list position. If one is not found, return.
            ArcGISFeature selectedComment = _commentFeatures[e.Position] as ArcGISFeature;

            if (selectedComment == null)
            {
                return;
            }

            // Get the map image layer that contains the service request sublayer and the service request comments table.
            ArcGISMapImageLayer serviceRequestsMapImageLayer = _myMapView.Map.OperationalLayers[0] as ArcGISMapImageLayer;

            // Get the (non-spatial) table that contains the service request comments.
            ServiceFeatureTable commentsTable = serviceRequestsMapImageLayer.Tables[0];

            // Get the relationship that defines related service request features to features in the comments table (this is the first and only relationship).
            RelationshipInfo commentsRelationshipInfo = commentsTable.LayerInfo.RelationshipInfos.FirstOrDefault();

            // Create query parameters to get the related service request for features in the comments table.
            RelatedQueryParameters relatedQueryParams = new RelatedQueryParameters(commentsRelationshipInfo)
            {
                ReturnGeometry = true
            };

            // Query the comments table to get the related service request feature for the selected comment.
            IReadOnlyList <RelatedFeatureQueryResult> relatedRequestsResult = await commentsTable.QueryRelatedFeaturesAsync(selectedComment, relatedQueryParams);

            // Get the first result.
            RelatedFeatureQueryResult result = relatedRequestsResult.FirstOrDefault();

            // Get the first feature from the result. If it's null, warn the user and return.
            ArcGISFeature serviceRequestFeature = result.FirstOrDefault() as ArcGISFeature;

            if (serviceRequestFeature == null)
            {
                // Report to the user that a related feature was not found, then return.
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                AlertDialog         alert        = alertBuilder.Create();
                alert.SetMessage("Related feature not found.");
                alert.Show();

                return;
            }

            // Load the related service request feature (so its geometry is available).
            await serviceRequestFeature.LoadAsync();

            // Get the service request geometry (point).
            MapPoint serviceRequestPoint = serviceRequestFeature.Geometry as MapPoint;

            // Create a cyan marker symbol to display the related feature.
            Symbol selectedRequestSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Cyan, 14);

            // Create a graphic using the service request point and marker symbol.
            Graphic requestGraphic = new Graphic(serviceRequestPoint, selectedRequestSymbol);

            // Add the graphic to the graphics overlay and zoom the map view to its extent.
            _selectedFeaturesOverlay.Graphics.Add(requestGraphic);
            await _myMapView.SetViewpointCenterAsync(serviceRequestPoint, 150000);
        }
        /// <summary>
        /// Gets relationship information for the identified feature and creates the corresponding viewmodels
        /// </summary>
        internal async Task GetRelationshipInfoForFeature(ArcGISFeature feature)
        {
            // clear related records from previous searches
            DestinationRelationships.Clear();
            OriginRelationships.Clear();

            // get RelationshipInfos from the table
            var relationshipInfos = feature.FeatureTable.GetRelationshipInfos();

            // query only the related tables which match the application rules
            // save destination and origin type relationships separately as origin relates features are editable in the app
            foreach (var relationshipInfo in relationshipInfos)
            {
                var parameters = new RelatedQueryParameters(relationshipInfo);

                // only one related table should return given the specific relationship info passed as parameter
                var relatedTable  = feature.FeatureTable.GetRelatedFeatureTable(relationshipInfo);
                var relationships = await feature.FeatureTable.GetRelatedRecords(feature, relationshipInfo);

                if (relationshipInfo.IsValidDestinationRelationship())
                {
                    try
                    {
                        // this is a one to many relationship so it will never return more than one result
                        var relatedFeatureQueryResult = relationships.Where(r => r.IsValidRelationship()).First();

                        var destinationRelationshipViewModel = new DestinationRelationshipViewModel(relationshipInfo, relatedTable, ConnectivityMode);
                        await destinationRelationshipViewModel.InitializeAsync(relatedFeatureQueryResult);

                        DestinationRelationships.Add(destinationRelationshipViewModel);
                    }
                    catch (Exception ex)
                    {
                        UserPromptMessenger.Instance.RaiseMessageValueChanged(null, Resources.GetString("QueryRelatedFeaturesError_Message"), true, ex.StackTrace);
                    }
                }
                else if (relationshipInfo.IsValidOriginRelationship())
                {
                    try
                    {
                        foreach (var relatedFeatureQueryResult in relationships.Where(r => r.IsValidRelationship()))
                        {
                            var originRelationshipsCollection = new ObservableCollection <OriginRelationshipViewModel>();

                            foreach (var relatedFeature in relatedFeatureQueryResult)
                            {
                                var originRelatedFeature = new OriginRelationshipViewModel(relationshipInfo, ConnectivityMode);
                                await originRelatedFeature.LoadViewModel(relatedFeature).ContinueWith(t =>
                                {
                                    originRelationshipsCollection.Add(originRelatedFeature);
                                });
                            }

                            //sort collection
                            SortCollection(originRelationshipsCollection);

                            OriginRelationships.Add(new OriginRelationship(relatedTable, relationshipInfo, originRelationshipsCollection));
                        }
                    }
                    catch (Exception ex)
                    {
                        UserPromptMessenger.Instance.RaiseMessageValueChanged(null, Resources.GetString("GetFeatureRelationshipError_Message"), true, ex.StackTrace);
                    }
                }
            }
        }