Query all features of an ArcGIS Feature Service
This package calls queryFeatures from ArcGIS REST JS multiple times until it gets all the features.
npm install query-all-features
Then:
import { queryAllFeatures } from "query-all-features";
queryAllFeatures(
{
url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"
}
).then((results) => {
console.log('results', results);
}, (err) => {
console.error('err', err);
});
queryAllFeatures(requestOptions, additionalOptions): Promise<IQueryFeaturesResponse>
Query a feature service, repeatedly paging through the results to get all the features.
Parameter | Type | Notes |
---|---|---|
requestOptions | IQueryFeaturesOptions | This is the same input object that you would pass into ArcGIS REST JS queryFeatures. |
additionalOptions | IQueryFeaturesAllAdditionalOptions | Additional options specific to this module. See table below. |
Parameter | Type | Notes |
---|---|---|
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. |
import { queryAllFeatures } from "query-all-features";
queryAllFeatures(
{
url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"
}, {
pageBy: 100
}
).then((results) => {
console.log('results', results);
}, (err) => {
console.error('err', err);
});
Promise<IQueryFeaturesResponse>
A Promise that will resolve with the same query response as queryFeatures.
npm install query-all-features
Then:
const { queryAllFeatures } = require("query-all-features");
queryAllFeatures({url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"}).then((results) => {
console.log('results', results);
}, (err) => {
console.error('err', err);
});
Distributed as an ES module which should work "out-of-the-box" with most popular module bundlers. See "Quick Start" above.
<script type="module">
import { queryAllFeatures } from "https://cdn.skypack.dev/query-all-features";
queryAllFeatures({url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"}).then((results) => {
console.log('results', results);
}, (err) => {
console.error('err', err);
});
</script>
<!-- arcgis-rest-request and arcgis-rest-feature-service are dependencies: -->
<script src="https://unpkg.com/@esri/arcgis-rest-request@4"></script>
<script src="https://unpkg.com/@esri/arcgis-rest-feature-service@4"></script>
<script src="https://unpkg.com/query-all-features"></script>
<script>
queryAllFeatures.queryAllFeatures({url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"}).then((results) => {
console.log('results', results);
}, (err) => {
console.log('err', err);
});
</script>
Copyright 2022 Gavin Rehkemper
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.