Zoom to selected feature using Data Expression

199
3
04-23-2021 02:43 AM
IanHolmes9000
New Contributor

Hello, I am using the new release of ArcGIS Dashboards (April 2021).  I have a List element which is populated from a custom Data Expression and a Map element which is driven by a single point dataset.  I've added actions to the List element so that when an item is selected in the List the map should pan/zoom/flash to the selected feature but I cannot get this to work.

If I set the data source of my List element to be the same as the point dataset in the map then the pan/zoom/flash actions work fine.

Does anyone know what is used as the link between the features drawn in the Map and features in other Dashboard Elements (e.g. the List in my case) as there is no option to specify the matching source and target fields (like you get when you configure a filter)?  I tried adding the OBJECTID from the source (point) data to the FeatureSet created in the custom Data Expression but this didn't resolve the issue.

I'm wondering if I need to add the geometry of the point features displayed in my map to the FeatureSet created in the custom Data Expression.  Would this solve the problem (are the geometries used in the pan/zoom/flash actions)?  I can't find any example of how to do this though, does anyone know?  Code snippets below:

 

// get FeatureSet of point features displayed in the map, including geometry:
var fsCarParkAreas = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), '9e0dc7e170384732a4d28704bc18e446', 0, ['*'], true)
// make a new CombinedDictionary to hold the combined values:
var combinedDict = {
fields: [
{ name: "CarParkID", type: "esriFieldTypeInteger" },
{ name: "CarParkAreaID", type: "esriFieldTypeInteger" },
{ name: "SiteName", type: "esriFieldTypeString" },
{ name: "AreaName", type: "esriFieldTypeString" },
{ name: "PercentOccupied", type: "esriFieldTypeInteger" },
{ name: "Busyness", type: "esriFieldTypeString" },
{ name: "ManualOverride", type: "esriFieldTypeString" },
{ name: "OBJECTID", type: "esriFieldTypeInteger" },
],
geometryType: "",
features: [],
};
// code to loop through all the existing features in fsCarParkAreas
// and add in some extra values based on various conditions
// then add to the combinedDict:
// add details to CombinedDictionary
combinedDict.features[i] = {
attributes: {
CarParkID: cpid,
CarParkAreaID: carparkarea.CarParkAreaID,
SiteName: carpark.SiteName,
AreaName: carparkarea.AreaName,
PercentOccupied: percentoccupied,
ManualOverride: manualoverride,
Busyness: busyness,
OBJECTID: carparkarea.OBJECTID
},
};
// Return CombinedDictionary cast as a feature set
return FeatureSet(Text(combinedDict));

 

 

I think what I'm missing is code to add the geometry of the existing feature in fsCarParkAreas when adding features to the combinedDict (the documentation shows how to create new features but I want to use  the geometry of existing features: https://developers.arcgis.com/arcade/function-reference/data_functions/#featureset)

Any help/pointers would be greatly appreciated.

0 Kudos
3 Replies
ClaytonBurns2
New Contributor II

Hi Ian,

Did you ever find a resolution to this issue? I'm running into the same problem with the exact same workflow. Only filter works once I use a data expression on a list of the layer. All the other options work fine in a list of the layer without a data expression being used.

Did the geometry idea you had end up working?

0 Kudos
IanHolmes9000
New Contributor

Hi Clayton, no I never got this to work and couldn't figure out how to add the geometry so gave up in the end.  If you do ever find a solution, please do post it here as I'd love to know how to achieve it.

0 Kudos
TimLiponis
Esri Contributor

@ClaytonBurns2 @IanHolmes9000 

I have found a way to get this to work using the data expression:

var assignments = FeatureSetByPortalItem(Portal('https://cotgis.maps.arcgis.com'), '31717adc351941d9a990f88e1049714c',0,);
var types = FeatureSetByPortalItem(Portal('https://cotgis.maps.arcgis.com'), '31717adc351941d9a990f88e1049714c',3);
var workers = FeatureSetByPortalItem(Portal('https://cotgis.maps.arcgis.com'), '31717adc351941d9a990f88e1049714c',1);
var dispatchers = FeatureSetByPortalItem(Portal('https://cotgis.maps.arcgis.com'), '31717adc351941d9a990f88e1049714c',2);
var filterAssignments = Filter(assignments,'status > 0')

function getTableValue(features, matchValue, matchField, returnFieldName){
    for (var f in features){
        if (f[matchField] == matchvalue){
            return f[returnFieldName]
        }
    }
    return "N/A"
}


var assign = {
    fields: [
        { name: "description", type: "esriFieldTypeString" },
        { name: "status", type: "esriFieldTypeInteger" },
        { name: "statusdescript", type: "esriFieldTypeString" },
        { name: "notes", type: "esriFieldTypeString" },
        { name: "priority", type: "esriFieldTypeString" },
        { name: "assignmenttype", type: "esriFieldTypeGUID" },
        { name: "workorderid", type: "esriFieldTypeString" },
        { name: "duedate", type: "esriFieldTypeDate" },
        { name: "workerid", type: "esriFieldTypeGUID" },
        { name: "GlobalID", type: "esriFieldTypeGUID" },
        { name: "location", type: "esriFieldTypeString" },
        { name: "declinedcomment", type: "esriFieldTypeString" },
        { name: "assigneddate", type: "esriFieldTypeDate" },
        { name: "inprogressdate", type: "esriFieldTypeDate" },
        { name: "completeddate", type: "esriFieldTypeDate" },
        { name: "declineddate", type: "esriFieldTypeDate" },
        { name: "pauseddate", type: "esriFieldTypeDate" },
        { name: "dispatcherid", type: "esriFieldTypeGUID" },
        { name: "CreationDate", type: "esriFieldTypeDate" },
        { name: "Creator", type: "esriFieldTypeString" },
        { name: "EditDate", type: "esriFieldTypeDate" },
        { name: "Editor", type: "esriFieldTypeString" },
        { name: "Trash", type: "esriFieldTypeString" },
        { name: "Graffiti", type: "esriFieldTypeString" },
        { name: "PowerWash", type: "esriFieldTypeString" },
        { name: "AssignDescription", type: "esriFieldTypeString" },
        { name: "WorkerName", type: "esriFieldTypeString" },
        { name: "DispatcherName", type: "esriFieldTypeString" },
    ],
    geometryType: "esriGeometryPoint",
    features: [],
}
var FsFilter;
var i = 0
var epoch = Date(1970, 0, 01, 0, 0, 0, 0);

for (var f1 in filterAssignments){
    var d = f1.assignmenttype
    var code = f1.status
    var codename = when(code==0,"Unassigned",code==1,"Assigned",code==2,"In Progress",code==3,"Completed",code==4,"Declined",code==5,"Paused",code==6,"Canceled","")
    //return codename    
    FsFilter = Filter(types,'GlobalID like @d')
    //return FsFilter;
    for (var f2 in FsFilter){
        var n = getTableValue(workers,f1.workerid,'globalid','name')
        var o = getTableValue(dispatchers,f1.dispatcherid,'globalid','name')
        var description;
        
        // for (code in codes){
        //     if code.
        // }
        if(f2["description"]=='ada'){
            description = upper(f2["description"])
        }else{
            description = proper(f2["description"])
        }
        assign.features[i++] = {
            attributes: {
                description: f1["description"],
                status: f1["status"],
                statusdescript: codename,
                notes: f1["notes"],
                priority: f1["priority"],
                assignmenttype: f1["assignmenttype"],
                workorderid: f1["workorderid"],
                duedate: f1["duedate"],
                workerid: f1["workerid"],
                GlobalID: f1["GlobalID"],
                location: f1["location"],
                declinedcomment: f1["declinedcomment"],
                assigneddate: DateDiff(f1["assigneddate"],epoch,'milliseconds'),
                inprogressdate: DateDiff(f1["inprogressdate"],epoch,'milliseconds'),
                completeddate: DateDiff(f1["completeddate"],epoch,'milliseconds'),
                declineddate: DateDiff(f1["declineddate"],epoch,'milliseconds'),
                pauseddate: DateDiff(f1["pauseddate"],epoch,'milliseconds'),
                dispatcherid: f1["dispatcherid"],
                CreationDate: DateDiff(f1["CreationDate"],epoch,'milliseconds'),
                Creator: f1["Creator"],
                EditDate: DateDiff(f1["EditDate"],epoch,'milliseconds'),
                Editor: f1["Editor"],
                Trash: f1["Trash"],
                Graffiti: f1["Graffiti"],
                PowerWash: f1["PowerWash"],
                AssignDescription: description,
                WorkerName: n,
                DispatcherName: o
            },
    		geometry: Geometry(f1)
            };
        }
    }
// }
//return assign
return FeatureSet(Text(assign));

Using the geometryType of "esriGeometryPoint" (line 48) and adding in the geometry: Geometry(feature) (line 106) tag in the dictionary before converting the feature set worked for me. 

I'd be curious to see if this works for either of you.

0 Kudos