|
| 1 | +# Query All Features |
| 2 | + |
| 3 | +*Query all features of an ArcGIS Feature Service* |
| 4 | + |
| 5 | +This package calls [queryFeatures](https://developers.arcgis.com/arcgis-rest-js/api-reference/arcgis-rest-feature-service/queryFeatures) multiple times until it gets all the features. |
| 6 | + |
| 7 | +- [Quick Start](#quick-start) |
| 8 | +- [API Reference](#api-reference) |
| 9 | +- [Usage](#usage) |
| 10 | +- [License](#license) |
| 11 | + |
| 12 | +## Quick Start |
| 13 | + |
| 14 | +```bash |
| 15 | +npm install query-all-features |
| 16 | +``` |
| 17 | + |
| 18 | +Then: |
| 19 | + |
| 20 | +```js |
| 21 | +import { queryAllFeatures } from "query-all-features"; |
| 22 | + |
| 23 | +queryAllFeatures({url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"}).then((results) => { |
| 24 | + console.log('results', results); |
| 25 | +}, (err) => { |
| 26 | + console.error('err', err); |
| 27 | +}); |
| 28 | +``` |
| 29 | + |
| 30 | +## API Reference |
| 31 | + |
| 32 | +### queryAllFeatures |
| 33 | + |
| 34 | +<pre> |
| 35 | +queryAllFeatures(requestOptions, additionalOptions): Promise<<a href="[my-url](https://developers.arcgis.com/arcgis-rest-js/api-reference/arcgis-rest-feature-service/IQueryFeaturesResponse)">IQueryFeaturesResponse</a>> |
| 36 | +</pre> |
| 37 | + |
| 38 | +Query a feature service, repeatedly paging through the results to get all the features. |
| 39 | + |
| 40 | +#### Parameters |
| 41 | + |
| 42 | +| Parameter | Type | Notes | |
| 43 | +|-------------------|------------------------------------|-----------------------------------------------------------------------| |
| 44 | +| requestOptions | [IQueryFeaturesOptions](https://developers.arcgis.com/arcgis-rest-js/api-reference/arcgis-rest-feature-service/IQueryFeaturesOptions) | This is the same input object that you would pass into [queryFeatures](https://developers.arcgis.com/arcgis-rest-js/api-reference/arcgis-rest-feature-service/IQueryFeaturesOptions). | |
| 45 | +| additionalOptions | [IQueryFeaturesAllAdditionalOptions](#IQueryFeaturesAllAdditionalOptions) | Additional options specific to this module. See table below. | |
| 46 | + |
| 47 | +##### IQueryFeaturesAllAdditionalOptions |
| 48 | + |
| 49 | +| Parameter | Type | Notes | |
| 50 | +|-------------------|------------------------------------|-----------------------------------------------------------------------| |
| 51 | +| pageBy (optional) | *number* | How many records to request from the service at a time. By default, the service info will be checked to find the maxRecordCount of the service, and that will be used as the `pageBy` value. If this `pageBy` value is provided, that additional request will not be made. | |
| 52 | + |
| 53 | +```js |
| 54 | +import { queryAllFeatures } from "query-all-features"; |
| 55 | + |
| 56 | +queryAllFeatures({url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"}, { pageBy: 100}).then((results) => { |
| 57 | + console.log('results', results); |
| 58 | +}, (err) => { |
| 59 | + console.error('err', err); |
| 60 | +}); |
| 61 | +``` |
| 62 | + |
| 63 | +#### Returns |
| 64 | + |
| 65 | +<pre> |
| 66 | +Promise<<a href="[my-url](https://developers.arcgis.com/arcgis-rest-js/api-reference/arcgis-rest-feature-service/IQueryFeaturesResponse)">IQueryFeaturesResponse</a>> |
| 67 | +</pre> |
| 68 | + |
| 69 | +A Promise that will resolve with the same query response as [queryFeatures](https://developers.arcgis.com/arcgis-rest-js/api-reference/arcgis-rest-feature-service/queryFeatures). |
| 70 | + |
| 71 | +## Usage |
| 72 | + |
| 73 | +### Node JS |
| 74 | + |
| 75 | +```bash |
| 76 | +npm install query-all-features |
| 77 | +``` |
| 78 | + |
| 79 | +Then: |
| 80 | + |
| 81 | +```js |
| 82 | +const { queryAllFeatures } = require("query-all-features"); |
| 83 | + |
| 84 | +queryAllFeatures({url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"}).then((results) => { |
| 85 | + console.log('results', results); |
| 86 | +}, (err) => { |
| 87 | + console.error('err', err); |
| 88 | +}); |
| 89 | +``` |
| 90 | + |
| 91 | +### Browser - ES Modules |
| 92 | + |
| 93 | +Distributed as an ES module which should work "out-of-the-box" with most popular module bundlers. See "Quick Start" above. |
| 94 | + |
| 95 | +### Browser - ES Modules via CDN |
| 96 | + |
| 97 | +```html |
| 98 | +<script type="module"> |
| 99 | + import { queryAllFeatures } from "https://cdn.skypack.dev/query-all-features"; |
| 100 | +
|
| 101 | + queryAllFeatures({url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"}).then((results) => { |
| 102 | + console.log('results', results); |
| 103 | + }, (err) => { |
| 104 | + console.error('err', err); |
| 105 | + }); |
| 106 | +</script> |
| 107 | +``` |
| 108 | + |
| 109 | +[Example in action](https://codepen.io/gavinr/pen/ExQYegd?editors=0010) |
| 110 | + |
| 111 | +### Browser - Script tag via UMD CDN |
| 112 | + |
| 113 | +```html |
| 114 | +<script src="https://unpkg.com/query-all-features"></script> |
| 115 | + |
| 116 | +<script> |
| 117 | + queryAllFeatures.queryAllFeatures({url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"}).then((results) => { |
| 118 | + console.log('results', results); |
| 119 | + document.body.innerHTML = `${results.features.length} results: <br /><br /><pre>` + JSON.stringify(results, null, 4) + '</pre>'; |
| 120 | + }, (err) => { |
| 121 | + console.log('err', err); |
| 122 | + document.body.innerHTML = err; |
| 123 | + }); |
| 124 | +</script> |
| 125 | +``` |
| 126 | + |
| 127 | +[Example in action](https://jsbin.com/kegayoz/edit?html,output) |
| 128 | + |
| 129 | +## License |
| 130 | + |
| 131 | + Copyright 2022 Gavin Rehkemper |
| 132 | + |
| 133 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 134 | + you may not use this file except in compliance with the License. |
| 135 | + You may obtain a copy of the License at |
| 136 | + |
| 137 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 138 | + |
| 139 | + Unless required by applicable law or agreed to in writing, software |
| 140 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 141 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 142 | + See the License for the specific language governing permissions and |
| 143 | + limitations under the License. |
0 commit comments