Select to view content in your preferred language

Alter a symbol

133
3
Jump to solution
a week ago
Daniel4
New Contributor II

I want to change the fill of polygons, when the user press a button. I am using this to get the render of the layer:

CIMSimpleRenderer currentRenderer = layer.GetRenderer() as CIMSimpleRenderer;

I am saving this render in a dict, to be able to change back later. 

I am creating this, I want to alter to change the color of the polygons:

CIMSimpleRenderer newRenderer = layer.GetRenderer() as CIMSimpleRenderer;

I am using this to make a new fill:

var fill = SymbolFactory.Instance.ConstructSolidFill(ColorFactory.Instance.CreateRGBColor(0, 0, 0));

How can I add the fill to the newRender?

For every polygon feature layer in TOC, I want to change the fill color, but retain the outline color. 

 

 

 

 

1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

Since you have access to the SymbolLayers, you can manipulate any of these layers.

//Get the layers in the symbol
var symbolLayer = polygonSymbol.SymbolLayers.ToList();
//Can modify the layers in the symbol anyway you want.

View solution in original post

0 Kudos
3 Replies
UmaHarano
Esri Regular Contributor

Symbols are made of layers. You can extract the symbol layers from your renderer's symbol and add the fill symbol to these layers. Here is a code snippet

var renderer = lyr.GetRenderer() as CIMSimpleRenderer;
//Get the renderer's symbol and cast it to the type of symbol
var polygonSymbol = renderer.Symbol.Symbol as CIMPolygonSymbol;
//Get the layers in the symbol
var symbolLayer = polygonSymbol.SymbolLayers.ToList();
//Create a solid fill symbol layer
var fill = SymbolFactory.Instance.ConstructSolidFill(ColorFactory.Instance.RedRGB);
//Add the fill to the symbol layers
symbolLayer.Add(fill);
//Set the symbol layers back to the symbol
polygonSymbol.SymbolLayers = symbolLayer.ToArray();
//Set the symbol back to the renderer
renderer.Symbol.Symbol = polygonSymbol;
//Set the renderer back to the layer
lyr.SetRenderer(renderer);

 

You can see the renderer's symbol layers in the UI Like this:

UmaHarano_0-1718198015100.png

 

0 Kudos
Daniel4
New Contributor II

Hi Uma, thanks for your answer. 

I added the new fill, and can see it like this:

Daniel4_0-1718264677512.png

 

But is there a way, to turn off the visibility of the middle symbol layer?

0 Kudos
UmaHarano
Esri Regular Contributor

Since you have access to the SymbolLayers, you can manipulate any of these layers.

//Get the layers in the symbol
var symbolLayer = polygonSymbol.SymbolLayers.ToList();
//Can modify the layers in the symbol anyway you want.
0 Kudos