Esempio n. 1
0
        /// <summary>
        /// Retrieves the pop-up info and determines whether there is more than one relationship for the layer. If there is more
        /// than one, the relationships are displayed in a list for the user to choose from before proceeding.
        /// </summary>
        /// <param name="parameter">OnClickPopupInfo from clicked layer</param>
        public void Execute(object parameter)
        {
            relationshipList.Clear();

            OnClickPopupInfo popupInfo = parameter as OnClickPopupInfo;

            popupWindow = popupInfo.Container as InfoWindow;

            // Instantiate the View Model
            if (vm == null)
            {
                vm = new QueryRelatedViewModel(relationshipList, MapApplication.Current.Map);
            }

            // Instantiate the Relationship View
            if (relationshipView == null)
            {
                relationshipView = new RelationshipSelectionView();
            }

            // Instantiate the Keep on Map View
            if (keepOnMapView == null)
            {
                keepOnMapView = new KeepOnMap();
            }

            // Instantiate the No results found View
            if (noRecordsView == null)
            {
                noRecordsView = new NoRecordsFoundView();
            }

            // Set the variables on the ViewModel
            vm.PopupInfo          = popupInfo;
            vm.KeepOnMapView      = keepOnMapView;
            vm.RelationshipView   = relationshipView;
            vm.NoRecordsFoundView = noRecordsView;

            // Set the data context of the RelationshipView and the KeepOnMapView to the QueryRelatedViewModel
            relationshipView.DataContext = vm;
            keepOnMapView.DataContext    = vm;
            noRecordsView.DataContext    = vm;

            // Get the layer info from the pop-up to access the Relationships. Verify the layer is a FeatureLayer to proceed.
            FeatureLayer relatesLayer;
            Layer        lyr = popupInfo.PopupItem.Layer;

            if (lyr is FeatureLayer)
            {
                relatesLayer = lyr as FeatureLayer;

                // Check the number of relationships for the layer
                int relCount = relatesLayer.LayerInfo.Relationships.Count();
                if (relCount > 1) // Layer has more than one relationship
                {
                    foreach (Relationship rel in relatesLayer.LayerInfo.Relationships)
                    {
                        relationshipList.Add(rel);
                    }

                    numberOfRelates = string.Format(Strings.RelationshipsFound,
                                                    relatesLayer.LayerInfo.Relationships.Count().ToString());
                    vm.NumberOfRelationships = numberOfRelates;

                    // Add the available relationships view to the popupWindow.
                    Grid infoWindowGrid = Utils.FindChildOfType <Grid>(popupWindow, 3);
                    infoWindowGrid.Children.Add(relationshipView);


                    // Can now navigate back to attributes and close the popup from the relationship view,
                    // so notify about change in executable state
                    ((DelegateCommand)vm.GoBack).RaiseCanExecuteChanged();
                    ((DelegateCommand)vm.CloseRelationshipView).RaiseCanExecuteChanged();
                }
                else // Layer only has one relationship, so can use Relationship.First to retrieve the ID.
                {
                    // Set the SelectedRelationship property on the ViewModel
                    vm.SelectedRelationship = relatesLayer.LayerInfo.Relationships.First();
                    // Call Execute method on the ViewModel
                    vm.QueryRelated.Execute(vm.SelectedRelationship);
                }
            }
            else
            {
                return;
            }
        }
        /// <summary>
        /// Retrieves the pop-up info and determines whether there is more than one relationship for the layer. If there is more
        /// than one, the relationships are displayed in a list for the user to choose from before proceeding.
        /// </summary>
        /// <param name="parameter">OnClickPopupInfo from clicked layer</param>
        public void Execute(object parameter)
        {
            relationshipList.Clear();

            OnClickPopupInfo popupInfo = parameter as OnClickPopupInfo;
            popupWindow = popupInfo.Container as InfoWindow;

            // Instantiate the View Model
            if (vm == null)
                vm = new QueryRelatedViewModel(relationshipList, MapApplication.Current.Map);

            // Instantiate the Relationship View
            if (relationshipView == null)
                relationshipView = new RelationshipSelectionView();

            // Instantiate the Keep on Map View
            if (keepOnMapView == null)
                keepOnMapView = new KeepOnMap();

            // Instantiate the No results found View
            if (noRecordsView == null)
                noRecordsView = new NoRecordsFoundView();

            // Set the variables on the ViewModel
            vm.PopupInfo = popupInfo;
            vm.KeepOnMapView = keepOnMapView;
            vm.RelationshipView = relationshipView;
            vm.NoRecordsFoundView = noRecordsView;

            // Set the data context of the RelationshipView and the KeepOnMapView to the QueryRelatedViewModel
            relationshipView.DataContext = vm;
            keepOnMapView.DataContext = vm;
            noRecordsView.DataContext = vm;

            // Get the layer info from the pop-up to access the Relationships. Verify the layer is a FeatureLayer to proceed.
            FeatureLayer relatesLayer;
            Layer lyr = popupInfo.PopupItem.Layer;
            if (lyr is FeatureLayer)
            {
                relatesLayer = lyr as FeatureLayer;

                // Check the number of relationships for the layer
                int relCount = relatesLayer.LayerInfo.Relationships.Count();
                if (relCount > 1) // Layer has more than one relationship
                {
                    foreach (Relationship rel in relatesLayer.LayerInfo.Relationships)
                    {
                        relationshipList.Add(rel);
                    }

                    numberOfRelates = string.Format(Strings.RelationshipsFound, 
                        relatesLayer.LayerInfo.Relationships.Count().ToString());
                    vm.NumberOfRelationships = numberOfRelates;

                    // Add the available relationships view to the popupWindow.  
                    Grid infoWindowGrid = Utils.FindChildOfType<Grid>(popupWindow, 3);
                    infoWindowGrid.Children.Add(relationshipView);


                    // Can now navigate back to attributes and close the popup from the relationship view, 
                    // so notify about change in executable state
                    ((DelegateCommand)vm.GoBack).RaiseCanExecuteChanged();
                    ((DelegateCommand)vm.CloseRelationshipView).RaiseCanExecuteChanged();
                }
                else // Layer only has one relationship, so can use Relationship.First to retrieve the ID.
                {
                    // Set the SelectedRelationship property on the ViewModel
                    vm.SelectedRelationship = relatesLayer.LayerInfo.Relationships.First();
                    // Call Execute method on the ViewModel
                    vm.QueryRelated.Execute(vm.SelectedRelationship);
                }
            }
            else
            {
                return;
            }
        }