-
Notifications
You must be signed in to change notification settings - Fork 10
/
fetchNgwLayerItems.ts
41 lines (39 loc) · 1.41 KB
/
fetchNgwLayerItems.ts
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
import { propertiesFilter } from '@nextgis/properties-filter';
import CancelablePromise from '@nextgis/cancelable-promise';
import {
createFeatureFieldFilterQueries,
fetchNgwLayerItemsRequest,
} from './featureLayerUtils';
import { prepareNgwFieldsToPropertiesFilter } from './prepareNgwFieldsToPropertiesFilter';
import type { Geometry } from 'geojson';
import type { FeatureItem } from '@nextgis/ngw-connector';
import type { FeatureProperties } from '@nextgis/utils';
import type { FetchNgwItemsOptions } from '../interfaces';
export function fetchNgwLayerItems<
G extends Geometry = Geometry,
P extends FeatureProperties = FeatureProperties,
>(options: FetchNgwItemsOptions<P>): CancelablePromise<FeatureItem<P, G>[]> {
const filters = options.filters;
if (filters) {
return createFeatureFieldFilterQueries({
...options,
filters,
}).then((data) => {
const clientFilterValidate = options.clientFilterValidate ?? true;
// Additional client-side filter check
if (clientFilterValidate) {
data = data.filter((y) => {
const fields = prepareNgwFieldsToPropertiesFilter({
...y.fields,
id: y.id,
});
const result = propertiesFilter(fields, filters);
return result;
});
}
return data;
}) as CancelablePromise<FeatureItem<P, G>[]>;
} else {
return fetchNgwLayerItemsRequest<G, P>(options);
}
}