//Create a CIMSymbol from style item selected in the results gallery list box and //apply this newly created symbol to the feature layer currently selected in Contents pane private async void ApplyTheSelectedSymbol(StyleItem selectedStyleItemToApply) { if (selectedStyleItemToApply == null || string.IsNullOrEmpty(selectedStyleItemToApply.Key)) { return; } await QueuedTask.Run(() => { //Get the feature layer currently selected in the Contents pane FeatureLayer ftrLayer = MappingModule.ActiveTOC.MostRecentlySelectedLayer as FeatureLayer; if (ftrLayer == null) { return; } //Create symbol from style item. CIMSymbol symbolFromStyleItem = selectedStyleItemToApply.GetObject() as CIMSymbol; //Set real world setting for created symbol = feature layer's setting //so that there isn't a mismatch between symbol and feature layer SymbolBuilder.SetRealWorldUnits(symbolFromStyleItem, ftrLayer.UsesRealWorldSymbolSizes); //Get simple renderer from feature layer CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer; //Set current renderer's symbol reference = symbol reference of the newly created symbol currentRenderer.Symbol = SymbolBuilder.MakeSymbolReference(symbolFromStyleItem); //Update feature layer renderer with new symbol ftrLayer.SetRenderer(currentRenderer); }); }
//Creates a new style item and sets its properties from an existing style item public Task <StyleItem> CreateNewStyleItemAsync(StyleItem existingItem) { if (existingItem == null) { throw new System.ArgumentNullException(); } return(QueuedTask.Run(() => { StyleItem item = new StyleItem(); //Get object from existing style item object obj = existingItem.GetObject(); //New style item's properties are set from the existing item item.SetObject(obj); //Key, Name, Tags and Category for the new style item have to be set //These values are NOT populated from the object passed in to SetObject item.Key = "KeyOfTheNewItem"; item.Name = "NameOfTheNewItem"; item.Tags = "TagsForTheNewItem"; item.Category = "CategoryOfTheNewItem"; return item; })); }
//Create a CIMSymbol from style item selected in the results gallery list box and //apply this newly created symbol to the feature layer currently selected in Contents pane private async void ApplyTheSelectedSymbol(StyleItem selectedStyleItemToApply) { if (selectedStyleItemToApply == null || string.IsNullOrEmpty(selectedStyleItemToApply.Key)) return; await QueuedTask.Run(() => { //Get the feature layer currently selected in the Contents pane FeatureLayer ftrLayer = MappingModule.ActiveTOC.MostRecentlySelectedLayer as FeatureLayer; if (ftrLayer == null) return; //Create symbol from style item. CIMSymbol symbolFromStyleItem = selectedStyleItemToApply.GetObject() as CIMSymbol; //Set real world setting for created symbol = feature layer's setting //so that there isn't a mismatch between symbol and feature layer SymbolBuilder.SetRealWorldUnits(symbolFromStyleItem, ftrLayer.UsesRealWorldSymbolSizes); //Get simple renderer from feature layer CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer; //Set current renderer's symbol reference = symbol reference of the newly created symbol currentRenderer.Symbol = SymbolBuilder.MakeSymbolReference(symbolFromStyleItem); //Update feature layer renderer with new symbol ftrLayer.SetRenderer(currentRenderer); }); }