Select to view content in your preferred language

How to render a feature layer using multiple fields in the query condition?

1084
4
06-15-2022 06:56 AM
DrewMorris
Emerging Contributor

We are trying to use a custom renderer based on a client's requirements that the values basically operate in two tiers of value:

If FIELD_ONE = ‘TIER 1’ AND DATE is within last 2 years then flag GREEN
If FIELD_ONE = ‘TIER 1’ AND DATE is not within last 2 years, then flag RED

If FIELD_ONE = ‘TIER 2’ AND DATE is within last 5 years then flag GREEN
If FIELD_ONE = ‘TIER 2’ AND DATE is not within last 5 years, then flag RED

We do not have any problems calculating the last 2 or 5 years for the DATE field, so that is not an issue. The actual issue is that the Renderer(s) that are available seem to only allow the use of one field or doesn't fit our needs. 

We have tried using UniqueValueRenderer, but each date being a unique value creates problems. ClassBreaksRenderer does not apply either since the fieldName property only accepts one field. The best method yet that we've found is applying an Arcade expression to the layer's symbology in Portal, and then importing it into the code via PortalItem (still in progress). We would like to know if there are ways to render the layer client-side in the application using our conditions. We looked at ArcadeExpression type as well, but it did not look like there was a way to insert that into the Renderer types. 

 

4 Replies
MarkBockenhauer
Esri Regular Contributor

You could use the unique value renderer with an Arcade expression.   Something like this could work for what you wrote.

var DateDifference = DateDiff(today(),$feature.created_date, "year")
var result ="";
if (($feature.FIELD_ONE == 'TIER 1')&&(DateDifference <= 2)) {
result = 'Green Flag';
} else if (($feature.FIELD_ONE == 'TIER 1')&&(DateDifference >= 2)) {
result = 'Red Flag';
}else if (($feature.FIELD_ONE == 'TIER 2')&&(DateDifference <= 5)) {
result = 'Green Flag';
}else if (($feature.FIELD_ONE == 'TIER 2')&&(DateDifference >= 5)) {
result = 'Red Flag';
}
return result;

 

In mapviewer choose Attributes set an Expression

MarkBockenhauer_0-1655326101283.png

 

Or in ArcGIS Pro

MarkBockenhauer_1-1655326172646.png

 

You can set symbology for each returned result from your expression.

0 Kudos
DrewMorris
Emerging Contributor

Hey @MarkBockenhauer , we do have an Arcade expression set up that performs the correct query just like yours, we just don't know how to implement it client-side in QML via the UniqueValueRenderer type (or any other Renderer). Is there a way to add an Arcade expression to a Renderer QML object? Thanks!

0 Kudos
LucasDanzinger
Esri Frequent Contributor

We don't have a client side API at the moment, so you'll need to set it in the web map.

0 Kudos
DrewMorris
Emerging Contributor

Thanks @LucasDanzinger , I think we're going the route of using multiple feature layers to render these conditions.  We were trying to use a FeatureLayer type with PortalItem but we were unsuccessful due to the reasons my colleague has described here. What we're trying now is loading two different FeatureLayer instances in which each one has a different definitionExpression for FIELD_ONE. 

0 Kudos