How can I configure the Arcade expression for Operations Dashboard to dynamically change data in widgets when map extent changes?

3007
10
Jump to solution
01-04-2022 11:06 AM
Labels (1)
Norchevskyi
New Contributor II

Hi,

I have the Arcade Expression (that was described here:ArcGIS Operations Dashboard Arcade Join Table )  for the Indicator widget, that perform a join operation between a feature layer and a feature table, I applied the rule "When map extent changes" in Map actions for the Indicator widget. But the Widget doesn't display the data, that is empty.

Is it possible to customize the Arcade expression so that the widget dynamically displays data from the current extent?

Thank you,

Roman

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Your FeatureSet is being set to an empty geometry type, which is better for performance. To bring in the spatial component for map filtering, etc., you need to define the geometry type and include the geometry in your features array.

var joinedDict = {
    ...
    geometryType: "esriGeometryPoint" // or whatever geometry type applies
    ...
}

...

        joinedDict.features[i] = {
            attributes: {
                StreetID: tableID,
                Name: p["Address"],
				Depth: t["Depth"],
            },
            geometry: Geometry(p)
        }

...
- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
10 Replies
jcarlson
MVP Esteemed Contributor

Your FeatureSet is being set to an empty geometry type, which is better for performance. To bring in the spatial component for map filtering, etc., you need to define the geometry type and include the geometry in your features array.

var joinedDict = {
    ...
    geometryType: "esriGeometryPoint" // or whatever geometry type applies
    ...
}

...

        joinedDict.features[i] = {
            attributes: {
                StreetID: tableID,
                Name: p["Address"],
				Depth: t["Depth"],
            },
            geometry: Geometry(p)
        }

...
- Josh Carlson
Kendall County GIS
0 Kudos
Norchevskyi
New Contributor II

Josh, thank you for help. I added your your edits to the expression:

var portal = Portal("https://www.arcgis.com/");
var polyfs = FeatureSetByPortalItem(portal,"2c70f00e262a4488b266595720312617",0,["*"],true);
var tablefs = FeatureSetByPortalItem(portal,"227503e1ba6848baa7227b6311c04802",0,["*"],false);

var joinedDict = {
  fields: [
    { name: "StreetID", type: "esriFieldTypeInteger" },
    { name: "Name", type: "esriFieldTypeString" },	
    { name: "Depth", type: "esriFieldTypeDouble" },
  ],
    geometryType: "esriGeometryPoint",
'features':[]};

var i = 0;
for (var t in tablefs) {
    var tableID = t["StreetID"]
    for (var p in Filter(polyfs, "StreetID = "+tableID)){
        joinedDict.features[i] = {
            attributes: {
                StreetID: tableID,
                Name: p["Address"],
				Depth: t["Depth"],
            },
            geometry: Geometry(p)
        }
    }
i++
}

return FeatureSet(Text(joinedDict));

 

The widget is working but does not display data when map extent changes. 

Norchevskyi_0-1641326744563.png

 

Thank you,

Roman

0 Kudos
jcarlson
MVP Esteemed Contributor

You added the appropriate action to the map widget? I can get it to update just fine.

uosl_0-1641328809030.png

 

- Josh Carlson
Kendall County GIS
0 Kudos
Norchevskyi
New Contributor II

Yes, see please my screen:

Norchevskyi_0-1641329007069.png

Thank you,

Roman

0 Kudos
Norchevskyi
New Contributor II

Josh, it's very strange, but when full extent we can see all counts of features, and when zooming we see 0 features

Thank you,

Roman

0 Kudos
jcarlson
MVP Esteemed Contributor

That is very strange indeed! I created a List widget and added a Flash action on it. It seems that the features are coming in with just two particular points in this area:

uosl_0-1641330278755.png

I noticed there are only two values that show up in the Street ID field, so that seems to correspond with this. I'm assuming these values should correspond with the points layer in your screenshots, though, right?

Should you maybe join these based on a matching address field, rather than the street id?

- Josh Carlson
Kendall County GIS
0 Kudos
Norchevskyi
New Contributor II

Josh, the dashhboard is working. It was my mistake, as is joined data had only two values for StreetID field. All is well, but it seems that this method can work with no more than a few hundred features, if there are several thousand features, then the dashboard takes a very long time to process the data.

Thank you so much for your help and time,

Roman

0 Kudos
ScoutStanley
New Contributor III

I am very new to data expressions and implementing within dashboards. I am having hard time figuring out how to get the geometry function to relate to my split choices. Basically, I have a survey123 with a multiple choice question (rent_amounts) and within the dashboard I have a sidebar category. The sidebar category I was able to split out the rent amount choices, but I can't figure out how to get it to filter with the map and address points inputted. Below is the current script. Here is link to dashboard Rental Dashboard 

// Reference layer using the FeatureSetByPortalItem() function. 
var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), '288db7f54ea048c5b6241f156ef0f646' , 0, ['rent_amount'], false);

// Empty dictionary to capture each rental amount reported as separate rows. 
var choicesDict = {'fields': [{ 'name': 'split_choices', 'type': 'esriFieldTypeString'}], 
                    'geometryType': 'esriGeometryPoint', 'features': []}; 

var index = 0; 

// Split comma separated rental amounts and store in dictionary.  
for (var feature in fs) { 
    var split_array  =  Split(feature["rent_amount"], ',') 
    var count_arr = Count(split_array) 
    for(var i = 0; i < count_arr; i++ ){ 
        choicesDict.features[index++] = { 
            'attributes': { 'split_choices': Trim(split_array[i]),  
            }} 
}} 

// Convert dictionary to featureSet. 
var fs_dict = FeatureSet(Text(choicesDict)); 

// Return featureset after grouping by rental amounts. 
return GroupBy(fs_dict, ['split_choices'], 
       [{ name: 'split_count', expression: 'split_choices', statistic: 'COUNT' }]);

 

SupriyaK
New Contributor III

I'm also trying to figure this out. Did you find a solution?

0 Kudos