Hello, I am trying to add styling to my polygon layer using values in two different fields. I am new to Arcade and a coding amateur at best. I can get it to work by adding another duplicate layer to my web map and colouring it green if there's something in the Date field, but I want to avoid having to add extra un-necessary layers/complication to my web map.
So, to summise:
Field 1 - To Be Assessed - This is a Y or N text field - pre-populated.
Field 2 - Date Assessed - This is a Date Field - empty to start with, to be filled in by the surveyor.
-----------------------------------------
If field 1 = Y - colour polygon RED
If field 1 = N - colour polygon BLUE
If field 2 is not null, or has a date in it, colour polygon GREEN
So far I have got as far as the below but I am not getting it to work:
----------------------------------------
var survey = $feature['Survey_2024'];
var result = "";
If (IsEmpty(survey)) {Console("SURVEY=?");}
else if (survey == 'N') {result += "NO SURVEY";}
else {result += "YES - SURVEY REQUIRED";}
if (isEmpty($feature.Date_Assessed)) { } else
{result += "COMPLETE";}
result = Trim(result);
if (result=="") {
result = "No Data";
}
return result;
Grateful for any help! Many thanks, Harry
Your pseudo-code makes it pretty easy to understand.
If field 1 = Y - colour polygon RED
If field 1 = N - colour polygon BLUE
If field 2 is not null, or has a date in it, colour polygon GREEN
When you have a series of conditions, the function When is your friend. The conditions will evaluate in order, so put the most important ones first. And you need to include a fallback option at the end.
return When(
!IsEmpty($feature.field_2), 'Green',
$feature.field_1 == 'Y', 'Red',
$feature.field_1 == 'N', 'Blue',
'Other'
)
Note that this will give you categories, but won't directly define the color. You'll need to open up each category and configure the symbol settings accordingly.
Hi Josh
Wow - that makes it look easy! I've tried putting it in as is, but it has the red blocks and doesn't let me save it - have I missed something? Thanks for your help!
Does the editor show you a message if you over over the red sections? Usually that would mean there's something wrong with the field name.
If the field really is "Survey_2021", try using bracket notation, like $feature['Survey_2021'] instead. Capitalization counts!