Esempio n. 1
0
        /// <summary>
        /// The OnProjectCollectionChanged event handler is called each time there is a change
        /// in the projectItem collection (either adding or deleting a project item).
        /// </summary>
        /// <param name="projectItemEventArgs"></param>
        private void OnProjectCollectionChanged(ArcGISProjectItemsChangedEventArgs projectItemEventArgs)
        {
            try {
                System.Diagnostics.Debug.WriteLine("In ArcGISProjectItemsChangedEvents");
                if (projectItemEventArgs.ProjectItem is MapProjectItem) //it is a Map
                {
                    var mapProjectItem = projectItemEventArgs.ProjectItem as MapProjectItem;
                    switch (projectItemEventArgs.Action)
                    {
                    case System.Collections.Specialized.NotifyCollectionChangedAction.Add:     //New item has been added to project
                        System.Diagnostics.Debug.WriteLine(string.Format("New map {0} Path {1}", mapProjectItem.Name, mapProjectItem.Path));
                        Map map = MappingModule.FindMap(mapProjectItem.Path);
                        Add(new ComboBoxItem(map.Name));
                        break;

                    case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:            //item has been removed
                        var x = ItemCollection.FirstOrDefault(i => i.ToString() == mapProjectItem.Name); //find in the ComboBox that matches the Map being removed
                        if (x != null)
                        {
                            Remove(x);     //remove the item
                        }
                        break;

                    default:
                        System.Diagnostics.Debug.WriteLine(string.Format("Unknown action item: {0}", projectItemEventArgs.Action.ToString()));
                        break;
                    }
                }
            }
            catch (Exception ex) {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// The OnProjectCollectionChanged event handler is called each time there is a change
 /// in the projectItem collection (either adding or deleting a project item).
 /// </summary>
 /// <param name="projectItemEventArgs"></param>
 private void OnProjectCollectionChanged(ArcGISProjectItemsChangedEventArgs projectItemEventArgs)
 {
     //TODO Step 2 - Code the OnProjectCollectionChanged method.
     if (projectItemEventArgs.ProjectItem is MapProjectItem)   //it is a Map
     //switch (projectItemEventArgs.Action) {
     //    case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
     //}
     {
     }
 }
Esempio n. 3
0
        // Step 2 OnProjectCollectionChanged event

        /// <summary>
        /// Project item changed event.  Fired when a project item is added or removed from the project.
        /// </summary>
        /// <param name="args"></param>
        private void OnProjectCollectionChanged(ArcGISProjectItemsChangedEventArgs args)
        {
            if (args == null)
            {
                return;
            }

            if (_allMaps == null)
            {
                return;
            }

            // don't assume already on the dispatch thread...
            System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(() =>
            {
                // new project item was added
                if (args.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
                {
                    // only care about map project item
                    if (args.ProjectItem is MapProjectItem)
                    {
                        // projectItem.Path contains the URI of the item.  Our list of views has this attribute so try and match the new addition.

                        // does a map with the uri already exist?
                        MapProjectItem map = _allMaps.FirstOrDefault(m => m.Url == args.ProjectItem.Path);
                        // one cannot be found; so add it to our list
                        if (map == null)
                        {
                            _allMaps.Add(args.ProjectItem as MapProjectItem);
                            NotifyPropertyChanged(() => AllMaps);
                        }
                    }
                }
                // project item was removed
                else if (args.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
                {
                    // only care about map project item
                    if (args.ProjectItem is MapProjectItem)
                    {
                        // does a map with the same uri and type already exist in our list
                        MapProjectItem map = _allMaps.FirstOrDefault(m => m.Url == args.ProjectItem.Path);
                        // found a match; so remove it from our list
                        if (map != null)
                        {
                            _allMaps.Remove(args.ProjectItem as MapProjectItem);
                            NotifyPropertyChanged(() => AllMaps);
                        }
                    }
                }
            }));
        }
Esempio n. 4
0
        // TODO Step 2 - add OnProjectCollectionChanged method
        /// <summary>
        /// Subscribe to Project Item changed events which is getting called each
        /// time project items are added or removed in ArcGIS Pro
        /// </summary>
        /// <param name="args">ArcGISProjectItemsChangedEventArgs</param>
        private void OnProjectCollectionChanged(ArcGISProjectItemsChangedEventArgs args)
        {
            if (args == null)
            {
                return;
            }
            var mapItem = args.ProjectItem as MapProjectItem;

            if (mapItem == null)
            {
                return;
            }

            // new project item was added
            switch (args.Action)
            {
            case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
            {
                var foundItem = _allMaps.FirstOrDefault(m => m.Url == mapItem.Path);
                // one cannot be found; so add it to our list
                if (foundItem == null)
                {
                    _allMaps.Add(mapItem);
                }
            }
            break;

            case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
            {
                // only care about map project item
                if (_allMaps.Contains(mapItem))
                {
                    _allMaps.Remove(mapItem);
                }
            }
            break;
            }
        }