Pop-up in time-enabled web map to update sums/counts as date changes/arcade

1031
5
Jump to solution
05-12-2021 05:02 PM
Labels (2)
kmsmikrud
Occasional Contributor III

Hello,

I have a web map with AGOL hosted feature layers that are time enabled based on CreationDate. This web map is used in web app builder and has the time-slider widget configured to show survey data for each day. I am trying to figure out in the pop-up how to get the data to update to what the map is showing on the time-slider for summaries and totals.

Currently for the survey polygons, I would like to show feature counts and summaries. The below code works but just summaries the entire point feature layer for all survey days. I can add a date filter but I don't want the data to be tied to a specific date and have a filter for 5/3, 5/4, 5/6...

What is the best way to do this?

 

 

var sm_hschool = Intersects(FeatureSetByName($map, "Herring School:"), $feature);
return Round(Sum(sm_hschool, "NUMSMALL"),0);

 

 

Thanks in advance!

Kathy

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi @kmsmikrud ,

As far as I can see the $layer returns the entire featureset and does not take into account the current state of the layer (like filtered on a date-time range using the slider). It would be a great enhancement to have access to this "state" and being able to get a result taking into account that state.

Are you willing to create an idea for this?

View solution in original post

0 Kudos
5 Replies
XanderBakker
Esri Esteemed Contributor

Hi @kmsmikrud ,

As far as I can see the $layer returns the entire featureset and does not take into account the current state of the layer (like filtered on a date-time range using the slider). It would be a great enhancement to have access to this "state" and being able to get a result taking into account that state.

Are you willing to create an idea for this?

0 Kudos
kmsmikrud
Occasional Contributor III

Hi @XanderBakker ,

Darn I was hoping you would have a solution, but thanks so much for answering so quickly and pardon my delay. I will create an idea for this. I would have thought this would be a pretty typical use for use with the time-slider widget and wanting to count and sum totals for features.

Would you perhaps be able to help troubleshoot a work-around?  For this time series there are only 7 survey dates so I thought in the pop-up I would just filter the data for each survey data and then use that to intersect and sum.

I am a beginner with arcade and had the code below for an expression, but I keep getting token errors at the bottom in the result section. Do you have suggestions for improving this lengthy code and then having it print multiple results?

Thanks in advance and I will create an idea.

Kathy

var dt_query0503 = " CreationDate <= timestamp '2021-05-04 07:59:59' AND CreationDate >= timestamp '2021-05-03 08:00:00'";
var dt_query0504 = " CreationDate <= timestamp '2021-05-05 07:59:59' AND CreationDate >= timestamp '2021-05-04 08:00:00'";
var dt_query0505 = " CreationDate <= timestamp '2021-05-06 07:59:59' AND CreationDate >= timestamp '2021-05-05 08:00:00'";
var dt_query0506 = " CreationDate <= timestamp '2021-05-07 07:59:59' AND CreationDate >= timestamp '2021-05-06 08:00:00'";


var sec_dt03_schools = Filter(FeatureSetByName($map,"Herring School:"),dt_query0503)
var sec_dt04_schools = Filter(FeatureSetByName($map,"Herring School:"),dt_query0504)
var sec_dt05_schools = Filter(FeatureSetByName($map,"Herring School:"),dt_query0505)
var sec_dt06_schools = Filter(FeatureSetByName($map,"Herring School:"),dt_query0506)

    
var section_school03 = Intersects(sec_dt03_schools, $feature);
var FB_03 = Round(Sum(section_school03, "FINAL_BIO"),2)

var section_school04 = Intersects(sec_dt04_schools, $feature);
var FB_04 = Round(Sum(section_school04, "FINAL_BIO"),2)

var section_school05 = Intersects(sec_dt05_schools, $feature);
var FB_05 = Round(Sum(section_school05, "FINAL_BIO"),2)

var section_school06 = Intersects(sec_dt06_schools, $feature);
var FB_06 = Round(Sum(section_school06, "FINAL_BIO"),2)

var result = "";
{
    result = "5/3/21: " + FB_03;
    result += TextFormatting.NewLine + "5/4/21: " + FB_04;
    result += TextFormatting.NewLine + "5/5/21: " + FB_05;
    result += TextFormatting.NewLine + "5/6/21: " + FB_06;
} 
return result;

 

 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @kmsmikrud ,

Sorry for the delay. Can you try the following and see if it works?

// can you validate if the query is valid?
var dt_query0503 = "CreationDate <= timestamp '2021-05-04 07:59:59' AND CreationDate >= timestamp '2021-05-03 08:00:00'";
var dt_query0504 = "CreationDate <= timestamp '2021-05-05 07:59:59' AND CreationDate >= timestamp '2021-05-04 08:00:00'";
var dt_query0505 = "CreationDate <= timestamp '2021-05-06 07:59:59' AND CreationDate >= timestamp '2021-05-05 08:00:00'";
var dt_query0506 = "CreationDate <= timestamp '2021-05-07 07:59:59' AND CreationDate >= timestamp '2021-05-06 08:00:00'";

// access the layer and intersect it a single time with the feature
// and only retrieve the attribute you need
var fs = Intersects(FeatureSetByName($map, "Herring School:", ["FINAL_BIO"], False), $feature);
var sec_dt03_schools = Filter(fs, dt_query0503);
var sec_dt04_schools = Filter(fs, dt_query0504);
var sec_dt05_schools = Filter(fs, dt_query0505);
var sec_dt06_schools = Filter(fs, dt_query0506);

// do the Sum on the featuresets from the previous step
var FB_03 = Round(Sum(sec_dt03_schools, "FINAL_BIO"), 2);
var FB_04 = Round(Sum(sec_dt04_schools, "FINAL_BIO"), 2);
var FB_05 = Round(Sum(sec_dt05_schools, "FINAL_BIO"), 2);
var FB_06 = Round(Sum(sec_dt06_schools, "FINAL_BIO"), 2);

// create the result string
var result = "5/3/21: " + FB_03;
result += TextFormatting.NewLine + "5/4/21: " + FB_04;
result += TextFormatting.NewLine + "5/5/21: " + FB_05;
result += TextFormatting.NewLine + "5/6/21: " + FB_06;

// return the result
return result;

 

0 Kudos
kmsmikrud
Occasional Contributor III

Hi @XanderBakker,

The above code works great!! thank-you!! It is so great to see it work and how you made the code more efficient. I was looking at other examples of code and GeoNet posts, and I see you removed the var result = ""; Why is this not needed in this code but needed in others? Thanks s much!

Kathy

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @kmsmikrud ,

When I use a for loop I normally declare the variable outside the loop and adjust it inside the loop. In this case, we don't have a for loop and can simply declare the variable when we assign the first content to it.