Zoom to selected feature using Data Expression

1657
5
04-23-2021 02:43 AM
MappyIan
Occasional Contributor II

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
5 Replies
ClaytonBurns2
New Contributor III

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
MappyIan
Occasional Contributor II

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.

TimLiponis
Esri Contributor

@ClaytonBurns2 @MappyIan 

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.

PhilipShutler
New Contributor III

This solution worked!

For reference: add in geometryType of "esriGeometryPoint" (or whatever type of geometry is needed) and then add in the geometry: Geometry(feature). 

Thanks, @TimLiponis 

S_RossWygmans_GISS-T
New Contributor II

I'm trying to combine features of multiple data types (points, lines, and polygons) into the output dictionary to be displayed in a dashboard list, but I cannot get the Zoom action to work with the list. I tried using the geometryType of "esriGeometryAny", but I'm getting an error for an invalid parameter. 

If I assign geometryType of "esriGeometryPoint" to the dictionary, the Zoom action works, but (not surprisingly) all features except point features are filtered out from the list. 

Any ideas?

var portal = Portal('https://gis.ufl.edu/portal');

var redlinePoint = Filter(FeatureSetByPortalItem(
    portal,'bab42c7c586847868ebc5eb89416481e',
    1,
    ['*'],
    true
), "itype = 'Electric'")

var redlineLine = Filter(FeatureSetByPortalItem(
    portal,
    'bab42c7c586847868ebc5eb89416481e',
    4,
    ['*'],
    true
), "itype = 'Electric'")

var redlinePoly = Filter(FeatureSetByPortalItem(
    portal,
    'bab42c7c586847868ebc5eb89416481e',
    3,
    ['*'],
    true
), "itype = 'Electric'")

var features = []
var feat

for (var feature in redlinePoint) {
    feat = {
        'attributes': {
            'objecttype': ['PointObject'],
            'itype': feature['itype'],
            'comment': feature['comment'],
            'last_edited_date': Number(Date(Year(feature['last_edited_date']), Month(feature['last_edited_date']), Day(feature['last_edited_date']))),
        },
        geometry: Geometry(feature)
    };
    Push(features, feat);
};

for (var feature in redlineLine) {
    feat = {
        'attributes': {
            'objecttype': ['LineObject'],
            'itype': feature['itype'],
            'comment': feature['comment'],
            'last_edited_date': Number(Date(Year(feature['last_edited_date']), Month(feature['last_edited_date']), Day(feature['last_edited_date']))),
        },
        geometry: Geometry(feature)
    };
    Push(features, feat);
};

for (var feature in redlinePoly) {
    feat = {
        'attributes': {
            'objecttype': ['LineObject'],
            'itype': feature['itype'],
            'comment': feature['comment'],
            'last_edited_date': Number(Date(Year(feature['last_edited_date']), Month(feature['last_edited_date']), Day(feature['last_edited_date']))),
        },
        geometry: Geometry(feature)
    };
    Push(features, feat);
};


var out_dict = {
    'fields': [
        {name: 'itype', type: 'esriFieldTypeString'},
        {name: 'comment', type: 'esriFieldTypeString'},
        {name: 'last_edited_date', type: 'esriFieldTypeDate'}, 
        {name: 'objecttype', type: 'esriFieldTypeString'},
        {name: 'geometry', type: 'esriFieldTypeGeometry'}
    ], 
    geometryType: '',
    features: features
};

return FeatureSet(Text(out_dict));

 

 

0 Kudos