/// <summary> /// Imports the selected mxd to the project /// </summary> internal async Task ImportMxd() { // verify that a map can be created from the selection if (MapFactory.CanCreateMapFrom(SelectedMxd)) { // creates a new map and adds it to the project. Also opens the mapview Map map = await MapFactory.CreateMapAsync(SelectedMxd); } }
/// <summary> /// Opens a web map item in a map pane. /// </summary> /// <param name="item"></param> private async void OpenWebMapAsync(object item) { if (item is WebMapItem) { WebMapItem clickedWebMapItem = (WebMapItem)item; //Open WebMap var currentItem = ItemFactory.Create(clickedWebMapItem.ID, ItemFactory.ItemType.PortalItem); if (MapFactory.CanCreateMapFrom(currentItem)) { var newMap = await MapFactory.CreateMapAsync(currentItem); await FrameworkApplication.Panes.CreateMapPaneAsync(newMap); } } }
internal void AddLayerToMap(string url) { //clear previous flag, if any _addFailed = false; OnPropertyChanged("AddStatus"); string id = url; //get the query result var result = _results.FirstOrDefault(ri => ri.Id == id); if (result == null) { throw new ApplicationException(string.Format("Debug: bad id {0}", id)); } if (result.Item == null) { result.Item = ItemFactory.Create(id, ItemFactory.ItemType.PortalItem); } // Syntax can get complicated here // Question - do you need to await the QueuedTask.Run? If so, you need a Func<Task> // and not an Action. //http://stackoverflow.com/questions/20395826/explicitly-use-a-functask-for-asynchronous-lambda-function-when-action-overloa // //As it currently stands, this QueuedTask.Run will return to the caller on the first await QueuedTask.Run(action: async() => { if (LayerFactory.CanCreateLayerFrom(result.Item)) { LayerFactory.CreateLayer(result.Item, MapView.Active.Map); } else if (MapFactory.CanCreateMapFrom(result.Item)) { Map newMap = await MapFactory.CreateMapAsync(result.Item); IMapPane newMapPane = await ProApp.Panes.CreateMapPaneAsync(newMap); } else { _addFailed = true;//cannot be added FrameworkApplication.Current.Dispatcher.Invoke(() => OnPropertyChanged("AddStatus")); } }); }
protected internal async virtual void ExecuteItemAction(string url) { _result = _results.FirstOrDefault(ri => ri.Id == url); if (_result == null) { return; } //Either we open a project and then create the item or //we download the item and then create a project from it. //MapPackage is a special case. We download it, create //a project and then add the map package to it. switch (_result.OnlineItemType) { case OnlineItemType.WebMap: { await Project.CreateAsync(new CreateProjectSettings() { Name = System.IO.Path.GetFileNameWithoutExtension(_result.Name) }); var currentItem = ItemFactory.Create(_result.Id, ItemFactory.ItemType.PortalItem); if (MapFactory.CanCreateMapFrom(currentItem)) { var newMap = await MapFactory.CreateMapAsync(currentItem); await FrameworkApplication.Panes.CreateMapPaneAsync(newMap); } } break; case OnlineItemType.Layer: { var ps = new CreateProjectSettings() { Name = System.IO.Path.GetFileNameWithoutExtension(_result.Name), LocationPath = ConfigWithStartWizardModule.DefaultFolder(), TemplatePath = ConfigWithStartWizardModule.GetDefaultTemplates()[0] //Scene }; _eventToken = ArcGIS.Desktop.Mapping.Events.MapViewInitializedEvent.Subscribe((args) => { Item currentItem = ItemFactory.Create(_result.Id, ItemFactory.ItemType.PortalItem); if (LayerFactory.CanCreateLayerFrom(currentItem)) { QueuedTask.Run(() => LayerFactory.CreateLayer(currentItem, args.MapView.Map)); } ArcGIS.Desktop.Mapping.Events.MapViewInitializedEvent.Unsubscribe(_eventToken); _eventToken = null; }); try { await Project.CreateAsync(ps); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } break; default: var query = new OnlineQuery(_activePortalUri); query.ConfigureData("", _result.Id, _result.Name); await new SubmitQuery().DownloadFileAsync(query); //Project package if (_result.OnlineItemType == OnlineItemType.ProjectPackage) { Project.OpenAsync(query.DownloadFileName); } //Project Template else if (_result.OnlineItemType == OnlineItemType.Template) { var ps = new CreateProjectSettings() { Name = System.IO.Path.GetFileNameWithoutExtension(_result.Name), LocationPath = ConfigWithStartWizardModule.DefaultFolder(), TemplatePath = query.DownloadFileName }; try { await Project.CreateAsync(ps); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } //Map Package else if (_result.OnlineItemType == OnlineItemType.MapPackage) { await Project.CreateAsync(new CreateProjectSettings() { Name = System.IO.Path.GetFileNameWithoutExtension(_result.Name) }); try { var mapPackage = ItemFactory.Create(query.DownloadFileName); await Project.Current.AddAsync(mapPackage); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } break; } }