I have a text filed that I want to symbolize: if there is no value -a red dot; if there is a value -a green dot.
I started but I'm new to Arcade and I'm stuck:
var dot=$feature.Name
if dot=null
return "red"
You can use IIF
iif ($feature.Name != '', 'green', 'red') //if the attribute is a blank string
iif ($feature.Name != null, 'green', 'red') //if the attribute is a null value
IsEmpty will check for nulls and empties. I think throwing that into an IIF would be maybe the simplest yet.
Iif(IsEmpty($feature.Name), 'red', 'green')
I always forget about just using IIF sometimes!
In Arcade (as in many other coding languages), a single "=" assigns a value. "dot = null" will assign the dot variable the value null.
Two equals signs checks the value and returns a true or false. "dot == null" -> True/False.
Also, in Arcade, if statements follow the format
if ( condition ) {
do something
} else {
do something
}
The "else" is optional, but in your case, it will help to return a specific value.
Re-writing your expression to follow that, we would have something like this:
var dot = $feature.Name
if (dot == null){
return "red"
} else {
return "green"
}
Thank you gentlemen! I'll give it a try.
This is what I got which is not what I expected:-)
Some of the dot should be green because there are values in the Name filed.
Well, the values you get from your expression could be anything, it doesn't necessarily know that you've specified a color name and want the dot to be that color. You still need to go into your symbology classes and define them each.
And, as you found, if you don't have a value present in the data, it won't show up as being available for defining in your symbology settings.
Since your expression is really just a binary output, you can just define the "Other" symbology to be the alternate type. Then, even if the "no value" option shows up sometime in the future, you won't have to go in and re-define the symbology settings.