void SetMosaicRule(MosaicLayer mosaicLayer, FeatureLayer footprintLayer, List <long> selectedItems) { ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { // Check if overviews are supposed to be excluded from the selection. string objectIDs = null; if (excludeOverviews) { // Get the selected rows from the feature layer. RowCursor selectedRows = footprintLayer.GetSelection().Search(); if (selectedRows.MoveNext()) { using (var selectedRow = selectedRows.Current) { // Get the value for the Category field. int tag = Convert.ToInt32(selectedRow.GetOriginalValue(selectedRows.FindField("Category"))); // For each row, if Category is not 2 (2 = overview), then add the object id to the list of items to lock to. if (tag != 2) { objectIDs = selectedRow.GetOriginalValue(selectedRows.FindField("OBJECTID")).ToString(); } while (selectedRows.MoveNext()) { tag = Convert.ToInt32(selectedRow.GetOriginalValue(selectedRows.FindField("Category"))); if (tag != 2) { objectIDs += "," + selectedRow.GetOriginalValue(selectedRows.FindField("OBJECTID")).ToString(); } } } } } // Get the mosaic rule of the image sub-layer of the mosaic layer. ImageServiceLayer imageLayer = mosaicLayer.GetImageLayer() as ImageServiceLayer; CIMMosaicRule newMosaicRule = imageLayer.GetMosaicRule(); // If there is no saved mosaic rule, then save the original mosaic rule of the mosaic layer. if (mosaicRule == null) { mosaicRule = newMosaicRule; // Then create a new mosaic rule. newMosaicRule = new CIMMosaicRule(); } // Set the Mosaic Method to 'Lock Raster' newMosaicRule.MosaicMethod = RasterMosaicMethod.LockRaster; // Set the object id's to lock to. if (excludeOverviews) { newMosaicRule.LockRasterID = objectIDs; } else { newMosaicRule.LockRasterID = string.Join(",", selectedItems); } // Update the mosaic layer with the changed mosaic rule. imageLayer.SetMosaicRule(newMosaicRule); }); }
// 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); }); } }