Select to view content in your preferred language

Changing the color for a feature using Arcade

354
9
Jump to solution
02-03-2025 08:46 AM
Labels (2)
MPach
by
Frequent Contributor

I'm trying to change the color of a feature using some Arcade logic. I'm not sure what property to set the value against though. Here's the Arcade Code:

var color = When( $feature.duedate > Now(), "#1550f5",
      $feature.duedate < Now() && $feature["device_las"]=="Failed","#f7332a", 
      $feature.duedate < Now(), "#020202",
      $feature.Device_Status == "Inactive", "#fcf132", "#bdbabf" )
     

 I know I can set the color of text and selections using the following:

return {
textColor: color,
backgroundColor: '',
separatorColor: '',
selectionColor: '',
selectionTextColor: '',

}

but I can't figure out what property to use to change the color of feature itself. I wouldn't be surprised if this is a very easy answer.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DavidSolari
MVP Regular Contributor

If you have access to Pro you can try attribute driven symbology, I detail the basics in this thread.

View solution in original post

9 Replies
KenBuja
MVP Esteemed Contributor

You use Arcade to set the outputs ("Active", "Inactive", "Failed", etc), but then you have to set the colors in the Styles dialog.

MPach
by
Frequent Contributor

Ok, I guess that was not my understanding of how this worked. I was under the impression that if set the logic using Arcade the color of the feature would change in the map based on the way the logic was evaluated. I guess you're saying that is not the case, correct? 

0 Kudos
KenBuja
MVP Esteemed Contributor

Unlike the Dashboard example you have in your initial question, the map doesn't get the color information from the Arcade expression for the symbology. It just gets the unique categories. For example, I have a map where I use an expression to classify the points based on the type of survey it is and whether it's been completed.

if ($feature.TYPE == "PRIMARY") {
  if ($feature.SURVEY == "FISH & BENTHIC") {
    if ($feature.BenthicStatus == 0 && $feature.FishStatus == 0) {
      return "Fish and Benthics";
    }
  } else if ($feature.SURVEY == "FISH ONLY") {
    if ($feature.FishStatus == 0) {
      return "Fish Only";
    }
  }
} else if ($feature.TYPE == "SECONDARY") {
  return "Secondary Site";
}

Then I go into the "Pick a style" section of the Styles dialog to select the symbol shape, color, outline, etc for each category.

Snag_ef986d.png

Note that if the attributes of the feature change, its symbololgy will be automatically updated according to your expression. 

 

MPach
by
Frequent Contributor

Ok, that all makes sense. I feel like there is something else that I am missing then. Here's what I'm trying to do. I have a feature class with a bunch of fields describing backflow preventers for our Cross Connections Dept. The fields that are used in my Arcade logic are the Due Date, Last Test Status (Pass, Failed), and Device Status (Active, Inactive). I guess what I need to try to do then is get my Arcade or Python logic somehow to autopopulate a new field that holds the values being described, which in this case are 1) In Compliance 2) Failing and Past Due 3) Past Due 4) Inactive. From there I can use the Arcade expression I currently have to color code those values in the map. From the sounds of it I feel like I might need to publish a feature class and assign attribute rules for this. Any other help or way that you can think of to do something like this?

0 Kudos
DavidSolari
MVP Regular Contributor

If you have access to Pro you can try attribute driven symbology, I detail the basics in this thread.

MPach
by
Frequent Contributor

Thank you. This looks promising. I'm hoping to have time to play with it tomorrow. 

0 Kudos
MPach
by
Frequent Contributor

I think this is going to work. You said it translates over to ArcGIS Online too, correct? Are there any changes that I have to make to have it work in an ArcGIS Online Map? One last question, I plan to use this map in a Field Maps application where new points will be placed on the map daily. Based on my testing it appears the symbology works dynamically based on the field values being used by the Arcade logic. Is there anything that I would need to know for Field Maps using these?

Thank you very much for your help. 

Mark

0 Kudos
DavidSolari
MVP Regular Contributor

I'll admit I didn't test this thoroughly but everything seemed to work in the ArcGIS Online map viewer. Field Maps has its own rendering engine so you'll have to do your own testing in there. Unless I've missed something, there's no way to configure this without Pro so you'll have to avoid symbology edits outside of there, so make sure everyone's happy with the rest of the symbols before you hit production. Good luck!

MPach
by
Frequent Contributor

Much appreciated! This saved me some hassle getting my TS department to set up an attribute rule for me since they won't given me access to the server directly. 

0 Kudos