Hi -
I'm sure someone on here has asked this and received an answer, but I can't find it.
I have a data expression being used within a table element of a dashboard. I'd ideally like the user be able to make a selection (polygon) in the dashboard's map and then have the table be filter spatially based on the selection in the map using layer actions.
This code works great with a category selector, but not with my configured layer actions (it returns no data). I suspect my geometry is not being included in the Push and final FeatureSet (starts at lines 108 to end). Any suggestions on how to correct this?
// custom memorize function to increase performance of featureset
function Memorize(fs) {
var temp_dict = {
fields: Schema(fs)['fields'],
geometryType: Schema(fs).geometryType,
features: []
}
for (var f in fs) {
var attrs = {}
for (var attr in f) {
attrs[attr] = Iif(TypeOf(f[attr]) == 'Date', Number(f[attr]), f[attr])
}
Push(
temp_dict['features'],
{attributes: attrs, geometry: Geometry(f)}
)
}
return FeatureSet(Text(temp_dict))
}
// variable to define the portal URL
var portal = Portal("https://mass-eoeea.maps.arcgis.com");
//Quabbin and Ware Encroachments
var qEncroach = FeatureSetByPortalItem(portal,"1234abc",0,['Date_Found', 'Type', 'Encroachment_Priority', 'Description'],true);
//Wachusett and Sudbury Encroachments
var wEncroach = FeatureSetByPortalItem(portal,"5678def",0,['Date_Found', 'Type', 'Encroachment_Priority', 'Description'],true);
// Create a FeatureSet with all encroachments from Quabbin, Ware and Wachusett
var int_dict = {
fields: [
{'name': 'type', 'type': 'esriFieldTypeString'},
{'name': 'edate', 'type': 'esriFieldTypeDate'},
{'name': 'priority', 'type': 'esriFieldTypeString'},
{'name': 'descript', 'type': 'esriFieldTypeString'}],
geometryType: 'esriGeometryPoint',
"spatialReference": {
"wkid": 102100,
"latestWkid": 3857
}, 'features':[],
};
// Fill intermediate FeatureSet with encroachment info
var i = 0;
for (var f in qEncroach) {
int_dict.features[i] = {
attributes: {
'type': f["Type"],
'edate': DateDiff(f["Date_Found"], Date(1970, 0, 1, 0, 0, 0), "milliseconds"),
'priority': f["Encroachment_Priority"],
'descript': f["Description"],
},
geometry: Geometry(f),
}
i++;
};
for (var g in wEncroach) {
int_dict.features[i] = {
attributes: {
'type': g["Type"],
'edate': DateDiff(g["Date_Found"], Date(1970, 0, 1, 0, 0, 0), "milliseconds"),
'priority': g["Encroachment_Priority"],
'descript': g["Description"],
},
geometry: Geometry(g),
}
i++;
};
Console(Text(int_dict));
var encroach_set = Memorize(FeatureSet(Text(int_dict)))
// Basins
var basins = Memorize(FeatureSetByPortalItem(portal, "987406d7d0614370b6493dfe58c9e62c", 0, ['District', 'Subbasin_Name'], true))
// create final featureset
var finalDict = {
fields: [
{name: "Encroach_Type", type: "esriFieldTypeString"},
{name: "Encroach_Date", type: "esriFieldTypeDate"},
{name: "Encroach_Priority", type: "esriFieldTypeString"},
{name: "Encroach_Description", type: "esriFieldTypeString"},
{name: "SubbasinName", type: "esriFieldTypeString"},
{name: "DistrictName", type: "esriFieldTypeString"},
],
geometryType:"esriGeometryPoint",
"spatialReference": {
"wkid":102100,
"latestWkid":3857
},
features: [],
}
// intersect CMRs with basins to determine which basin each occured in
for(var e in encroach_set) {
var i_basin = First(Intersects(e, basins))
var i_basin_name = Iif(i_basin == null, "No basin", i_basin.Subbasin_Name)
var i_basin_district = Iif(i_basin == null, "No district", i_basin.District)
//add to array
Push(finalDict['features'],
{attributes:{
Encroach_Type: e['type'],
Encroach_Date: e['edate'],
Encroach_Priority: e['priority'],
Encroach_Description: e['descript'],
SubbasinName: i_basin_name,
DistrictName: i_basin_district,
}})
}
Console(Text(finalDict));
return FeatureSet(Text(finalDict))
did you find an answer? I have a watershed polygon i need to filter points by within the dashboard app. but it filters a "square" FULL extent of pol but the actual polyline. is there a script or a feature in the action setting i am missing to do the filter correctly?
Came across this thread because I'm having the same issue as you, Mark. Unfortunately you have to set up your spatial filter using feature data. If you used the "Grouped Values" option, the spatial filter uses the resultant features' envelope, not the actual geometry. See this thread: https://community.esri.com/t5/arcgis-dashboards-questions/selector-spatial-filter-by-polygon-geometr...
That said, if you need to spatially filter based on multiple polygons (which is what I need to do), it seems like you may be out of luck. I've experimented with using multi-part polygons features and using the feature option in the selector widget, but the dashboard spatial filter does not seem to like multi-part polygons 😕
That is exactly what I was doing. I changed it to feature and is working as should. thank you!
there is a tab within the Selector Section for single or multi. but that will only select multiple polygons within that layer. not sure how to filter is with multi polygon from different layers at the same time.
It looks like you're not including geometry for the features when you're appending to your finalDict FeatureSet. Thinking this would maybe do the trick:
Push(finalDict['features'],
{attributes:{
Encroach_Type: e['type'],
Encroach_Date: e['edate'],
Encroach_Priority: e['priority'],
Encroach_Description: e['descript'],
SubbasinName: i_basin_name,
DistrictName: i_basin_district,
},
'geometry':Geometry(e)
})
Another handy trick I've used with feature sets to test if my geometry is coming in as expected is to add a list widget linked to the data expression. Then set the action for the list widget to zoom and flash in the map. If you click through the list items, you should then be able to tell if it is reading into your feature set correctly.