@mapcreator/api 5.0.0-alpha.74 → 5.0.0-alpha.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/api/choropleth.d.ts +57 -19
- package/cjs/api/choropleth.d.ts.map +1 -1
- package/cjs/api/choropleth.js +24 -20
- package/cjs/api/choropleth.js.map +1 -1
- package/esm/api/choropleth.d.ts +57 -19
- package/esm/api/choropleth.d.ts.map +1 -1
- package/esm/api/choropleth.js +23 -20
- package/esm/api/choropleth.js.map +1 -1
- package/package.json +1 -1
- package/src/api/choropleth.ts +100 -86
package/cjs/api/choropleth.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ApiError, type ApiSuccess, type Flatten, type Revivers } from '../utils.js';
|
|
1
2
|
import type { RequireAtLeastOne } from 'type-fest';
|
|
2
3
|
import type { Polygon } from 'geojson';
|
|
3
4
|
export type ApiSearchPoint = {
|
|
@@ -16,18 +17,35 @@ type SingleOrGroupedAreaBase = {
|
|
|
16
17
|
subtitle: string;
|
|
17
18
|
svgPreview: string;
|
|
18
19
|
boundingBox: Polygon;
|
|
20
|
+
isGroup: boolean;
|
|
21
|
+
properties: Record<string, string> | null;
|
|
19
22
|
};
|
|
20
|
-
export type GroupedArea = SingleOrGroupedAreaBase
|
|
21
|
-
isGroup: true;
|
|
22
|
-
};
|
|
23
|
+
export type GroupedArea = SingleOrGroupedAreaBase;
|
|
23
24
|
export type SingleArea = SingleOrGroupedAreaBase & {
|
|
24
|
-
isGroup: false;
|
|
25
25
|
vectorSource: string;
|
|
26
26
|
sourceLayer: string;
|
|
27
27
|
featureId: number;
|
|
28
|
-
properties: Record<string, string>;
|
|
29
28
|
};
|
|
30
29
|
export type SingleOrGroupedArea = SingleArea | GroupedArea;
|
|
30
|
+
export type ApiSingleOrGroupedArea = {
|
|
31
|
+
data: {
|
|
32
|
+
id: number;
|
|
33
|
+
title: string;
|
|
34
|
+
subtitle: string;
|
|
35
|
+
svg_preview: string;
|
|
36
|
+
bounding_box: string;
|
|
37
|
+
is_group: boolean;
|
|
38
|
+
vector_source: string | null;
|
|
39
|
+
source_layer: string | null;
|
|
40
|
+
feature_id: number | null;
|
|
41
|
+
properties: string | null;
|
|
42
|
+
};
|
|
43
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
44
|
+
export type ApiSingleOrGroupedAreaData = Flatten<Exclude<ApiSingleOrGroupedArea, ApiError>['data']>;
|
|
45
|
+
export declare const singleOrGroupedAreaRevivers: Revivers<ApiSingleOrGroupedArea, SingleOrGroupedArea>;
|
|
46
|
+
/**
|
|
47
|
+
* TODO When SAGA search on click is implemented, remove mode and make searchBounds required
|
|
48
|
+
*/
|
|
31
49
|
export declare function searchSingleOrGroupedAreas(language: string, search: RequireAtLeastOne<{
|
|
32
50
|
searchBounds?: ApiSearchBounds;
|
|
33
51
|
query?: string;
|
|
@@ -39,8 +57,22 @@ export type GroupedAreaChild = {
|
|
|
39
57
|
vectorSource: string;
|
|
40
58
|
sourceLayer: string;
|
|
41
59
|
featureId: number;
|
|
60
|
+
boundingBox: Polygon;
|
|
42
61
|
properties: Record<string, string>;
|
|
43
62
|
};
|
|
63
|
+
type ApiGroupedAreaChild = {
|
|
64
|
+
data: {
|
|
65
|
+
id: number;
|
|
66
|
+
title: string;
|
|
67
|
+
vector_source: string;
|
|
68
|
+
source_layer: string;
|
|
69
|
+
feature_id: number;
|
|
70
|
+
bounding_box: string;
|
|
71
|
+
properties: string;
|
|
72
|
+
};
|
|
73
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
74
|
+
export type ApiGroupedAreaChildData = Flatten<Exclude<ApiGroupedAreaChild, ApiError>['data']>;
|
|
75
|
+
export declare const groupedAreaChildRevivers: Revivers<ApiGroupedAreaChild, GroupedAreaChild>;
|
|
44
76
|
export declare function groupedAreaChildren(groupId: number, language: string): Promise<GroupedAreaChild[]>;
|
|
45
77
|
export type MatchedGroup = {
|
|
46
78
|
id: number;
|
|
@@ -51,14 +83,17 @@ export type MatchedGroup = {
|
|
|
51
83
|
name: string;
|
|
52
84
|
};
|
|
53
85
|
export type ApiMatchedGroup = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
86
|
+
data: {
|
|
87
|
+
id: number;
|
|
88
|
+
sml: number;
|
|
89
|
+
children_count: number;
|
|
90
|
+
match_field: string;
|
|
91
|
+
property: string;
|
|
92
|
+
name: string;
|
|
93
|
+
};
|
|
94
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
95
|
+
export type ApiMatchedGroupData = Flatten<Exclude<ApiMatchedGroup, ApiError>['data']>;
|
|
96
|
+
export declare function getGroupsByDataSample(sample: Record<string, string[]>, language: string): Promise<MatchedGroup[]>;
|
|
62
97
|
export type BoundPolygon = {
|
|
63
98
|
index: number;
|
|
64
99
|
id: number;
|
|
@@ -67,12 +102,15 @@ export type BoundPolygon = {
|
|
|
67
102
|
inputName: string;
|
|
68
103
|
};
|
|
69
104
|
export type ApiBoundPolygon = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
105
|
+
data: {
|
|
106
|
+
index: number;
|
|
107
|
+
id: number;
|
|
108
|
+
sml: number;
|
|
109
|
+
name: string;
|
|
110
|
+
input_name: string;
|
|
111
|
+
};
|
|
112
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
113
|
+
export type ApiBoundPolygonData = Flatten<Exclude<ApiBoundPolygon, ApiError>['data']>;
|
|
76
114
|
export declare function getBoundPolygons(groupId: number, property: string, data: string[], language: string): Promise<BoundPolygon[]>;
|
|
77
115
|
export {};
|
|
78
116
|
//# sourceMappingURL=choropleth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"choropleth.d.ts","sourceRoot":"","sources":["../../src/api/choropleth.ts"],"names":[],"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,qBAAqB,CACzC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAChC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,YAAY,EAAE,CAAC,CAQzB;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC;AAExC,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAEtF,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EAAE,EACd,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,YAAY,EAAE,CAAC,CASzB"}
|
package/cjs/api/choropleth.js
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.groupedAreaChildRevivers = exports.singleOrGroupedAreaRevivers = void 0;
|
|
3
4
|
exports.searchSingleOrGroupedAreas = searchSingleOrGroupedAreas;
|
|
4
5
|
exports.groupedAreaChildren = groupedAreaChildren;
|
|
5
6
|
exports.getGroupsByDataSample = getGroupsByDataSample;
|
|
6
7
|
exports.getBoundPolygons = getBoundPolygons;
|
|
7
8
|
const utils_js_1 = require("../utils.js");
|
|
9
|
+
exports.singleOrGroupedAreaRevivers = {
|
|
10
|
+
boundingBox: (data) => JSON.parse(data.bounding_box),
|
|
11
|
+
properties: (data) => (data.properties != null ? JSON.parse(data.properties) : null),
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* TODO When SAGA search on click is implemented, remove mode and make searchBounds required
|
|
15
|
+
*/
|
|
8
16
|
async function searchSingleOrGroupedAreas(language, search, mode = 'both') {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
elem.boundingBox = JSON.parse(elem.boundingBox);
|
|
15
|
-
if (!elem.isGroup) {
|
|
16
|
-
elem.properties = JSON.parse(elem.properties);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return result;
|
|
20
|
-
});
|
|
17
|
+
const pathname = '/v1/choropleth/polygons/search';
|
|
18
|
+
const query = (0, utils_js_1.getSearchParams)(Object.assign(Object.assign(Object.assign(Object.assign({ language }, search.searchBounds), (search.query && { query: search.query })), (search.searchPoint && { point: search.searchPoint })), { mode }));
|
|
19
|
+
const path = `${pathname}?${query}`;
|
|
20
|
+
const options = { revivers: exports.singleOrGroupedAreaRevivers };
|
|
21
|
+
return (0, utils_js_1.request)(path, null, null, options);
|
|
21
22
|
}
|
|
23
|
+
exports.groupedAreaChildRevivers = {
|
|
24
|
+
boundingBox: (data) => JSON.parse(data.bounding_box),
|
|
25
|
+
properties: (data) => JSON.parse(data.properties),
|
|
26
|
+
};
|
|
22
27
|
async function groupedAreaChildren(groupId, language) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
28
|
+
const pathname = `/v1/choropleth/groups/${groupId}/children-optimized`;
|
|
29
|
+
const query = (0, utils_js_1.getSearchParams)({ language });
|
|
30
|
+
const path = `${pathname}?${query}`;
|
|
31
|
+
const options = { revivers: exports.groupedAreaChildRevivers };
|
|
32
|
+
return (0, utils_js_1.request)(path, null, null, options);
|
|
29
33
|
}
|
|
30
34
|
async function getGroupsByDataSample(sample, language) {
|
|
31
35
|
const path = `/v1/choropleth/groups/sample`;
|
|
@@ -33,7 +37,7 @@ async function getGroupsByDataSample(sample, language) {
|
|
|
33
37
|
}
|
|
34
38
|
async function getBoundPolygons(groupId, property, data, language) {
|
|
35
39
|
const path = `/v1/choropleth/groups/bind`;
|
|
36
|
-
const
|
|
37
|
-
return (0, utils_js_1.request)(path,
|
|
40
|
+
const body = { group_id: groupId, property, data, language };
|
|
41
|
+
return (0, utils_js_1.request)(path, body);
|
|
38
42
|
}
|
|
39
43
|
//# sourceMappingURL=choropleth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"choropleth.js","sourceRoot":"","sources":["../../src/api/choropleth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"choropleth.js","sourceRoot":"","sources":["../../src/api/choropleth.ts"],"names":[],"mappings":";;;AAiEA,gEAyBC;AA+BD,kDAWC;AAwBD,sDAWC;AAsBD,4CAcC;AA3MD,0CAAoH;AAwDvG,QAAA,2BAA2B,GAA0D;IAChG,WAAW,EAAE,CAAC,IAAgC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAY;IAC3F,UAAU,EAAE,CAAC,IAAgC,EAAE,EAAE,CAC/C,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAA2B,CAAC,CAAC,CAAC,IAAI,CAAC;CAC3F,CAAC;AAEF;;GAEG;AACI,KAAK,UAAU,0BAA0B,CAC9C,QAAgB,EAChB,MAIE,EACF,OAAqC,MAAM;IAE3C,MAAM,QAAQ,GAAG,gCAAgC,CAAC;IAClD,MAAM,KAAK,GAAG,IAAA,0BAAe,4DAC3B,QAAQ,IACL,MAAM,CAAC,YAAY,GACnB,CAA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AC;AACjF,CAAC;AAsBM,KAAK,UAAU,gBAAgB,CACpC,OAAe,EACf,QAAgB,EAChB,IAAc,EACd,QAAgB;IAEhB,MAAM,IAAI,GAAG,4BAA4B,CAAC;IAC1C,MAAM,IAAI,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAM7D,OAAO,IAAA,kBAAO,EAAqC,IAAI,EAAE,IAAI,CAAC,CAAC;AACjE,CAAC"}
|
package/esm/api/choropleth.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ApiError, type ApiSuccess, type Flatten, type Revivers } from '../utils.js';
|
|
1
2
|
import type { RequireAtLeastOne } from 'type-fest';
|
|
2
3
|
import type { Polygon } from 'geojson';
|
|
3
4
|
export type ApiSearchPoint = {
|
|
@@ -16,18 +17,35 @@ type SingleOrGroupedAreaBase = {
|
|
|
16
17
|
subtitle: string;
|
|
17
18
|
svgPreview: string;
|
|
18
19
|
boundingBox: Polygon;
|
|
20
|
+
isGroup: boolean;
|
|
21
|
+
properties: Record<string, string> | null;
|
|
19
22
|
};
|
|
20
|
-
export type GroupedArea = SingleOrGroupedAreaBase
|
|
21
|
-
isGroup: true;
|
|
22
|
-
};
|
|
23
|
+
export type GroupedArea = SingleOrGroupedAreaBase;
|
|
23
24
|
export type SingleArea = SingleOrGroupedAreaBase & {
|
|
24
|
-
isGroup: false;
|
|
25
25
|
vectorSource: string;
|
|
26
26
|
sourceLayer: string;
|
|
27
27
|
featureId: number;
|
|
28
|
-
properties: Record<string, string>;
|
|
29
28
|
};
|
|
30
29
|
export type SingleOrGroupedArea = SingleArea | GroupedArea;
|
|
30
|
+
export type ApiSingleOrGroupedArea = {
|
|
31
|
+
data: {
|
|
32
|
+
id: number;
|
|
33
|
+
title: string;
|
|
34
|
+
subtitle: string;
|
|
35
|
+
svg_preview: string;
|
|
36
|
+
bounding_box: string;
|
|
37
|
+
is_group: boolean;
|
|
38
|
+
vector_source: string | null;
|
|
39
|
+
source_layer: string | null;
|
|
40
|
+
feature_id: number | null;
|
|
41
|
+
properties: string | null;
|
|
42
|
+
};
|
|
43
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
44
|
+
export type ApiSingleOrGroupedAreaData = Flatten<Exclude<ApiSingleOrGroupedArea, ApiError>['data']>;
|
|
45
|
+
export declare const singleOrGroupedAreaRevivers: Revivers<ApiSingleOrGroupedArea, SingleOrGroupedArea>;
|
|
46
|
+
/**
|
|
47
|
+
* TODO When SAGA search on click is implemented, remove mode and make searchBounds required
|
|
48
|
+
*/
|
|
31
49
|
export declare function searchSingleOrGroupedAreas(language: string, search: RequireAtLeastOne<{
|
|
32
50
|
searchBounds?: ApiSearchBounds;
|
|
33
51
|
query?: string;
|
|
@@ -39,8 +57,22 @@ export type GroupedAreaChild = {
|
|
|
39
57
|
vectorSource: string;
|
|
40
58
|
sourceLayer: string;
|
|
41
59
|
featureId: number;
|
|
60
|
+
boundingBox: Polygon;
|
|
42
61
|
properties: Record<string, string>;
|
|
43
62
|
};
|
|
63
|
+
type ApiGroupedAreaChild = {
|
|
64
|
+
data: {
|
|
65
|
+
id: number;
|
|
66
|
+
title: string;
|
|
67
|
+
vector_source: string;
|
|
68
|
+
source_layer: string;
|
|
69
|
+
feature_id: number;
|
|
70
|
+
bounding_box: string;
|
|
71
|
+
properties: string;
|
|
72
|
+
};
|
|
73
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
74
|
+
export type ApiGroupedAreaChildData = Flatten<Exclude<ApiGroupedAreaChild, ApiError>['data']>;
|
|
75
|
+
export declare const groupedAreaChildRevivers: Revivers<ApiGroupedAreaChild, GroupedAreaChild>;
|
|
44
76
|
export declare function groupedAreaChildren(groupId: number, language: string): Promise<GroupedAreaChild[]>;
|
|
45
77
|
export type MatchedGroup = {
|
|
46
78
|
id: number;
|
|
@@ -51,14 +83,17 @@ export type MatchedGroup = {
|
|
|
51
83
|
name: string;
|
|
52
84
|
};
|
|
53
85
|
export type ApiMatchedGroup = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
86
|
+
data: {
|
|
87
|
+
id: number;
|
|
88
|
+
sml: number;
|
|
89
|
+
children_count: number;
|
|
90
|
+
match_field: string;
|
|
91
|
+
property: string;
|
|
92
|
+
name: string;
|
|
93
|
+
};
|
|
94
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
95
|
+
export type ApiMatchedGroupData = Flatten<Exclude<ApiMatchedGroup, ApiError>['data']>;
|
|
96
|
+
export declare function getGroupsByDataSample(sample: Record<string, string[]>, language: string): Promise<MatchedGroup[]>;
|
|
62
97
|
export type BoundPolygon = {
|
|
63
98
|
index: number;
|
|
64
99
|
id: number;
|
|
@@ -67,12 +102,15 @@ export type BoundPolygon = {
|
|
|
67
102
|
inputName: string;
|
|
68
103
|
};
|
|
69
104
|
export type ApiBoundPolygon = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
105
|
+
data: {
|
|
106
|
+
index: number;
|
|
107
|
+
id: number;
|
|
108
|
+
sml: number;
|
|
109
|
+
name: string;
|
|
110
|
+
input_name: string;
|
|
111
|
+
};
|
|
112
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
113
|
+
export type ApiBoundPolygonData = Flatten<Exclude<ApiBoundPolygon, ApiError>['data']>;
|
|
76
114
|
export declare function getBoundPolygons(groupId: number, property: string, data: string[], language: string): Promise<BoundPolygon[]>;
|
|
77
115
|
export {};
|
|
78
116
|
//# sourceMappingURL=choropleth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"choropleth.d.ts","sourceRoot":"","sources":["../../src/api/choropleth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"choropleth.d.ts","sourceRoot":"","sources":["../../src/api/choropleth.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C,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,YAAY,EAAE,CAAC,CAQzB;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC;AAExC,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAEtF,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EAAE,EACd,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,YAAY,EAAE,CAAC,CASzB"}
|
package/esm/api/choropleth.js
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import { getSearchParams, request } from '../utils.js';
|
|
2
|
+
export const singleOrGroupedAreaRevivers = {
|
|
3
|
+
boundingBox: (data) => JSON.parse(data.bounding_box),
|
|
4
|
+
properties: (data) => (data.properties != null ? JSON.parse(data.properties) : null),
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* TODO When SAGA search on click is implemented, remove mode and make searchBounds required
|
|
8
|
+
*/
|
|
2
9
|
export async function searchSingleOrGroupedAreas(language, search, mode = 'both') {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
elem.boundingBox = JSON.parse(elem.boundingBox);
|
|
9
|
-
if (!elem.isGroup) {
|
|
10
|
-
elem.properties = JSON.parse(elem.properties);
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
return result;
|
|
14
|
-
});
|
|
10
|
+
const pathname = '/v1/choropleth/polygons/search';
|
|
11
|
+
const query = getSearchParams(Object.assign(Object.assign(Object.assign(Object.assign({ language }, search.searchBounds), (search.query && { query: search.query })), (search.searchPoint && { point: search.searchPoint })), { mode }));
|
|
12
|
+
const path = `${pathname}?${query}`;
|
|
13
|
+
const options = { revivers: singleOrGroupedAreaRevivers };
|
|
14
|
+
return request(path, null, null, options);
|
|
15
15
|
}
|
|
16
|
+
export const groupedAreaChildRevivers = {
|
|
17
|
+
boundingBox: (data) => JSON.parse(data.bounding_box),
|
|
18
|
+
properties: (data) => JSON.parse(data.properties),
|
|
19
|
+
};
|
|
16
20
|
export async function groupedAreaChildren(groupId, language) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
21
|
+
const pathname = `/v1/choropleth/groups/${groupId}/children-optimized`;
|
|
22
|
+
const query = getSearchParams({ language });
|
|
23
|
+
const path = `${pathname}?${query}`;
|
|
24
|
+
const options = { revivers: groupedAreaChildRevivers };
|
|
25
|
+
return request(path, null, null, options);
|
|
23
26
|
}
|
|
24
27
|
export async function getGroupsByDataSample(sample, language) {
|
|
25
28
|
const path = `/v1/choropleth/groups/sample`;
|
|
@@ -27,7 +30,7 @@ export async function getGroupsByDataSample(sample, language) {
|
|
|
27
30
|
}
|
|
28
31
|
export async function getBoundPolygons(groupId, property, data, language) {
|
|
29
32
|
const path = `/v1/choropleth/groups/bind`;
|
|
30
|
-
const
|
|
31
|
-
return request(path,
|
|
33
|
+
const body = { group_id: groupId, property, data, language };
|
|
34
|
+
return request(path, body);
|
|
32
35
|
}
|
|
33
36
|
//# sourceMappingURL=choropleth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"choropleth.js","sourceRoot":"","sources":["../../src/api/choropleth.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"choropleth.js","sourceRoot":"","sources":["../../src/api/choropleth.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+D,eAAe,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAwDpH,MAAM,CAAC,MAAM,2BAA2B,GAA0D;IAChG,WAAW,EAAE,CAAC,IAAgC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAY;IAC3F,UAAU,EAAE,CAAC,IAAgC,EAAE,EAAE,CAC/C,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAA2B,CAAC,CAAC,CAAC,IAAI,CAAC;CAC3F,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,QAAgB,EAChB,MAIE,EACF,OAAqC,MAAM;IAE3C,MAAM,QAAQ,GAAG,gCAAgC,CAAC;IAClD,MAAM,KAAK,GAAG,eAAe,2DAC3B,QAAQ,IACL,MAAM,CAAC,YAAY,GACnB,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,GACzC,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,KACxD,IAAI,IACJ,CAAC;IACH,MAAM,IAAI,GAAG,GAAG,QAAQ,IAAI,KAAK,EAAE,CAAC;IACpC,MAAM,OAAO,GAAG,EAAE,QAAQ,EAAE,2BAA2B,EAAE,CAAC;IAM1D,OAAO,OAAO,CAAmD,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC9F,CAAC;AA0BD,MAAM,CAAC,MAAM,wBAAwB,GAA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js';
|
|
1
|
+
import { type ApiError, type ApiSuccess, type Flatten, type Revivers, getSearchParams, request } from '../utils.js';
|
|
2
2
|
|
|
3
3
|
import type { RequireAtLeastOne } from 'type-fest';
|
|
4
4
|
import type { Polygon } from 'geojson';
|
|
@@ -15,47 +15,54 @@ export type ApiSearchBounds = {
|
|
|
15
15
|
max_lng: number;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
type ApiSingleOrGroupedArea = {
|
|
19
|
-
id: number;
|
|
20
|
-
title: string;
|
|
21
|
-
subtitle: string;
|
|
22
|
-
svg_preview: string;
|
|
23
|
-
bounding_box: string;
|
|
24
|
-
is_group: boolean;
|
|
25
|
-
vector_source: string | null;
|
|
26
|
-
source_layer: string | null;
|
|
27
|
-
feature_id: number | null;
|
|
28
|
-
properties: Record<string, string> | null;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
type ApiSingleOrGroupedAreaArray = {
|
|
32
|
-
data: ApiSingleOrGroupedArea[];
|
|
33
|
-
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
34
|
-
|
|
35
18
|
type SingleOrGroupedAreaBase = {
|
|
36
19
|
id: number;
|
|
37
20
|
title: string;
|
|
38
21
|
subtitle: string;
|
|
39
22
|
svgPreview: string;
|
|
40
23
|
boundingBox: Polygon;
|
|
24
|
+
isGroup: boolean;
|
|
25
|
+
properties: Record<string, string> | null;
|
|
41
26
|
};
|
|
42
27
|
|
|
43
28
|
// TODO don't export this once search on click is out
|
|
44
|
-
export type GroupedArea = SingleOrGroupedAreaBase
|
|
45
|
-
isGroup: true;
|
|
46
|
-
};
|
|
29
|
+
export type GroupedArea = SingleOrGroupedAreaBase;
|
|
47
30
|
|
|
48
31
|
// TODO don't export this once search on click is out
|
|
49
32
|
export type SingleArea = SingleOrGroupedAreaBase & {
|
|
50
|
-
isGroup: false;
|
|
51
33
|
vectorSource: string;
|
|
52
34
|
sourceLayer: string;
|
|
53
35
|
featureId: number;
|
|
54
|
-
properties: Record<string, string>;
|
|
55
36
|
};
|
|
56
37
|
|
|
57
38
|
export type SingleOrGroupedArea = SingleArea | GroupedArea;
|
|
58
39
|
|
|
40
|
+
export type ApiSingleOrGroupedArea = {
|
|
41
|
+
data: {
|
|
42
|
+
id: number;
|
|
43
|
+
title: string;
|
|
44
|
+
subtitle: string;
|
|
45
|
+
svg_preview: string;
|
|
46
|
+
bounding_box: string;
|
|
47
|
+
is_group: boolean;
|
|
48
|
+
vector_source: string | null;
|
|
49
|
+
source_layer: string | null;
|
|
50
|
+
feature_id: number | null;
|
|
51
|
+
properties: string | null;
|
|
52
|
+
};
|
|
53
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
54
|
+
|
|
55
|
+
export type ApiSingleOrGroupedAreaData = Flatten<Exclude<ApiSingleOrGroupedArea, ApiError>['data']>;
|
|
56
|
+
|
|
57
|
+
export const singleOrGroupedAreaRevivers: Revivers<ApiSingleOrGroupedArea, SingleOrGroupedArea> = {
|
|
58
|
+
boundingBox: (data: ApiSingleOrGroupedAreaData) => JSON.parse(data.bounding_box) as Polygon,
|
|
59
|
+
properties: (data: ApiSingleOrGroupedAreaData) =>
|
|
60
|
+
(data.properties != null ? JSON.parse(data.properties) as Record<string, string> : null),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* TODO When SAGA search on click is implemented, remove mode and make searchBounds required
|
|
65
|
+
*/
|
|
59
66
|
export async function searchSingleOrGroupedAreas(
|
|
60
67
|
language: string,
|
|
61
68
|
search: RequireAtLeastOne<{
|
|
@@ -65,43 +72,23 @@ export async function searchSingleOrGroupedAreas(
|
|
|
65
72
|
}>,
|
|
66
73
|
mode: 'polygon' | 'group' | 'both' = 'both',
|
|
67
74
|
): Promise<SingleOrGroupedArea[]> {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
...(search.query && { query: search.query }),
|
|
76
|
-
...(search.searchPoint && { point: search.searchPoint }),
|
|
77
|
-
mode,
|
|
78
|
-
})}`,
|
|
79
|
-
).then(result => {
|
|
80
|
-
result.forEach(
|
|
81
|
-
elem => {
|
|
82
|
-
elem.boundingBox = JSON.parse(elem.boundingBox as unknown as string) as Polygon;
|
|
83
|
-
if (!elem.isGroup) {
|
|
84
|
-
elem.properties = JSON.parse(elem.properties as unknown as string) as Record<string, string>;
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
return result;
|
|
75
|
+
const pathname = '/v1/choropleth/polygons/search';
|
|
76
|
+
const query = getSearchParams({
|
|
77
|
+
language,
|
|
78
|
+
...search.searchBounds,
|
|
79
|
+
...(search.query && { query: search.query }),
|
|
80
|
+
...(search.searchPoint && { point: search.searchPoint }),
|
|
81
|
+
mode,
|
|
90
82
|
});
|
|
91
|
-
}
|
|
83
|
+
const path = `${pathname}?${query}`;
|
|
84
|
+
const options = { revivers: singleOrGroupedAreaRevivers };
|
|
92
85
|
|
|
93
|
-
type
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
vector_source: string;
|
|
97
|
-
source_layer: string;
|
|
98
|
-
feature_id: number;
|
|
99
|
-
properties: Record<string, string>;
|
|
100
|
-
};
|
|
86
|
+
type ApiSingleOrGroupedAreaArray = {
|
|
87
|
+
data: ApiSingleOrGroupedAreaData[];
|
|
88
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
101
89
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
90
|
+
return request<ApiSingleOrGroupedAreaArray, SingleOrGroupedArea>(path, null, null, options);
|
|
91
|
+
}
|
|
105
92
|
|
|
106
93
|
export type GroupedAreaChild = {
|
|
107
94
|
id: number;
|
|
@@ -109,21 +96,40 @@ export type GroupedAreaChild = {
|
|
|
109
96
|
vectorSource: string;
|
|
110
97
|
sourceLayer: string;
|
|
111
98
|
featureId: number;
|
|
99
|
+
boundingBox: Polygon;
|
|
112
100
|
properties: Record<string, string>;
|
|
113
101
|
};
|
|
114
102
|
|
|
103
|
+
type ApiGroupedAreaChild = {
|
|
104
|
+
data: {
|
|
105
|
+
id: number;
|
|
106
|
+
title: string;
|
|
107
|
+
vector_source: string;
|
|
108
|
+
source_layer: string;
|
|
109
|
+
feature_id: number;
|
|
110
|
+
bounding_box: string;
|
|
111
|
+
properties: string;
|
|
112
|
+
};
|
|
113
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
114
|
+
|
|
115
|
+
export type ApiGroupedAreaChildData = Flatten<Exclude<ApiGroupedAreaChild, ApiError>['data']>;
|
|
116
|
+
|
|
117
|
+
export const groupedAreaChildRevivers: Revivers<ApiGroupedAreaChild, GroupedAreaChild> = {
|
|
118
|
+
boundingBox: (data: ApiGroupedAreaChildData) => JSON.parse(data.bounding_box) as Polygon,
|
|
119
|
+
properties: (data: ApiGroupedAreaChildData) => JSON.parse(data.properties) as Record<string, string>,
|
|
120
|
+
};
|
|
121
|
+
|
|
115
122
|
export async function groupedAreaChildren(groupId: number, language: string): Promise<GroupedAreaChild[]> {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
});
|
|
123
|
+
const pathname = `/v1/choropleth/groups/${groupId}/children-optimized`;
|
|
124
|
+
const query = getSearchParams({ language });
|
|
125
|
+
const path = `${pathname}?${query}`;
|
|
126
|
+
const options = { revivers: groupedAreaChildRevivers };
|
|
127
|
+
|
|
128
|
+
type ApiApiGroupedAreaChildArray = {
|
|
129
|
+
data: ApiGroupedAreaChildData[];
|
|
130
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
131
|
+
|
|
132
|
+
return request<ApiApiGroupedAreaChildArray, GroupedAreaChild>(path, null, null, options);
|
|
127
133
|
}
|
|
128
134
|
|
|
129
135
|
export type MatchedGroup = {
|
|
@@ -136,22 +142,26 @@ export type MatchedGroup = {
|
|
|
136
142
|
};
|
|
137
143
|
|
|
138
144
|
export type ApiMatchedGroup = {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
data: {
|
|
146
|
+
id: number;
|
|
147
|
+
sml: number;
|
|
148
|
+
children_count: number;
|
|
149
|
+
match_field: string;
|
|
150
|
+
property: string;
|
|
151
|
+
name: string;
|
|
152
|
+
};
|
|
153
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
154
|
+
|
|
155
|
+
export type ApiMatchedGroupData = Flatten<Exclude<ApiMatchedGroup, ApiError>['data']>;
|
|
146
156
|
|
|
147
157
|
export async function getGroupsByDataSample(
|
|
148
|
-
sample:
|
|
158
|
+
sample: Record<string, string[]>,
|
|
149
159
|
language: string,
|
|
150
160
|
): Promise<MatchedGroup[]> {
|
|
151
161
|
const path = `/v1/choropleth/groups/sample`;
|
|
152
162
|
|
|
153
163
|
type ApiMatchedGroupArray = {
|
|
154
|
-
data:
|
|
164
|
+
data: ApiMatchedGroupData[];
|
|
155
165
|
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
156
166
|
|
|
157
167
|
return request<ApiMatchedGroupArray, MatchedGroup>(path, { sample, language });
|
|
@@ -166,12 +176,16 @@ export type BoundPolygon = {
|
|
|
166
176
|
};
|
|
167
177
|
|
|
168
178
|
export type ApiBoundPolygon = {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
179
|
+
data: {
|
|
180
|
+
index: number;
|
|
181
|
+
id: number;
|
|
182
|
+
sml: number;
|
|
183
|
+
name: string;
|
|
184
|
+
input_name: string;
|
|
185
|
+
};
|
|
186
|
+
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
187
|
+
|
|
188
|
+
export type ApiBoundPolygonData = Flatten<Exclude<ApiBoundPolygon, ApiError>['data']>;
|
|
175
189
|
|
|
176
190
|
export async function getBoundPolygons(
|
|
177
191
|
groupId: number,
|
|
@@ -180,11 +194,11 @@ export async function getBoundPolygons(
|
|
|
180
194
|
language: string,
|
|
181
195
|
): Promise<BoundPolygon[]> {
|
|
182
196
|
const path = `/v1/choropleth/groups/bind`;
|
|
183
|
-
const
|
|
197
|
+
const body = { group_id: groupId, property, data, language };
|
|
184
198
|
|
|
185
199
|
type ApiBoundPolygonArray = {
|
|
186
|
-
data:
|
|
200
|
+
data: ApiBoundPolygonData[];
|
|
187
201
|
} & Omit<ApiSuccess, 'data'> | ApiError;
|
|
188
202
|
|
|
189
|
-
return request<ApiBoundPolygonArray, BoundPolygon>(path,
|
|
203
|
+
return request<ApiBoundPolygonArray, BoundPolygon>(path, body);
|
|
190
204
|
}
|