// This method will be called when the AddToMap button is clicked, this button will be displayed only if more than one scene is selected in the Datagrid private async void AddToMap() { if (SelectedLayer is ImageServiceLayer) { await QueuedTask.Run(() => { ImageServiceLayer imageServiceLayer = (ImageServiceLayer)SelectedLayer; // Store information of original service layer so that it can be displayed back again CIMMosaicRule originalMosaicRule = imageServiceLayer.GetMosaicRule(); string originalLayerName = imageServiceLayer.Name; //Map _map = await GetMapFromProject(Project.Current, "Map"); Map _map = MapView.Active.Map; // Create a Group Layer which will act as a cotainer where selected layers will be added GroupLayer grplayer = (GroupLayer)LayerFactory.Instance.CreateGroupLayer(_map, 0, _groupLayerName); int _sceneCount = 0; foreach (object obj in _selectedList.Reverse <object>()) { Scene scene = obj as Scene; CIMMosaicRule mosaicRule = new CIMMosaicRule(); mosaicRule.MosaicMethod = RasterMosaicMethod.LockRaster; mosaicRule.LockRasterID = scene.ObjectID; ((ImageServiceLayer)imageServiceLayer).SetMosaicRule(mosaicRule); imageServiceLayer.SetName(scene.Name); imageServiceLayer.SetVisibility(false); int ListCount = _selectedList.Count - 1; if (_sceneCount == ListCount) { imageServiceLayer.SetVisibility(true); } else { imageServiceLayer.SetVisibility(false); _sceneCount = _sceneCount + 1; } LayerFactory.Instance.CopyLayer(imageServiceLayer, grplayer); } // Done to display original image service layer imageServiceLayer.SetMosaicRule(originalMosaicRule); imageServiceLayer.SetName(originalLayerName); imageServiceLayer.SetVisibility(false); SelectedLayer = imageServiceLayer; // Set visibilty of Group Layer to be true by default grplayer.SetVisibility(true); // Once the user has entered Group Layer Name, reset the Stack Panel GroupLayerName = ""; NotifyPropertyChanged(() => GroupLayerName); GroupNameVisibility = false; NotifyPropertyChanged(() => GroupNameVisibility); }); } }
// This method will be called when the lock button is clicked private async void LockScenes(object sender) { // Disable the AddToMap button IsAddToMapEnabled = false; NotifyPropertyChanged(() => IsAddToMapEnabled); if ((sender as ICollection <object>).Count == 0) { return; } _selectedList = sender as ICollection <object>; int _selectedListCount = _selectedList.Count; // This will be hit if only one scene has been selected if (_selectedListCount == 1) { if (SelectedLayer is ImageServiceLayer) { await QueuedTask.Run(() => { //Map _map = await GetMapFromProject(Project.Current, "Map"); Map _map = MapView.Active.Map; ImageServiceLayer imageServiceLayer = (ImageServiceLayer)SelectedLayer; ImageServiceLayer originalServiceLayer = (ImageServiceLayer)LayerFactory.Instance.CopyLayer(imageServiceLayer, _map, 1); originalServiceLayer.SetVisibility(false); object obj = _selectedList.First(); Scene scene = obj as Scene; CIMMosaicRule mosaicRule = new CIMMosaicRule(); mosaicRule.MosaicMethod = RasterMosaicMethod.LockRaster; mosaicRule.LockRasterID = scene.ObjectID; imageServiceLayer.SetName(scene.Name); ((ImageServiceLayer)imageServiceLayer).SetMosaicRule(mosaicRule); imageServiceLayer.SetVisibility(true); SelectedLayer = originalServiceLayer; }); } } else if (_selectedList.Count > 1) { // If more than one record has been selected, display the text box to accept GroupName GroupNameVisibility = true; NotifyPropertyChanged(() => GroupNameVisibility); } // Once the lock button has been clicked it should not be clickable again, the same goes for the DataGrid //IsLockButtonEnabled = false; //NotifyPropertyChanged(() => IsLockButtonEnabled); //DataGridEnabled = false; //NotifyPropertyChanged(() => DataGridEnabled); }
// Event Handler, gets name of selected RFT and changes the rendering rule of the Image Service to be displayed accordingly private async void RFT_SelectChanged(object sender) { try { //Map _map1 = await GetMapFromProject(Project.Current, "Map"); Map _map = MapView.Active.Map; if (_map == null) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("AddRasterLayerToMap: Failed to get map."); return; } string dataSoureUrl = ServiceURL; ImageServiceLayer imageServiceLayer = null; await QueuedTask.Run(() => { imageServiceLayer = (ImageServiceLayer)LayerFactory.Instance.CreateLayer(new Uri(dataSoureUrl), _map); if (imageServiceLayer == null) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed to create layer for url:" + dataSoureUrl); return; } ImageServiceLayer isLayer = imageServiceLayer; // Create a new Rendering rule CIMRenderingRule setRenderingrule = new CIMRenderingRule(); // Set the name of the rendering rule. setRenderingrule.Name = sender.ToString(); // Update the image service with the new mosaic rule. isLayer.SetRenderingRule(setRenderingrule); string originalLayerName = isLayer.Name; isLayer.SetName(originalLayerName + "_" + sender.ToString()); }); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } }