Select to view content in your preferred language

Filtering a List Widget using Arcade Formatting

314
4
Jump to solution
08-29-2024 12:08 PM
Labels (1)
MinaNada
Emerging Contributor

Hi everyone,

I'm working on a dashboard for invasive plant management using iNaturalist observations for the National Park Service and was wondering if it's possible to filter iNat observations based on a list of species the parks deem "invasive".

So far, I tried to write some arcade code to take iNaturalist feature layer (which is a live feed layer) and compare them with a species list I wrote. 

The problem I'm running into is that there is no data being populated on the list widget. I'm using the line-item source code to call on the returned data but I'm uncertain on what exactly is causing this issue

My best guess is that somehow, it's not returning correctly since it's in a "if" statement? Attached below is a screenshot of what I'm seeing on the iNaturalist list widget to get a better sense of what I'm talking about.

 

Here's the arcade advanced formatting code:

// Create a list of all invasive species' scientific names across parks
var invasiveSpeciesList = [
    "Agave sisalana", "Albizia julibrissin", "Alternanthera philoxeroides", "Ardisia crenata",
    "Casuarina equisetifolia", "Cocos nucifera", "Heptapleuron actinophylla", "Heptapleuron arboricola",
    "Imperata cylindrica", "Lonicera japonica", "Lespedeza bicolor", "Ligustrum sinense",
    "Liquidambar styraciflua", "Lygodium japonicum", "Lygodium microphyllum", "Melia azedarach",
    "Microstegium vimineum", "Paspalum urvillei", "Perilla frutescens", "Phyllostachys aurea",
    "Pinus elliottii", "Poncirus trifoliata", "Pteridium aquilinum", "Pueraria montana",
    "Salvinia minima", "Salvinia molesta", "Scaevola taccada", "Schinus terebintifolius",
    "Thespesia populnea", "Triadica sebifera", "Wisteria sinensis"
]

// Get the species scientific name from the iNaturalist observation
var speciesName = $datapoint.scientific_name;

// Get the species scientific name from the iNaturalist observation
var commonName = $datapoint.common_name;

//Grab the observed on date
var observedOn = $datapoint.observed_on;

// Check if the species name is in the invasive species list
var isInvasive = IndexOf(invasiveSpeciesList, speciesName) > -1;

// If the species is invasive, return its details
if (isInvasive) {
    return {
        attributes: {
            commonName: commonName,
            speciesName: speciesName,
            observedOn: observedOn
        }
    };
} else {
    // If not invasive, return null to exclude it from the list
    return null;
}

 

And here's my line item source code:

<div style="background-color:#363636;border-left:3px solid white;padding:0.4rem 0.3rem 0.3rem 0.6rem;">
    <p>
        <span style="font-size:16px;color:white;"><span style="opacity:1;">Common Name: {commonName}</span></span>
    </p>
    <p>
        <span style="font-size:14px;color:white;"><span style="opacity:1;padding:1px;">Scientific Name: {speciesName}</span></span>
    </p>
    <p>
        <span style="font-size:14px;color:white;"><span style="border-radius:5px;opacity:1;padding:1px 6px;">Observed on: {observedOn}</span></span>
    </p>
</div>

 

I've also tried writing the line-item source code using:

Observed on: {expression/observedOn}

 

But that also didn't work.

 

And insight or help here would be greatly appreciated 🙂

 

-Mina

 

0 Kudos
1 Solution

Accepted Solutions
ToddW_stl
Esri Contributor

It seems like you only want/need to focus on invasive species - can you filter out the data you don't care about in your web map, or is this data being pulled in via stand-alone layer?  Do you need to show/access all 93 million+ observations in the dashboard at any time?  If you need all records in the dashboard you may try filtering the unwanted data out via a Category or Feature URL parameter, filtering against your list and map elements, and encoding spaces in the URL.

https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-url-parameter-what-is-it/...

https://doc.arcgis.com/en/dashboards/latest/create-and-share/url-parameters.htm

https://doc.arcgis.com/en/dashboards/latest/create-and-share/configuring-actions-on-url-parameters.h... 

UPDATE:   or set a Filter on the Data tab of the List element?

ToddW_stl_0-1724982279911.png

 

View solution in original post

0 Kudos
4 Replies
ToddW_stl
Esri Contributor

for an initial test, can you try to use this in your Line item template (if your field name is "observed_on"?  I'd have to do some digging into Arcade to comment on the advanced formatting.

Observed on: {field/observed_on}

 

0 Kudos
MinaNada
Emerging Contributor

Thanks Todd. I can confirm that using:

Observed on: {field/observed_on}

 

Populates the data. As with:

{field/common_name}
 {field/scientific_name}

 

The issue is that these are not the invasive species of interest from the list in the arcade. Attached is a screenshot below of how it looks now.

 

-Mina

0 Kudos
ToddW_stl
Esri Contributor

It seems like you only want/need to focus on invasive species - can you filter out the data you don't care about in your web map, or is this data being pulled in via stand-alone layer?  Do you need to show/access all 93 million+ observations in the dashboard at any time?  If you need all records in the dashboard you may try filtering the unwanted data out via a Category or Feature URL parameter, filtering against your list and map elements, and encoding spaces in the URL.

https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-url-parameter-what-is-it/...

https://doc.arcgis.com/en/dashboards/latest/create-and-share/url-parameters.htm

https://doc.arcgis.com/en/dashboards/latest/create-and-share/configuring-actions-on-url-parameters.h... 

UPDATE:   or set a Filter on the Data tab of the List element?

ToddW_stl_0-1724982279911.png

 

0 Kudos
MinaNada
Emerging Contributor

 @ToddW_stl I appreciate you sharing these really insightful links. We don't need access to all of these observations. After looking through those resources, I found a way to filter them from the web map itself. I will keep these URL parameters in mind as I'm building out the rest of the dashboard. Thanks!