Select to view content in your preferred language

Filter Map for features selected in data expression

145
0
04-03-2025 08:36 AM
Labels (1)
ctalleygreenville
Regular Contributor

Hi all,

I am having trouble setting filter actions on a map from a serial chart in Dashboard where a similar arcade

expression  is used for the map symbology and data expression. The arcade essentially creates a "new field" on the fly on which to set symbology and create dashboard items.

Background: I have a hosted feature layer for building inspections with a Status Field and a Last Inspected field. (flat file, no related records, no keeping track of previous inspections in this case).

ctalleygreenville_0-1743692335932.png

 

For the Web Map, users wanted to see the inspected buildings displayed with symbols based on different combinations of the inspection status and last inspection date fields.  For example, buildings where status = Not Inspected OR buildings where (Status = Inspected and the Last Inspection date is over 2 yrs old) are all lumped into a "Needs Inspection" category.  Other categories were created similarly.  Symbology is set in the Web Map on the layer using Arcade to change the symbology:

ctalleygreenville_1-1743692608593.png

 

Enter the Dashboard....

The web map is added with the symbology arcade being used.

A data expression using same feature layer (code for data expression at the bottom of this post) is added that essentially creates a feature set similar to what is shown on the map. The features set contains an added field to mimic the symbology settings.  Then a serial chart is created using the data expression. This is the resulting chart where the symbols look like the same symbols on the map:

ctalleygreenville_2-1743693619257.png

The problem that arises is that if the user clicks on one of the bars in the chart, I would like the map to react by filtering only those items.  However, when I access the actions for the chart, this is what happens (see below) - sadness when I realize that field is not present in the layer in the map. 

ctalleygreenville_3-1743694036765.png

Is there any way to make this happen that doesn't require adding another field to the feature layer for symbology purposes?  I looked at creating a view and using that in the map but didn't see a way to "create a field on the fly" like what is possible with SQL Views. Perhaps I missed something.

FacilityID is a field common to the feature layer and the data expression.  It would be great if I could somehow use that??

Even if someone says "nope, not possible" that would be helpful.

Thanks.

__________________________________________________

Here is the data expression code (removed some of the portal and item info at the top:

[
        'FACILITYID',
        'STATUS',
        'SHIFT',
        'Editor',
        'last_edit_date'
    ],
    false
);
 
var BuildingInspectionDictionary = {
    'fields': [   {name: "FACILITYID", alias: "FACILITYID", type: "esriFieldTypeString"},
    {name: "STATUS",alias: "Status", type: "esriFieldTypeString"},
    {name: "SHIFT", alias: "Shift", type: "esriFieldTypeString"},
    {name: "EDITOR",alias: "Editor",type: "esriFieldTypeString"},
    {name: "LASTEDITDATE",alias: "Last Edit Date",type: "esriFieldTypeDate"},
    {name: "INSPECTION_STATUS",alias: "Inspection Status",type: "esriFieldTypeString"}],
    geometryType: "esriGeometryNull",
    features: []
    };

var i = 0;

for (var f in fs) {

  var timeSinceLastInspection = DateDiff(Now(), f["last_edit_date"], 'hours')  
  var theStatus = f["STATUS"]    
  var theBuildingInspectionStatus = ""

  // time returned in datediff is either hours, minutes, seconds, or milliseconds.
  // 8760 hours is 1 year of hours.

  if (((theStatus == "INSPECTED")||(theStatus == "NOT APPLICABLE")) && (timeSinceLastInspection <= 8760)) {    
      theBuildingInspectionStatus = "Inspected within the last 365 days"    
    }  

    else if  ((theStatus == "INSPECTED") && (timeSinceLastInspection > 8760) && (timeSinceLastInspection <=  17520)) {    
     theBuildingInspectionStatus = "Inspected 1 to 2 yrs ago"    
  }    
      else if (((theStatus == "INSPECTED") && (timeSinceLastInspection > 17520)) || (theStatus == "NOT INSPECTED"))  {    
        theBuildingInspectionStatus = "Needs Inspection"    
        }    

        else if ((theStatus == "NOT APPLICABLE") && (timeSinceLastInspection > 8760)){    
          theBuildingInspectionStatus = "Check if Not Applicable"    
        }    
        else {theBuildingInspectionStatus = "Call GIS about this feature status type"}

 
  BuildingInspectionDictionary.features[i++] = {
    attributes:
      {
        FACILITYID: f["FACILITYID"],
        STATUS: f["STATUS"],
        SHIFT: f["SHIFT"],
        EDITOR: f["EDITOR"],
        LASTEDITDATE: f["last_edit_date"],
        INSPECTION_STATUS: theBuildingInspectionStatus
      }
  };
}
 
return FeatureSet(BuildingInspectionDictionary);

 

 

0 Kudos
0 Replies