Select to view content in your preferred language

Costum Arcade symbology expression

350
1
02-21-2024 05:42 AM
Labels (1)
PjotrC
by
New Contributor

Hi all, 

I'm working on a Arcade expression that reads the value in the attribute table and converts the value to a name and a rgb-color code. The problem that occurs is that the symbology doesn't get changed, but within the value tab of the symbology it just produces the string.

 

E.g instead of displaying the color that the rgb-code represents, it has the value:

{"color":"rgb(0, 0, 0)","colorName": "Error")

 

I'm working with the following code: 

// Define attribute column
var ValueColor = $feature.Color

// Error/default color
var DefaultColor = "rgb(0, 0, 0)";
var DefaultName = "Error";

// Define color and name
var Color;
var ColorName;

// CAD_Color_serie_10

if (ValueColor == 10) {
Color = "rgb(255, 0, 0)";
ColorName = $feature.Layer; }

else if (ValueColor == 20) {
Color = "rgb(255, 63, 0)";
ColorName = $feature.Layer; }

else if (ValueColor == 30) {
Color = "rgb(rgb(255, 127, 0)";
ColorName = $feature.Layer; }
else if (ValueColor == 40) {
Color = "rgb(255, 191, 0)";
ColorName = $feature.Layer; }

else if (ValueColor == 50) {
Color = "rgb(255, 255, 0)";
ColorName = $feature.Layer; }

else if (ValueColor == 60) {
Color = "rgb(191, 255, 0)";
ColorName = $feature.Layer; }

else if (ValueColor == 90) {
Color = "rgb(0, 255, 0)";
ColorName = $feature.Layer; }

else if (ValueColor == 130) {
Color = "rgb(0, 255, 255)";
ColorName = $feature.Layer; }

else if (ValueColor == 150) {
Color = "rgb(255, 63 , 0)";
ColorName = $feature.Layer; }

else if (ValueColor == 170) {
Color = "rgb(255, 63 , 0)";
ColorName = $feature.Layer; }

else if (ValueColor == 210) {
Color = "rgb(255, 63 , 0)";
ColorName = $feature.Layer; }

// return Error/Default color
else {
Color = DefaultColor;
ColorName = DefaultName; }

return {
"color": Color,
"colorName": ColorName
};

1 Reply
KenBuja
MVP Esteemed Contributor

Unfortunately, you can't set the symbology directly through Arcade. You have to go into the Styles editor and change the colors for each of the returned values. You can simplify the code this way.

var values = [10, 20, 30, 40, 50, 60, 90, 130, 150, 170, 210]
IIf(IndexOf(values, $feature.Color) > -1, $feature.Layer, 'Error')