Web Developer Work - I
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
857 B

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. import FeatureLayer from '@arcgis/core/layers/FeatureLayer';
  2. import Query from '@arcgis/core/rest/support/Query';
  3. import Graphic from '@arcgis/core/Graphic';
  4. const queryAllFeatures = async (
  5. layer: FeatureLayer,
  6. baseQuery: Partial<Query>,
  7. pageSize = 2000
  8. ): Promise<Graphic[]> => {
  9. const allFeatures: Graphic[] = [];
  10. let resultOffset = 0;
  11. let hasMore = true;
  12. while (hasMore) {
  13. const query = layer.createQuery();
  14. Object.assign(query, baseQuery);
  15. (query as any).resultOffset = resultOffset; // ArcGIS supports this, but it's not in TS type
  16. (query as any).resultRecordCount = pageSize;
  17. const result = await layer.queryFeatures(query);
  18. allFeatures.push(...result.features);
  19. hasMore = result.exceededTransferLimit === true;
  20. resultOffset += pageSize;
  21. }
  22. return allFeatures;
  23. };
  24. export default queryAllFeatures;