|
POST
|
Expects is more critical when the Arcade expression is used in Visualization and Labeling. From the documentation: In some profiles, such as Visualization and Labeling, apps only request the data attributes required for rendering each feature or label. You're getting the list of fields from the feature, which will contain all fields in the Popup profile. You can put some logic in there to skip fields you don't want to include for(var field in $feature){
if (field != 'Parking'){
if($feature[field] == "Yes"){
for(var s in sch.fields){
if(sch.fields[s].name == field){
Push(Yes, sch.fields[s].alias);
break;
}
}
}
}
}
... View more
06-17-2024
06:51 AM
|
0
|
1
|
2362
|
|
POST
|
The initial time I tried that, it didn't show up in my pop-up either. Try removing it and adding it back again.
... View more
06-14-2024
07:11 AM
|
0
|
0
|
1342
|
|
POST
|
Since I don't have access to your data, I've been using another dataset to do my testing. This version returns the expected FeatureSet. Can you modify it to use your data? function Memorize(fs) {
var fieldList = Schema(fs)['fields'];
Push(fieldList, {"alias":"Collision Year","editable":true,"length":4,"name":"collision_year","nullable":true,"type":"esriFieldTypeInteger"})
var temp_dict = {
fields: fieldList,
geometryType: '',
features: []
}
for (var f in fs) {
var attrs = {}
for (var attr in f) {
attrs[attr] = f[attr]
}
attrs['collision_year'] = Year(f['date'])
Push(
temp_dict['features'],
{attributes: attrs}
)
}
return FeatureSet(Text(temp_dict))
}// Fetches features from a public portal item
var fs = FeatureSetByPortalItem(
Portal("https://www.arcgis.com"),
// portal item id
"25e36eb0d93d49859f73a4c98b1d3484",
0, // layer id
["*"], // fields to include
false // include or exclude geometry
);
var newFS = Memorize(fs)
var summaryFS = GroupBy(newFS, 'collision_year',
[
{name: 'Maximum magnitude', expression: 'magnitude', statistic: 'Max' }
]);
return summaryFS;
... View more
06-13-2024
06:48 AM
|
0
|
13
|
3776
|
|
POST
|
I had to fix an error in line 13. There was an extra parenthesis at the end.
... View more
06-13-2024
06:17 AM
|
0
|
15
|
5263
|
|
POST
|
This is the whole expression. What do you get when you run in the code editor?
... View more
06-13-2024
06:01 AM
|
0
|
17
|
5264
|
|
POST
|
You can do that with the GroupBy function. Esri has a GitHub site with data expression samples, with one on GroupBy. You can add the year field to your FeatureSet using a modification of @jcarlson's Memorize function, then use GroupBy on it. This should work...but it's untested **Edit...fixing field names. and more fixes function Memorize(fs) {
var fieldList = Schema(fs)['fields'];
Push(fieldList, {"alias":"Collision Year","editable":true,"length":4,"name":"collision_year","nullable":true,"type":"esriFieldTypeInteger"})
var temp_dict = {
fields: fieldList,
geometryType: '',
features: []
}
for (var f in fs) {
var attrs = {}
for (var attr in f) {
attrs[attr] = f[attr]
}
attrs['collision_year'] = Year(f['collision_date'])
Push(
temp_dict['features'],
{attributes: attrs}
)
}
return FeatureSet(Text(temp_dict))
}
var cobportal = Portal('https://bloomingtonin.maps.arcgis.com/');
// assign Crash Dataset variables
var crashDatasetID = '50b2634c8c9443f58cd004f1138ef7ea';var crashLayerID = 0;
// assign FeatureSet variables
var crashFs = FeatureSetByPortalItem(cobportal, crashDatasetID, crashLayerID, ['number_dead', 'gis_incapacitating', 'collision_date'], true);
var newFS = Memorize(crashFs);
var summaryFS = GroupBy(newFS, 'collision_year',
[
{name: 'number_dead', expression: 'TotalDeaths', statistic: 'SUM' },
{name: 'gis_incapacitating', expression: 'TotalInjuries', statistic: 'SUM' }
]);
return summaryFS; I was hoping to use an SQL expression to define the year from the collision-date field to avoid using the Memorize function, but I can never seem to get more complicated SQL expressions to work.
... View more
06-12-2024
02:14 PM
|
1
|
19
|
5276
|
|
POST
|
A data expression must return a FeatureSet. // sets portal url
var cobportal = Portal('https://bloomingtonin.maps.arcgis.com/');
// assign Crash Dataset variables
var crashDatasetID = '50b2634c8c9443f58cd004f1138ef7ea';var crashLayerID = 0;
// assign FeatureSet variables
var crashFs = FeatureSetByPortalItem(cobportal, crashDatasetID, crashLayerID, ['number_dead', 'gis_incapacitating'], true);
// Initialize counters
var totalDeaths = 0;var totalInjuries = 0;
// Iterate through the FeatureSet and calculate totals
for (var crash in crashFs) {
if (IsEmpty(crash.number_dead) == false && crash.number_dead > 0) {
totalDeaths += crash.number_dead;
}
if (IsEmpty(crash.gis_incapacitating) == false && crash.gis_incapacitating == 'Yes') {
totalInjuries += 1;
}
}
// Return the results as a FeatureSet
var theDict = {
'fields': [
{'name':'TotalDeaths', 'type':'esriFieldTypeInteger'},
{'name':'TotalInjuries', 'type':'esriFieldTypeInteger'}
],
'geometryType': '',
'features': [{
'attributes': {
'TotalDeaths': totalDeaths,
'TotalInjuries': totalInjuries
}
}]
};
return FeatureSet(theDict);
... View more
06-12-2024
11:56 AM
|
2
|
21
|
5344
|
|
POST
|
You can use additional chaining to add those extra functions to get the intersect layer var intersectLayer = OrderBy(
Intersects(
Buffer(
FeatureSetByName(
$map,
"STATSGO2Soils"
),
-1,
'feet'
),
$feature
),
'Muname DESC'
);
... View more
06-12-2024
08:47 AM
|
0
|
6
|
2819
|
|
POST
|
If have a field that contains all of those comments, then you should be able to use that field in the pop-up. A pop-up will have the Fields element by default, which shows you all the fields. You can also add a Text element where you can type in a specific field surrounded by curly braces . An example looks like this, with the text "Site ID {SiteID}".
... View more
06-10-2024
07:50 AM
|
0
|
0
|
1094
|
|
POST
|
Can you go into more detail on how the popup would be different for each polygon?
... View more
06-07-2024
05:39 AM
|
0
|
2
|
1151
|
|
POST
|
Your return at line 33 means the GroupBy function didn't run. This sample script gives the expected table. One thing I had to change to make it work properly is to have the fields in the Dictionary start with a string. var fs = FeatureSet(
{"fields":[
{"alias":"Type","name":"Type","type":"esriFieldTypeString"},
{"alias":"Year","name":"Year","type":"esriFieldTypeInteger"}],
"spatialReference":{"wkid":4326},
"geometryType":"",
"features":[
{"geometry":'', "attributes":{"Type":'Apple',"Year":2022}},
{"geometry":'', "attributes":{"Type":'Apple',"Year":2022}},
{"geometry":'', "attributes":{"Type":'Banana',"Year":2023}},
{"geometry":'', "attributes":{"Type":'Pear',"Year":2024}},
]
}
);
var yearDict = {'fields': [{'name':'Type', 'type':'esriFieldTypeString'},
{'name':'y2022', 'type':'esriFieldTypeInteger'},
{'name':'y2023', 'type':'esriFieldTypeInteger'},
{'name':'y2024', 'type':'esriFieldTypeInteger'}],
'geometryType': '',
'features': []};
for (var feature in fs) {
var cat = feature['Type']
var yearone = Iif(feature['Year'] == 2022,1,null)
var yeartwo = Iif(feature['Year'] == 2023,1,null)
var yearthree = Iif(feature['Year'] == 2024,1,null)
Push(yearDict.features, {"attributes": {"Type": cat,
"y2022": yearone,
"y2023": yeartwo,
"y2024": yearthree}})
}
var fs_dict = FeatureSet(Text(yearDict));
//return fs_dict
return GroupBy(fs_dict, ['Type'],
[{ name: '2022', expression: 'y2022', statistic: 'Count' },
{ name: '2023', expression: 'y2023', statistic: 'Count' },
{ name: '2024', expression: 'y2024', statistic: 'Count' }]);
... View more
06-06-2024
12:40 PM
|
0
|
1
|
2740
|
|
POST
|
A little explanation of what my code is doing. It makes the array of targets and loops through them. The variable i is a number representing the position of the element in the array, so it will be 0 for the first loop, 1 for the second loop, and so on. That number gets tacked on the end of the field name if the number isn't equal to zero with this IIf function var tg = iif(i > 0, `target_goal_${i}`, 'target_goal') Unfortunately, you're adding more complexity to this. Looking at the data, the employment fields are only going to be added for the targets "Short_Term_Unemployed_and_Underemployed" and "Long_Term_Unemployed_and_Underemployed. Also, the "Situational_Briefings" target uses a different naming convention. So this code searches for those cases and gets the fields differently. var cap_target_text = Replace($datapoint.target, '_', ' ')
var result = "";
if (!IsEmpty(cap_target_text)) {
var targetArray = Split(cap_target_text, ",")
for (var i in targetArray) {
result += `<br><br><span style="color:#ffffbe"><i>Target: </i></span> ${Trim(targetArray[i])}`;
var tg = iif(i > 0, `target_goal_${i}`, 'target_goal')
if (!IsEmpty($datapoint[tg])) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint[tg]}`;
var tv = iif(i > 0, `target_value_${i}`, 'target_value')
if (!IsEmpty($datapoint[tv])) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint[tv]}`;
var gv = iif(i > 0, `gap_value_${i}`, 'gap_value')
if (!IsEmpty($datapoint[gv])) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint[gv]}`;
var gp = iif(i > 0, `gap_percent_${i}`, 'gap_percent')
if (!IsEmpty($datapoint[gp])) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint[gp]}%`;
if (Find('Unemployed', targetArray[i]) > -1) {
var unemploy_tg = iif(i > 0, `unemploy_target_goal_${i}`, 'unemploy_target_goal')
if (!IsEmpty($datapoint[unemploy_tg])) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint[unemploy_tg]}`;
var unemploy_tv = iif(i > 0, `unemploy_target_value_${i}`, 'unemploy_target_value')
if (!IsEmpty($datapoint[unemploy_tv])) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint[unemploy_tv]}`;
var unemploy_gv = iif(i > 0, `unemploy_gap_value_${i}`, 'unemploy_gap_value')
if (!IsEmpty($datapoint[unemploy_gv])) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint[unemploy_gv]}`;
var unemploy_gp = iif(i > 0, `unemploy_gap_percent_${i}`, 'unemploy_gap_percent')
if (!IsEmpty($datapoint[unemploy_gp])) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint[unemploy_gp]}%`;
}
if (targetArray[i] == 'Situational_Briefings'){
if (!IsEmpty($datapoint.sb_target_goal_5)) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint.sb_target_goal_5}`;
if (!IsEmpty($datapoint.target_value_numeric_5)) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint.target_value_numeric_5}`;
if (!IsEmpty($datapoint.sb_gap_value_5)) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint.sb_gap_value_5}`;
if (!IsEmpty($datapoint.sb_gap_percent_5)) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint.sb_gap_percent_5}`;
}
}
}
return {
textColor: '',
backgroundColor: '',
separatorColor:'',
selectionColor: '',
selectionTextColor: '',
attributes: {
result
}
}
... View more
06-06-2024
08:48 AM
|
1
|
1
|
2965
|
|
POST
|
This code (leaving off the calculation to No Count) give me a FeatureSet. What does it do in your dashboard? var noCount = 0
var ratioDict = {
'fields': [
{'name':'No_Count', 'type':'esriFieldTypeInteger'}
],
'geometryType': '',
'features': [{
'attributes': {
'No_Count': noCount
}
}]
};
// Transform the dictionary into a FeatureSet and return it
return FeatureSet(ratioDict);
... View more
06-06-2024
06:22 AM
|
0
|
1
|
3354
|
|
POST
|
Use this as the final line return FeatureSet(ratioDict);
... View more
06-05-2024
10:09 AM
|
0
|
3
|
3386
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-04-2025 06:39 AM | |
| 1 | 05-01-2026 08:26 AM | |
| 1 | 04-10-2026 12:01 PM | |
| 1 | 04-13-2026 09:11 AM | |
| 1 | 10-11-2023 06:18 AM |
| Online Status |
Offline
|
| Date Last Visited |
Wednesday
|