Query features with pagination

Explore in the sandboxView live

This sample demonstrates how to query features from a FeatureLayer that are beyond its maxRecordCount using pagination. This can be done by fetching a specified number of records, starting from a specified record in the service.

How it works

When the application starts, twenty counties with the highest household median income will be queried from the service as shown below. The querying is done by setting the query object's start and num properties. The start parameter is a zero based index indicating where to begin fetching features until you've reached the specified num parameter, or number of features to query.

                                                                                                                                                                                                                                                                                                                                                   
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
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>Query features with pagination | Sample | ArcGIS API for JavaScript 4.21</title>

    <script type="module" src="https://js.arcgis.com/calcite-components/1.0.0-beta.62/calcite.esm.js"></script>
    <script nomodule="" src="https://js.arcgis.com/calcite-components/1.0.0-beta.62/calcite.js"></script>
    <link rel="stylesheet" type="text/css" href="https://js.arcgis.com/calcite-components/1.0.0-beta.62/calcite.css"/>

    <link rel="stylesheet" href="https://js.arcgis.com/4.21/esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.21/"></script>

    <style>
      html,
      body,
      #viewDiv {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
        overflow: hidden;
      .panel-side {
        padding: 2px;
        width: 390px;
        height: 100%;
        position: absolute;
        top: 0;
        right: 0;
        z-index: 60;
      #resultsDiv {
        overflow: auto;
    </style>
    <script>
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer"
      ], (Map, MapView, FeatureLayer) => (async () => {
        const map = new Map({
          basemap: "gray-vector"
        const view = new MapView({
          container: "viewDiv",
          map: map,
          padding: {
            right: 390
          center: [-98, 38],
          zoom: 4,
          constraints: {
            geometry: {
              type: "extent",
              xmin: -17206956,
              xmax: -4570726,
              ymin: 1737191,
              ymax: 7421660,
              spatialReference: {
                wkid: 102100
            minZoom: 3
        const listNode = document.getElementById("incomeList");
        // Create the FeatureLayer using the popupTemplate
        const featureLayer = new FeatureLayer({
          url:
            "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Counties_education_smart_mapping/FeatureServer/0",
          outFields: ["*"],
          popupTemplate:  {
            title: "{NAME}",
            content: [
                type: "fields",
                fieldInfos: [
                    fieldName: "MEDHINC_CY",
                    label: "Median household income",
                    format: {
                      places: 0,
                      digitSeparator: true
                    fieldName: "Population25up",
                    label: "Population 25+",
                    format: {
                      places: 0,
                      digitSeparator: true
          renderer: createRenderer()
        let graphics;
        let start = 0;
        let highlight;
        // get number of all features from the service and use the count
        // to set the number of pages in the calcite-pagination component
        const featureCount = await featureLayer.queryFeatureCount();
        document.getElementById("tablePager").setAttribute("total", featureCount);
        // get the instance of the layerview representing the counties feature layer
        const layerView = await view.whenLayerView(featureLayer);
        // fetch the first twenty counties that have the highest household median income
        queryPage(0);
        // ************************************************************************
        // This function is used to fetch 20 features from a specified start location
        // It is called when the application loads first then it is called whenever
        // user changes the page number on the calcite-pagination component
        // ************************************************************************
        function queryPage(page) {
          // Query for the page of features.
          // order the results by median income in descending order
          const query = {
            start: page,
            num: 20,
            outFields: ["*"],
            returnGeometry: true,
            orderByFields: ["MEDHINC_CY DESC"]
          };
          const promise = featureLayer.queryFeatures(query)
            .then((featureSet) => convertFeatureSetToRows(featureSet, query));
        }
        // ************************************************************************
        // This function is called once "next" twenty countries are fetched
        // and sets up the list on the right side of the application
        // ************************************************************************
        function convertFeatureSetToRows(featureSet, query) {
          document.getElementById("incomeList").innerHTML = "";
          graphics.forEach((result, index) => {
            const attributes = result.attributes;
            const name = attributes.NAME;
            const income = `median income: ${attributes.MEDHINC_CY}`;
            const item = document.createElement("calcite-pick-list-item");
            item.setAttribute("label", name);
            item.setAttribute("value", index);
            item.setAttribute("description", income);
            item.addEventListener("click", onCountyClickHandler);
            document.getElementById("incomeList").appendChild(item);
          if (highlight) {
        // ************************************************************************
        // User clicked on the page number on the calcite-pagination
        // set up the query page and fetch the features from the service corresponding
        // to the page number
        // ************************************************************************
        document.getElementById("tablePager").addEventListener("calcitePaginationChange", (event) => {
          let page;
          if (event.detail.start === 1) {
            page = 0;
          } else {
          // set up the view for the new results
          view.zoom = 4;
          view.center = [-98, 38];
          if (view.popup.visible){
            view.popup.visible = false;
        // ***************************************************
        // this function runs when user clicks on the county
        // in the list shown on the right side of the app
        // ***************************************************
        function onCountyClickHandler(event) {
          const target = event.target;
          const resultId = target.getAttribute("value");
          // get the graphic corresponding to the clicked zip code
          const result =
            resultId && graphics && graphics[parseInt(resultId, 10)];
          if (result) {
            view.goTo(result.geometry.extent.expand(6))
              .then(() => {
                  features: [result],
                  location: result.geometry.centroid
              .catch((error) => {
                if (error.name != "AbortError") {
                  console.error(error);
        // called when the counties featurelayer is initialized
        // render the layer to show classification of household median income
        function createRenderer(){
          return renderer = {
            type: "class-breaks",
            field: "MEDHINC_CY",
            classBreakInfos: [
                minValue: 0,
                maxValue: 15000,
                symbol: {
                  type: "simple-fill",
                  color: "#097969",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
                minValue: 15000,
                maxValue: 50000,
                symbol: {
                  type: "simple-fill",
                  color: "#AFE1AF",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
                minValue: 50000,
                maxValue: 80000,
                symbol: {
                  type: "simple-fill",
                  color: "white",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
                minValue: 80000,
                maxValue: 100000,
                symbol: {
                  type: "simple-fill",
                  color: "#5F9EA0",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
                minValue: 100000,
                maxValue: 200000,
                symbol: {
                  type: "simple-fill",
                  color: "#0818A8",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
        const resultPanel = document.getElementById("result-panel");
        const toggleButton = document.getElementById("toggle-button");
        view.ui.add(toggleButton, "top-left");
        toggleButton.addEventListener("click", function(){
          if (resultPanel.clientWidth == 390){
            resultPanel.style.width = "0px";
            tablePager.style.width = "0px";
            toggleButton.icon = "chevrons-right";
            toggleButton.title = "Expand results panel";
          } else {
            resultPanel.style.width = "390px";
            tablePager.style.width = "390px";
            toggleButton.icon = "chevrons-left";
            toggleButton.title = "Collapse results panel"
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
      <div id="viewDiv"></div>
      <calcite-action id="toggle-button" text="Toggle results panel" title="Collapse results panel"
        icon="chevrons-left" scale="s">
      </calcite-action>
      <calcite-panel class="panel-side" id="result-panel">
        <div slot="header-content" scale="s">
          <h3 class="heading">Medium household income by counties from highest to lowest</h3>
          <p>returns 20 counties at a time<p>
        </div>
        <calcite-panel id="resultsDiv" >
          <calcite-pick-list id="incomeList"></calcite-pick-list>
        </calcite-panel>
        <div slot="footer">
          <calcite-pagination id="tablePager" start="1" num="20"></calcite-pagination>
        </div>
      </calcite-panel>
  </body>
</html>

Info for the fetched counties will be displayed in a calcite pick list items on the right side of the application. The counties corresponding to this list will also be highlighted on the map.

                                                                                                                                                                                                                                                                                                                                                   
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
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>Query features with pagination | Sample | ArcGIS API for JavaScript 4.21</title>

    <script type="module" src="https://js.arcgis.com/calcite-components/1.0.0-beta.62/calcite.esm.js"></script>
    <script nomodule="" src="https://js.arcgis.com/calcite-components/1.0.0-beta.62/calcite.js"></script>
    <link rel="stylesheet" type="text/css" href="https://js.arcgis.com/calcite-components/1.0.0-beta.62/calcite.css"/>

    <link rel="stylesheet" href="https://js.arcgis.com/4.21/esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.21/"></script>

    <style>
      html,
      body,
      #viewDiv {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
        overflow: hidden;
      .panel-side {
        padding: 2px;
        width: 390px;
        height: 100%;
        position: absolute;
        top: 0;
        right: 0;
        z-index: 60;
      #resultsDiv {
        overflow: auto;
    </style>
    <script>
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer"
      ], (Map, MapView, FeatureLayer) => (async () => {
        const map = new Map({
          basemap: "gray-vector"
        const view = new MapView({
          container: "viewDiv",
          map: map,
          padding: {
            right: 390
          center: [-98, 38],
          zoom: 4,
          constraints: {
            geometry: {
              type: "extent",
              xmin: -17206956,
              xmax: -4570726,
              ymin: 1737191,
              ymax: 7421660,
              spatialReference: {
                wkid: 102100
            minZoom: 3
        const listNode = document.getElementById("incomeList");
        // Create the FeatureLayer using the popupTemplate
        const featureLayer = new FeatureLayer({
          url:
            "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Counties_education_smart_mapping/FeatureServer/0",
          outFields: ["*"],
          popupTemplate:  {
            title: "{NAME}",
            content: [
                type: "fields",
                fieldInfos: [
                    fieldName: "MEDHINC_CY",
                    label: "Median household income",
                    format: {
                      places: 0,
                      digitSeparator: true
                    fieldName: "Population25up",
                    label: "Population 25+",
                    format: {
                      places: 0,
                      digitSeparator: true
          renderer: createRenderer()
        let graphics;
        let start = 0;
        let highlight;
        // get number of all features from the service and use the count
        // to set the number of pages in the calcite-pagination component
        const featureCount = await featureLayer.queryFeatureCount();
        document.getElementById("tablePager").setAttribute("total", featureCount);
        // get the instance of the layerview representing the counties feature layer
        const layerView = await view.whenLayerView(featureLayer);
        // fetch the first twenty counties that have the highest household median income
        queryPage(0);
        // ************************************************************************
        // This function is used to fetch 20 features from a specified start location
        // It is called when the application loads first then it is called whenever
        // user changes the page number on the calcite-pagination component
        // ************************************************************************
        function queryPage(page) {
          // Query for the page of features.
          // order the results by median income in descending order
          const query = {
            start: page,
            num: 20,
            outFields: ["*"],
            returnGeometry: true,
            orderByFields: ["MEDHINC_CY DESC"]
          const promise = featureLayer.queryFeatures(query)
            .then((featureSet) => convertFeatureSetToRows(featureSet, query));
        // ************************************************************************
        // This function is called once "next" twenty countries are fetched
        // and sets up the list on the right side of the application
        // ************************************************************************
        function convertFeatureSetToRows(featureSet, query) {
          document.getElementById("incomeList").innerHTML = "";

          graphics = featureSet.features;
          graphics.forEach((result, index) => {
            const attributes = result.attributes;
            const name = attributes.NAME;
            const income = `median income: ${attributes.MEDHINC_CY}`;

            const item = document.createElement("calcite-pick-list-item");
            item.setAttribute("label", name);
            item.setAttribute("value", index);
            item.setAttribute("description", income);
            item.addEventListener("click", onCountyClickHandler);
            document.getElementById("incomeList").appendChild(item);
          });

          if (highlight) {
            highlight.remove();
          }
          highlight = layerView.highlight(featureSet.features);
        }
        // ************************************************************************
        // User clicked on the page number on the calcite-pagination
        // set up the query page and fetch the features from the service corresponding
        // to the page number
        // ************************************************************************
        document.getElementById("tablePager").addEventListener("calcitePaginationChange", (event) => {
          let page;
          if (event.detail.start === 1) {
            page = 0;
          } else {
          // set up the view for the new results
          view.zoom = 4;
          view.center = [-98, 38];
          if (view.popup.visible){
            view.popup.visible = false;
        // ***************************************************
        // this function runs when user clicks on the county
        // in the list shown on the right side of the app
        // ***************************************************
        function onCountyClickHandler(event) {
          const target = event.target;
          const resultId = target.getAttribute("value");
          // get the graphic corresponding to the clicked zip code
          const result =
            resultId && graphics && graphics[parseInt(resultId, 10)];
          if (result) {
            view.goTo(result.geometry.extent.expand(6))
              .then(() => {
                  features: [result],
                  location: result.geometry.centroid
              .catch((error) => {
                if (error.name != "AbortError") {
                  console.error(error);
        // called when the counties featurelayer is initialized
        // render the layer to show classification of household median income
        function createRenderer(){
          return renderer = {
            type: "class-breaks",
            field: "MEDHINC_CY",
            classBreakInfos: [
                minValue: 0,
                maxValue: 15000,
                symbol: {
                  type: "simple-fill",
                  color: "#097969",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
                minValue: 15000,
                maxValue: 50000,
                symbol: {
                  type: "simple-fill",
                  color: "#AFE1AF",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
                minValue: 50000,
                maxValue: 80000,
                symbol: {
                  type: "simple-fill",
                  color: "white",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
                minValue: 80000,
                maxValue: 100000,
                symbol: {
                  type: "simple-fill",
                  color: "#5F9EA0",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
                minValue: 100000,
                maxValue: 200000,
                symbol: {
                  type: "simple-fill",
                  color: "#0818A8",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
        const resultPanel = document.getElementById("result-panel");
        const toggleButton = document.getElementById("toggle-button");
        view.ui.add(toggleButton, "top-left");
        toggleButton.addEventListener("click", function(){
          if (resultPanel.clientWidth == 390){
            resultPanel.style.width = "0px";
            tablePager.style.width = "0px";
            toggleButton.icon = "chevrons-right";
            toggleButton.title = "Expand results panel";
          } else {
            resultPanel.style.width = "390px";
            tablePager.style.width = "390px";
            toggleButton.icon = "chevrons-left";
            toggleButton.title = "Collapse results panel"
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
      <div id="viewDiv"></div>
      <calcite-action id="toggle-button" text="Toggle results panel" title="Collapse results panel"
        icon="chevrons-left" scale="s">
      </calcite-action>
      <calcite-panel class="panel-side" id="result-panel">
        <div slot="header-content" scale="s">
          <h3 class="heading">Medium household income by counties from highest to lowest</h3>
          <p>returns 20 counties at a time<p>
        </div>
        <calcite-panel id="resultsDiv" >
          <calcite-pick-list id="incomeList"></calcite-pick-list>
        </calcite-panel>
        <div slot="footer">
          <calcite-pagination id="tablePager" start="1" num="20"></calcite-pagination>
        </div>
      </calcite-panel>
  </body>
</html>

The user can also click on page numbers shown below the list to fetch the counties ordered by the median household income. The following function is called when the calcite pagination component's page number is changed.

                                                                                                                                                                                                                                                                                                                                                   
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
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <title>Query features with pagination | Sample | ArcGIS API for JavaScript 4.21</title>

    <script type="module" src="https://js.arcgis.com/calcite-components/1.0.0-beta.62/calcite.esm.js"></script>
    <script nomodule="" src="https://js.arcgis.com/calcite-components/1.0.0-beta.62/calcite.js"></script>
    <link rel="stylesheet" type="text/css" href="https://js.arcgis.com/calcite-components/1.0.0-beta.62/calcite.css"/>

    <link rel="stylesheet" href="https://js.arcgis.com/4.21/esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.21/"></script>

    <style>
      html,
      body,
      #viewDiv {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
        overflow: hidden;
      .panel-side {
        padding: 2px;
        width: 390px;
        height: 100%;
        position: absolute;
        top: 0;
        right: 0;
        z-index: 60;
      #resultsDiv {
        overflow: auto;
    </style>
    <script>
      require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer"
      ], (Map, MapView, FeatureLayer) => (async () => {
        const map = new Map({
          basemap: "gray-vector"
        const view = new MapView({
          container: "viewDiv",
          map: map,
          padding: {
            right: 390
          center: [-98, 38],
          zoom: 4,
          constraints: {
            geometry: {
              type: "extent",
              xmin: -17206956,
              xmax: -4570726,
              ymin: 1737191,
              ymax: 7421660,
              spatialReference: {
                wkid: 102100
            minZoom: 3
        const listNode = document.getElementById("incomeList");
        // Create the FeatureLayer using the popupTemplate
        const featureLayer = new FeatureLayer({
          url:
            "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Counties_education_smart_mapping/FeatureServer/0",
          outFields: ["*"],
          popupTemplate:  {
            title: "{NAME}",
            content: [
                type: "fields",
                fieldInfos: [
                    fieldName: "MEDHINC_CY",
                    label: "Median household income",
                    format: {
                      places: 0,
                      digitSeparator: true
                    fieldName: "Population25up",
                    label: "Population 25+",
                    format: {
                      places: 0,
                      digitSeparator: true
          renderer: createRenderer()
        let graphics;
        let start = 0;
        let highlight;
        // get number of all features from the service and use the count
        // to set the number of pages in the calcite-pagination component
        const featureCount = await featureLayer.queryFeatureCount();
        document.getElementById("tablePager").setAttribute("total", featureCount);
        // get the instance of the layerview representing the counties feature layer
        const layerView = await view.whenLayerView(featureLayer);
        // fetch the first twenty counties that have the highest household median income
        queryPage(0);
        // ************************************************************************
        // This function is used to fetch 20 features from a specified start location
        // It is called when the application loads first then it is called whenever
        // user changes the page number on the calcite-pagination component
        // ************************************************************************
        function queryPage(page) {
          // Query for the page of features.
          // order the results by median income in descending order
          const query = {
            start: page,
            num: 20,
            outFields: ["*"],
            returnGeometry: true,
            orderByFields: ["MEDHINC_CY DESC"]
          const promise = featureLayer.queryFeatures(query)
            .then((featureSet) => convertFeatureSetToRows(featureSet, query));
        // ************************************************************************
        // This function is called once "next" twenty countries are fetched
        // and sets up the list on the right side of the application
        // ************************************************************************
        function convertFeatureSetToRows(featureSet, query) {
          document.getElementById("incomeList").innerHTML = "";
          graphics.forEach((result, index) => {
            const attributes = result.attributes;
            const name = attributes.NAME;
            const income = `median income: ${attributes.MEDHINC_CY}`;
            const item = document.createElement("calcite-pick-list-item");
            item.setAttribute("label", name);
            item.setAttribute("value", index);
            item.setAttribute("description", income);
            item.addEventListener("click", onCountyClickHandler);
            document.getElementById("incomeList").appendChild(item);
          if (highlight) {
        // ************************************************************************
        // User clicked on the page number on the calcite-pagination
        // set up the query page and fetch the features from the service corresponding
        // to the page number
        // ************************************************************************
        document.getElementById("tablePager").addEventListener("calcitePaginationChange", (event) => {
          let page;
          if (event.detail.start === 1) {
            page = 0;
          } else {
            page = event.detail.start;
          }
          queryPage(page);

          // set up the view for the new results
          view.zoom = 4;
          view.center = [-98, 38];
          if (view.popup.visible){
            view.popup.visible = false;
          }
        });
        // ***************************************************
        // this function runs when user clicks on the county
        // in the list shown on the right side of the app
        // ***************************************************
        function onCountyClickHandler(event) {
          const target = event.target;
          const resultId = target.getAttribute("value");
          // get the graphic corresponding to the clicked zip code
          const result =
            resultId && graphics && graphics[parseInt(resultId, 10)];
          if (result) {
            view.goTo(result.geometry.extent.expand(6))
              .then(() => {
                  features: [result],
                  location: result.geometry.centroid
              .catch((error) => {
                if (error.name != "AbortError") {
                  console.error(error);
        // called when the counties featurelayer is initialized
        // render the layer to show classification of household median income
        function createRenderer(){
          return renderer = {
            type: "class-breaks",
            field: "MEDHINC_CY",
            classBreakInfos: [
                minValue: 0,
                maxValue: 15000,
                symbol: {
                  type: "simple-fill",
                  color: "#097969",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
                minValue: 15000,
                maxValue: 50000,
                symbol: {
                  type: "simple-fill",
                  color: "#AFE1AF",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
                minValue: 50000,
                maxValue: 80000,
                symbol: {
                  type: "simple-fill",
                  color: "white",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
                minValue: 80000,
                maxValue: 100000,
                symbol: {
                  type: "simple-fill",
                  color: "#5F9EA0",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
                minValue: 100000,
                maxValue: 200000,
                symbol: {
                  type: "simple-fill",
                  color: "#0818A8",
                  outline: {
                    color: "#D3D3D3",
                    width: 0.5
        const resultPanel = document.getElementById("result-panel");
        const toggleButton = document.getElementById("toggle-button");
        view.ui.add(toggleButton, "top-left");
        toggleButton.addEventListener("click", function(){
          if (resultPanel.clientWidth == 390){
            resultPanel.style.width = "0px";
            tablePager.style.width = "0px";
            toggleButton.icon = "chevrons-right";
            toggleButton.title = "Expand results panel";
          } else {
            resultPanel.style.width = "390px";
            tablePager.style.width = "390px";
            toggleButton.icon = "chevrons-left";
            toggleButton.title = "Collapse results panel"
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
      <div id="viewDiv"></div>
      <calcite-action id="toggle-button" text="Toggle results panel" title="Collapse results panel"
        icon="chevrons-left" scale="s">
      </calcite-action>
      <calcite-panel class="panel-side" id="result-panel">
        <div slot="header-content" scale="s">
          <h3 class="heading">Medium household income by counties from highest to lowest</h3>
          <p>returns 20 counties at a time<p>
        </div>
        <calcite-panel id="resultsDiv" >
          <calcite-pick-list id="incomeList"></calcite-pick-list>
        </calcite-panel>
        <div slot="footer">
          <calcite-pagination id="tablePager" start="1" num="20"></calcite-pagination>
        </div>
      </calcite-panel>
  </body>
</html>

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