Arcade expression for custom symbology

11-11-2018 08:51 PM
Occasional Contributor III

Hi All,

I have read several different blogs and postings to try and achieve a task in ArcGIS Online.  I would like too, based on two fields provide a custom image for a symbol for my webmap.  I want users to nominate an issue (i.e. snake sighting), and then calculate a period of time for when the webmap is viewed, to have the symbol change with age from a 'High' (<12 hours) indicent to 'Low' (> 48 hours) incident. So over the course of 2 days the symbol might change from a red snake to a green one.

The following code is my attempt so far to at least show the correct image within a pop-up.

var startDate = Date($;
var endDate = Now();
var age = DateDiff(endDate, startDate, 'hours');
When (
    age <= 12,'High',
    age > 12 && age <= 24, 'Medium',
    age > 24 && age <= 48, 'Low','Historical');

var issue = ($feature.issue)

if (issue == 'Snake' && age == 'High'){
return "snake1.png"
} else
if (issue == 'Snake' && age == 'Medium'){
return "snake2.png"
} else
if (issue == 'Snake' && age == 'Low'){
return "snake3.png"
} else
return "bird1.png"

I am finding that the bird1.png is showing, even though I only have snake events in my data.

What I ultimately want is a custom symbol using my PNG file, and then go one step further to place a buffer of set distance around point locations and color those with incident level (red/amber/green).

I am hoping this is something Arcade might be able to do.



0 Kudos
1 Reply
MVP Honored Contributor

The variable age isn't getting set to "High", "Medium", or "Low", so the if statements are defaulting to returning the bird icon. The When statement returns the values, but you have to instantiate a variable to hold the return.

Try something like this:

var ageDate = DateDiff(endDate, startDate, 'hours');
var age = When (
    ageDate <= 12,'High',
    ageDate > 12 && ageDate <= 24, 'Medium',
    ageDate > 24 && ageDate <= 48, 'Low','Historical');

What happens to historical dates with the snake sightings? In your code, since you don't account for that, it would also return a bird.

0 Kudos