gisarcgisarcgis-online

Arcade expression for automatically updating symbology based on time


I have a point layer called 'road blocks' which has three fields: Incident ID, where users can specify the incident ID for any kind of incident; 'start time', where users select the date and time; and 'end time', where users can select the tentative date and time. This layer is published to ArcGIS Online. I want to create symbology based on the start time and end time. When a road block starts, it turns red, and when it ends, it turns green.


Solution

  • Create an Arcade expression in the Visualization profile that returns two or three distinct values (depending on if you want to symbolize active/inactive or before/during/after) based on the current time and start/end times.

    The below example returns three distinct values for before/during/after, using Arcade's Now() function to get the current time:

    var currentTime = Now();
    var status;
    
    if (currentTime < $feature.StartTime) {
      status = "Planned";
    } else if (currentTime <= $feature.EndTime) {
      status = "Active";
    } else {
      status = "Complete";
    }
    
    return status;
    

    Note: depending on how/where the data is being viewed, this likely wont create a 'live' symbology. For example, if you're sharing a web map or app in ArcGIS Online, the symbology won't be reevaluated every second so Now()/currentTime will just represent the time the web map or app was initially loaded and symbology could become outdated until the page is refreshed. This issue can be minimized by setting the layer's refresh interval in the web map or app to the lowest possible value (currently 30 seconds).