1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// update the fire stats between 2014 - 2018 once timeExtent of// the TimeSlider changestimeSlider.watch("timeExtent", () =>{
updateFiresStats();
});
// This function is called when the timeSlider's timeExtent changes// It queries each layer view for fire stats and updates the chartfunctionupdateFiresStats(){
layerViewsEachAlways().then((layerViewsResults) => {
// query each and every fire layerviews for stats and process the results queryFeaturesForStats(layerViewsResults).then((fireStatsQueryResults) => {
monthDiv.innerHTML = "";
let month;
let acresBurntList = [];
let chartLabels = [];
// fire stats query results are back. Loop through them and process. fireStatsQueryResults.map((result) => {
if (result.error) {
return promiseUtils.resolve(result.error);
}
// The results of the Promise are returned in the value propertyelse {
// if the stats query returned a year for the given layerview// then process and update the chartif (result.value.year !== null){
// extract the year and month from the datelet date = newDate(result.value.year);
let year = date.getFullYear();
// array of burnt acres sum returned in the query results// for each layerview representing fires between 2014-2018 acresBurntList.push(result.value.acres_sum.toFixed(2));
//chart labels will show the year and count of fires for that yearconst label = year + ", " + result.value.fire_counts;
chartLabels.push(label);
}
}
});
// query results have been processed. Update the fires chart to display// sum of acres burnt for the given month and year firesChart.data.datasets[0].data = acresBurntList;
firesChart.data.labels = chartLabels;
firesChart.update();
startMonth = timeSlider.timeExtent.start.toLocaleString("default", { month: "long" });
endMonth = timeSlider.timeExtent.end.toLocaleString("default", { month: "long" });
monthDiv.innerHTML = "<b> Month: <span>" + startMonth + " - " + endMonth + "</span></b>";
});
});
}