I have a UniqueValueRenderer assigned to a StreamLayer, assigning "valueExpression" as shown:
valueExpression: `
const featureStartTime = $feature.START;
const now = Date.now();
const TIME_TO_LIVE = 90000;
const timeSinceStart = now - featureStartTime;
const veResult = (timeSinceStart > TIME_TO_LIVE) ? 'expired' : $feature.GROUP_NAME;
return veResult;
`,
'START' and 'GROUP_NAME' are attributes of the features produced by the StreamLayer.
My (Angular 15) application compiles without errors or warnings, but as soon as features begin streaming, the browser console shows an error from "esri.support.arcadeOnDemand": 'arcade-bad-expression', reporting UnexpectedIdentifier on the first line (declaration/assignment of "featureStartTime").
Can someone tell me what's wrong with my declaration of featureStartTime?
Here is the error object, as copied from the browser console:
{
"declaredRootClass": "esri.arcade.lib.parsingerror",
"name": "ParsingError",
"code": "UnexpectedIdentifier",
"index": 22,
"line": 2,
"column": 22,
"len": 15,
"data": {
"value": "featureStartTime"
},
"description": "Unexpected identifier",
"range": {
"start": {
"line": 2,
"column": 21
},
"end": {
"line": 2,
"column": 37
}
}
}
Note about Accepted Solution: I accepted the solution based on the fact that it got rid of the error I report above. Here is the final implementation, fully functional thanks to invaluable tips from @KenBuja and @AnneFitz , in case anyone is trying to solve a similar problem:
valueExpression: `
var timeSinceStart = DateDiff(Now(), Date($feature.START));
var veResult = IIf(timeSinceStart > ${TIME_TO_LIVE}, 'expired', $feature.GROUP_NAME);
return veResult;
`,