聚合空间统计

尝试一下在线预览

此示例演示在使用 groupByFieldsForStatistics 时,如何在 FeatureLayerView 上运行聚合空间统计信息,以获取分组要素的凸包。每个统计信息组将有一个凸包,表示包含该组中所有要素的最小区域。

工作方式

该地图显示了按地区符号化的国家森林系统(NFS)土地。数据是从美国林务局网站下载的。

当应用程序启动时,查询将运行一次以生成聚合统计信息,以获取按其区域分组的林的计数和总英亩数。统计查询还会返回每个分组要素的凸包几何。凸壳包表示包含一个区域中所有森林的最小区域。

                                                                                                                                                                                                                                                                                                                                                                                                                                        
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>Aggregate spatial statistics | Sample | GeoScene API for JavaScript 4.23</title>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
    <script type="module" src="https://js.geoscene.cn/calcite-components/1.0.0-beta.76/calcite.esm.js"></script>
    <script nomodule="" src="https://js.geoscene.cn/calcite-components/1.0.0-beta.76/calcite.js"></script>
    <link rel="stylesheet" type="text/css" href="https://js.geoscene.cn/calcite-components/1.0.0-beta.76/calcite.css"/>
    <link rel="stylesheet" href="https://js.geoscene.cn/4.23/geoscene/themes/light/main.css" />
    <script src="https://js.geoscene.cn/4.23/"></script>

    <style>
      html,
      body,
      #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        --calcite-shell-panel-max-width: 345px;
        --calcite-shell-panel-min-width: 345px;
      .content-container {
        overflow-x: hidden;
      .geoscene-feature {
        letter-spacing: 0em;
        line-height: 1.55rem;
        font-feature-settings: "liga"1, "calt"0;
        background: #fff;
        padding: 1em;
    </style>
    <script>
    require([
      "geoscene/Map",
      "geoscene/views/MapView",
      "geoscene/layers/FeatureLayer",
      "geoscene/widgets/Legend",
      "geoscene/widgets/Expand",
      "geoscene/widgets/Feature",
      "geoscene/core/reactiveUtils"
    ], (Map, MapView, FeatureLayer, Legend, Expand, Feature, reactiveUtils) =>
      (async () => {
        let chart;
        let groupField = "REGION";
        let statsField = "GIS_ACRES";
        const layer = new FeatureLayer({
          portalItem: {
            id: "6e8c367e59ab425a955623bba36e8e1b"
          outFields: ["*"],
          blendMode: "multiply",
          effect: "drop-shadow(2px, 2px, 2px)",
          title: "National Forests By Regions"
        const map = new Map({
          basemap: {
            portalItem: {
              id: "eedd0d4fff1347dcb188c09832e640b4"
          layers: [layer]
        const view = new MapView({
          container: "viewDiv",
          map: map,
          scale: 73957191,
          center: [-120, 38],
          padding: {
            right: 345
          constraints: {
            minScale: 73957191
        const legendExpand = new Expand({
          content: new Legend({
          expanded: false,
          expandIconClass: "esri-icon-legend",
          expandTooltip: "Expand Legend"
        view.ui.add(legendExpand, "top-left");
        // Provide graphic to a new instance of a Feature widget
        const feature = new Feature({
          // graphic: graphic,
          map: view.map,
          spatialReference: view.spatialReference,
          visible: false
        view.ui.add(feature, "bottom-left");
        const layerView = await view.whenLayerView(layer);
        await reactiveUtils.whenOnce(() => !layerView.updating);
        const aggregateForestDataByRegions = [];
        await runStats();
        // function runs once after when the app loads and runs stats query
        // on the national forests layer to get count, total acres of forests
        // in each region. It will also return convex-hull for each region so that
        // they can be used to show the convex-hull of features in each stats group.
        async function runStats() {
          const consumeStatsByRegion = {
            onStatisticField: statsField,
            outStatisticFieldName: "totalAcresStatsField",
            statisticType: "sum"
          };

          const forestsInRegion = {
            onStatisticField: "OBJECTID",
            outStatisticFieldName: "forestCountStatsField",
            statisticType: "count"
          };

          const aggregatedConvex = {
            statisticType: "convex-hull-aggregate",
            outStatisticFieldName: "aggregateConvexHull"
          };

          const query = layer.createQuery();
          query.groupByFieldsForStatistics = [groupField];
          query.orderByFields = [`${groupField} desc`];
          query.outStatistics = [
            consumeStatsByRegion,
            forestsInRegion,
            aggregatedConvex
          ];

          const statsResults = await layerView.queryFeatures(query);
          const regions = statsResults.features.map(function (feature, i) {
            return feature.attributes[groupField];
          const chartData = statsResults.features.map(function (feature, i) {
            const region = {
              extent: feature.aggregateGeometries.aggregateConvexHull,
              region: feature.attributes[groupField],
              count: feature.attributes.forestCountStatsField,
              totalAcres: feature.attributes.totalAcresStatsField
            return feature.attributes.totalAcresStatsField;
          const chartBlock = document.getElementById("chart-block");
          chartBlock.loading = false;
        let currentBiggestPark = null;
        let previousRegion = "";
        const factSection = document.getElementById("factSection");
        factSection.addEventListener("calciteBlockSectionToggle", (event) => {
        const resultBlock = document.getElementById("resultsHeading");
        const clearAction = document.getElementById("clearAction");
        // this function is called when user hovers over the donut chart
        // it will run stats on the region user is hovering over
        // get the number of forests in the region and get the largest forest
        function getForestStatsByRegion(data) {
          // run the query only when user is hovering over a new region on the chart
          if (data.region !== previousRegion) {
            resultBlock.heading = `Region ${data.region}`;
            resultBlock.disabled = false;
            resultBlock.open = true;
            clearAction.icon = "x";
            clearAction.disabled = false;
            clearAction.addEventListener("click", () => clearStatsInfo());
            const queryBiggestForest = layer.createQuery();
              geometry: data.extent,
              orderByFields: [`${statsField} desc`],
              returnGeometry: true,
              num: 1
            const totalAcres = parseInt(data.totalAcres).toLocaleString("en-US");
            // query for the selected region's forests for region specific stats
            layerView.queryFeatures(queryBiggestForest).then(async (results) => {
              if (results.features.length) {
                document.getElementById(
                  "acreageCount"
                ).innerHTML = `<b>${totalAcres}</b>`;
                document.getElementById(
                  "forestCount"
                ).innerHTML = `<b>${data.count}</b>`;
                currentBiggestPark = results.features[0];
                if (factSection.open) {
                  await handleParkPopup();
                const card = document.createElement("calcite-card");
                const cardTitle = document.createElement("span");
                cardTitle.slot = "title";
                const cardSubtitle = document.createElement("span");
                cardSubtitle.slot = "subtitle";
                cardSubtitle.innerHTML = `${currentBiggestPark.attributes.GIS_ACRES.toLocaleString("en-US")} acres`;
                const button = document.createElement("calcite-button");
                button.innerHTML = `Visit ${currentBiggestPark.attributes.FORESTNAME}`;
                button.iconEnd = `launch`;
                button.target = "_blank";
                button.width = "full";
                button.slot = "footer-trailing";
                factSection.innerHTML = "";
                factSection.text = `Highlight largest forest in region ${data.region}`;
        // this function is called once after the aggregate spatial statistics runs
        // show the total acres of forests in each region in the chart
        function updateChart(regions, chartData) {
          // Get the canvas element and render the chart in it
          const canvasElement = document.getElementById("chart");
          chart = new Chart(canvasElement.getContext("2d"), {
            type: "doughnut",
            data: {
              labels: regions,
              datasets: [
                  backgroundColor: [
                    "#64bfae",
                    "#b277b0",
                    "#b8d161",
                    "#49b1d8",
                    "#f17474",
                    "#fda853",
                    "#f8a1e0",
                    "#ffe569",
                    "#c69a6f"
                  borderWidth: 0,
                  data: chartData
            options: {
              responsive: false,
              legend: {
                display: false
              title: {
                display: false
              tooltips: {
                callbacks: {
                  label: (tooltipItem, data) => {
                    const acres =
                    return (
                      "Region: " + data.labels[tooltipItem.index] + " Total acres: " + parseInt(acres).toLocaleString("en-US")
          async function updateMapForSelectedRegion(data) {
              geometry: data.extent,
              symbol: {
                type: "simple-fill",
                color: [0, 0, 0, 0],
                outline: {
                  width: "3px",
                  color: "magenta"
              filter: {
                where: `${groupField} = '${data.region}'`
              excludedEffect: "blur(0pt) opacity(0.5) grayscale(1)",
              includedEffect: "drop-shadow(3pt 2pt 2pt rgba(50, 50, 50, 0.5))"
          // Add the convex hull of grouped forests for that region
          // set a featureffect on the layerview
          // run stats on forests of the clicked region
          canvasElement.addEventListener("mousemove", async () => {
            const data = await getRegionFromChart(event);
            if (data) {
              await updateMapForSelectedRegion(data);
        // runs when user clicks on the largest forest stats
        let highlight;
        async function handleParkPopup() {
          if (currentBiggestPark && factSection.open) {
            if (!feature.visible) {
              feature.visible = true;
            if (feature.graphic && feature.graphic.attributes.OBJECTID !== currentBiggestPark.attributes.OBJECTID){
          } else {
            feature.visible = false;
        // clear out region related graphics and stats when user is not hovering over the chart
        function clearStatsInfo() {
          layerView.featureEffect = null;
          feature.visible = false;
          resultBlock.heading = `No region selected`;
          resultBlock.disabled = true;
          resultBlock.open = false;
          clearAction.icon = "blank";
          clearAction.disabled = true;
          clearAction.addEventListener("click", () => clearStatsInfo());
          factSection.open = false;
        // called when user hovers over the donut chart
        async function getRegionFromChart(event) {
          const activePoints = chart.getElementsAtEvent(event);
          let selectedRegion = null;
          if (activePoints[0]) {
            const chartData = activePoints[0]["_chart"].config.data;
            const idx = activePoints[0]["_index"];
            const label = chartData.labels[idx];
            const value = chartData.datasets[0].data[idx];
            aggregateForestDataByRegions.forEach((data) => {
              if (data.region === label) {
          return selectedRegion;
    </script>
</head>

<body>
  <calcite-shell>
    <div id="viewDiv"></div>
    <calcite-shell-panel slot="contextual-panel" width-scale="">
      <calcite-panel heading="Total acreages of forests by region">
        <calcite-block open loading id="chart-block">
          <canvas id="chart" height="250" width="315" style="margin: 0 auto 1rem"></canvas>
          <calcite-notice active width="full" scale="s">
              <span slot="title">Instructions</span>
              <div slot="message">
                  Hover over the donut chart to see facts about forests in that
                  region.
              </div>
          </calcite-notice>
        </calcite-block>
        <calcite-block disabled id="resultsHeading" heading="No region selected" summary="Forest facts">
          <calcite-action disabled id="clearAction" slot="control" text="Clear" icon="blank">
          </calcite-action>
          <calcite-label layout="inline-space-between">Forests<span id="forestCount"></span></calcite-label>
          <calcite-label layout="inline-space-between">Acres<span id="acreageCount"></span></calcite-label>
          <calcite-block-section id="factSection" text="Highlight largest forest" toggle-display="switch">
          </calcite-block-section>
        </calcite-block>
    </calcite-panel>
    </calcite-shell-panel>
  </calcite-shell>
  </body>
</html>

然后,创建一个图表以显示每个区域中森林的总英亩数。用户可以将鼠标悬停在图表上以查看地图上的森林区域。表示包含该区域中所有森林的最小区域的凸包将添加到地图中,并且 featureEffect 将应用于图层视图以高亮显示所选区域中的森林。

                                                                                                                                                                                                                                                                                                                                                                                                                                        
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>Aggregate spatial statistics | Sample | GeoScene API for JavaScript 4.23</title>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
    <script type="module" src="https://js.geoscene.cn/calcite-components/1.0.0-beta.76/calcite.esm.js"></script>
    <script nomodule="" src="https://js.geoscene.cn/calcite-components/1.0.0-beta.76/calcite.js"></script>
    <link rel="stylesheet" type="text/css" href="https://js.geoscene.cn/calcite-components/1.0.0-beta.76/calcite.css"/>
    <link rel="stylesheet" href="https://js.geoscene.cn/4.23/geoscene/themes/light/main.css" />
    <script src="https://js.geoscene.cn/4.23/"></script>

    <style>
      html,
      body,
      #viewDiv {
          padding: 0;
          margin: 0;
          height: 100%;
          width: 100%;
        --calcite-shell-panel-max-width: 345px;
        --calcite-shell-panel-min-width: 345px;
      .content-container {
        overflow-x: hidden;
      .geoscene-feature {
        letter-spacing: 0em;
        line-height: 1.55rem;
        font-feature-settings: "liga"1, "calt"0;
        background: #fff;
        padding: 1em;
    </style>
    <script>
    require([
      "geoscene/Map",
      "geoscene/views/MapView",
      "geoscene/layers/FeatureLayer",
      "geoscene/widgets/Legend",
      "geoscene/widgets/Expand",
      "geoscene/widgets/Feature",
      "geoscene/core/reactiveUtils"
    ], (Map, MapView, FeatureLayer, Legend, Expand, Feature, reactiveUtils) =>
      (async () => {
        let chart;
        let groupField = "REGION";
        let statsField = "GIS_ACRES";
        const layer = new FeatureLayer({
          portalItem: {
            id: "6e8c367e59ab425a955623bba36e8e1b"
          outFields: ["*"],
          blendMode: "multiply",
          effect: "drop-shadow(2px, 2px, 2px)",
          title: "National Forests By Regions"
        const map = new Map({
          basemap: {
            portalItem: {
              id: "eedd0d4fff1347dcb188c09832e640b4"
          layers: [layer]
        const view = new MapView({
          container: "viewDiv",
          map: map,
          scale: 73957191,
          center: [-120, 38],
          padding: {
            right: 345
          constraints: {
            minScale: 73957191
        const legendExpand = new Expand({
          content: new Legend({
          expanded: false,
          expandIconClass: "esri-icon-legend",
          expandTooltip: "Expand Legend"
        view.ui.add(legendExpand, "top-left");
        // Provide graphic to a new instance of a Feature widget
        const feature = new Feature({
          // graphic: graphic,
          map: view.map,
          spatialReference: view.spatialReference,
          visible: false
        view.ui.add(feature, "bottom-left");
        const layerView = await view.whenLayerView(layer);
        await reactiveUtils.whenOnce(() => !layerView.updating);
        const aggregateForestDataByRegions = [];
        await runStats();
        // function runs once after when the app loads and runs stats query
        // on the national forests layer to get count, total acres of forests
        // in each region. It will also return convex-hull for each region so that
        // they can be used to show the convex-hull of features in each stats group.
        async function runStats() {
          const consumeStatsByRegion = {
            onStatisticField: statsField,
            outStatisticFieldName: "totalAcresStatsField",
            statisticType: "sum"
          const forestsInRegion = {
            onStatisticField: "OBJECTID",
            outStatisticFieldName: "forestCountStatsField",
            statisticType: "count"
          const aggregatedConvex = {
            statisticType: "convex-hull-aggregate",
            outStatisticFieldName: "aggregateConvexHull"
          const query = layer.createQuery();
          query.orderByFields = [`${groupField} desc`];
          const statsResults = await layerView.queryFeatures(query);
          const regions = statsResults.features.map(function (feature, i) {
            return feature.attributes[groupField];
          const chartData = statsResults.features.map(function (feature, i) {
            const region = {
              extent: feature.aggregateGeometries.aggregateConvexHull,
              region: feature.attributes[groupField],
              count: feature.attributes.forestCountStatsField,
              totalAcres: feature.attributes.totalAcresStatsField
            return feature.attributes.totalAcresStatsField;
          const chartBlock = document.getElementById("chart-block");
          chartBlock.loading = false;
        let currentBiggestPark = null;
        let previousRegion = "";
        const factSection = document.getElementById("factSection");
        factSection.addEventListener("calciteBlockSectionToggle", (event) => {
        const resultBlock = document.getElementById("resultsHeading");
        const clearAction = document.getElementById("clearAction");
        // this function is called when user hovers over the donut chart
        // it will run stats on the region user is hovering over
        // get the number of forests in the region and get the largest forest
        function getForestStatsByRegion(data) {
          // run the query only when user is hovering over a new region on the chart
          if (data.region !== previousRegion) {
            resultBlock.heading = `Region ${data.region}`;
            resultBlock.disabled = false;
            resultBlock.open = true;
            clearAction.icon = "x";
            clearAction.disabled = false;
            clearAction.addEventListener("click", () => clearStatsInfo());
            const queryBiggestForest = layer.createQuery();
              geometry: data.extent,
              orderByFields: [`${statsField} desc`],
              returnGeometry: true,
              num: 1
            const totalAcres = parseInt(data.totalAcres).toLocaleString("en-US");
            // query for the selected region's forests for region specific stats
            layerView.queryFeatures(queryBiggestForest).then(async (results) => {
              if (results.features.length) {
                document.getElementById(
                  "acreageCount"
                ).innerHTML = `<b>${totalAcres}</b>`;
                document.getElementById(
                  "forestCount"
                ).innerHTML = `<b>${data.count}</b>`;
                currentBiggestPark = results.features[0];
                if (factSection.open) {
                  await handleParkPopup();
                const card = document.createElement("calcite-card");
                const cardTitle = document.createElement("span");
                cardTitle.slot = "title";
                const cardSubtitle = document.createElement("span");
                cardSubtitle.slot = "subtitle";
                cardSubtitle.innerHTML = `${currentBiggestPark.attributes.GIS_ACRES.toLocaleString("en-US")} acres`;
                const button = document.createElement("calcite-button");
                button.innerHTML = `Visit ${currentBiggestPark.attributes.FORESTNAME}`;
                button.iconEnd = `launch`;
                button.target = "_blank";
                button.width = "full";
                button.slot = "footer-trailing";
                factSection.innerHTML = "";
                factSection.text = `Highlight largest forest in region ${data.region}`;
        // this function is called once after the aggregate spatial statistics runs
        // show the total acres of forests in each region in the chart
        function updateChart(regions, chartData) {
          // Get the canvas element and render the chart in it
          const canvasElement = document.getElementById("chart");
          chart = new Chart(canvasElement.getContext("2d"), {
            type: "doughnut",
            data: {
              labels: regions,
              datasets: [
                  backgroundColor: [
                    "#64bfae",
                    "#b277b0",
                    "#b8d161",
                    "#49b1d8",
                    "#f17474",
                    "#fda853",
                    "#f8a1e0",
                    "#ffe569",
                    "#c69a6f"
                  borderWidth: 0,
                  data: chartData
            options: {
              responsive: false,
              legend: {
                display: false
              title: {
                display: false
              tooltips: {
                callbacks: {
                  label: (tooltipItem, data) => {
                    const acres =
                    return (
                      "Region: " + data.labels[tooltipItem.index] + " Total acres: " + parseInt(acres).toLocaleString("en-US")
          async function updateMapForSelectedRegion(data) {
              geometry: data.extent,
              symbol: {
                type: "simple-fill",
                color: [0, 0, 0, 0],
                outline: {
                  width: "3px",
                  color: "magenta"
              filter: {
                where: `${groupField} = '${data.region}'`
              excludedEffect: "blur(0pt) opacity(0.5) grayscale(1)",
              includedEffect: "drop-shadow(3pt 2pt 2pt rgba(50, 50, 50, 0.5))"
          // Add the convex hull of grouped forests for that region
          // set a featureffect on the layerview
          // run stats on forests of the clicked region
          canvasElement.addEventListener("mousemove", async () => {
            const data = await getRegionFromChart(event);
            if (data) {
              await updateMapForSelectedRegion(data);
            }
          });
        }
        // runs when user clicks on the largest forest stats
        let highlight;
        async function handleParkPopup() {
          if (currentBiggestPark && factSection.open) {
            if (!feature.visible) {
              feature.visible = true;
            if (feature.graphic && feature.graphic.attributes.OBJECTID !== currentBiggestPark.attributes.OBJECTID){
          } else {
            feature.visible = false;
        // clear out region related graphics and stats when user is not hovering over the chart
        function clearStatsInfo() {
          layerView.featureEffect = null;
          feature.visible = false;
          resultBlock.heading = `No region selected`;
          resultBlock.disabled = true;
          resultBlock.open = false;
          clearAction.icon = "blank";
          clearAction.disabled = true;
          clearAction.addEventListener("click", () => clearStatsInfo());
          factSection.open = false;
        // called when user hovers over the donut chart
        async function getRegionFromChart(event) {
          const activePoints = chart.getElementsAtEvent(event);
          let selectedRegion = null;
          if (activePoints[0]) {
            const chartData = activePoints[0]["_chart"].config.data;
            const idx = activePoints[0]["_index"];
            const label = chartData.labels[idx];
            const value = chartData.datasets[0].data[idx];
            aggregateForestDataByRegions.forEach((data) => {
              if (data.region === label) {
          return selectedRegion;
    </script>
</head>

<body>
  <calcite-shell>
    <div id="viewDiv"></div>
    <calcite-shell-panel slot="contextual-panel" width-scale="">
      <calcite-panel heading="Total acreages of forests by region">
        <calcite-block open loading id="chart-block">
          <canvas id="chart" height="250" width="315" style="margin: 0 auto 1rem"></canvas>
          <calcite-notice active width="full" scale="s">
              <span slot="title">Instructions</span>
              <div slot="message">
                  Hover over the donut chart to see facts about forests in that
                  region.
              </div>
          </calcite-notice>
        </calcite-block>
        <calcite-block disabled id="resultsHeading" heading="No region selected" summary="Forest facts">
          <calcite-action disabled id="clearAction" slot="control" text="Clear" icon="blank">
          </calcite-action>
          <calcite-label layout="inline-space-between">Forests<span id="forestCount"></span></calcite-label>
          <calcite-label layout="inline-space-between">Acres<span id="acreageCount"></span></calcite-label>
          <calcite-block-section id="factSection" text="Highlight largest forest" toggle-display="switch">
          </calcite-block-section>
        </calcite-block>
    </calcite-panel>
    </calcite-shell-panel>
  </calcite-shell>
  </body>
</html>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.