@carto/api-client 0.4.6-0 → 0.4.6

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/api-client.cjs +208 -2167
  3. package/build/api-client.cjs.map +1 -1
  4. package/build/api-client.modern.js +208 -2040
  5. package/build/api-client.modern.js.map +1 -1
  6. package/build/constants.d.ts +0 -22
  7. package/build/index.d.ts +1 -4
  8. package/build/models/index.d.ts +1 -1
  9. package/build/sources/h3-tileset-source.d.ts +1 -2
  10. package/build/sources/index.d.ts +1 -1
  11. package/build/sources/quadbin-tileset-source.d.ts +1 -2
  12. package/build/sources/vector-tileset-source.d.ts +1 -2
  13. package/build/spatial-index.d.ts +7 -1
  14. package/build/types-internal.d.ts +0 -4
  15. package/build/types.d.ts +1 -61
  16. package/build/widget-sources/index.d.ts +1 -3
  17. package/build/widget-sources/types.d.ts +22 -31
  18. package/build/widget-sources/{widget-source.d.ts → widget-base-source.d.ts} +38 -13
  19. package/build/widget-sources/widget-query-source.d.ts +2 -2
  20. package/build/widget-sources/widget-table-source.d.ts +2 -2
  21. package/package.json +11 -14
  22. package/src/constants.ts +0 -25
  23. package/src/index.ts +1 -5
  24. package/src/models/index.ts +1 -1
  25. package/src/sources/h3-tileset-source.ts +6 -18
  26. package/src/sources/index.ts +1 -1
  27. package/src/sources/quadbin-tileset-source.ts +6 -18
  28. package/src/sources/raster-source.ts +0 -1
  29. package/src/sources/vector-query-source.ts +2 -5
  30. package/src/sources/vector-table-source.ts +2 -5
  31. package/src/sources/vector-tileset-source.ts +6 -19
  32. package/src/spatial-index.ts +8 -5
  33. package/src/types-internal.ts +0 -6
  34. package/src/types.ts +2 -60
  35. package/src/widget-sources/index.ts +1 -3
  36. package/src/widget-sources/types.ts +22 -32
  37. package/src/widget-sources/{widget-remote-source.ts → widget-base-source.ts} +147 -12
  38. package/src/widget-sources/widget-query-source.ts +3 -6
  39. package/src/widget-sources/widget-table-source.ts +3 -6
  40. package/build/filters/Filter.d.ts +0 -13
  41. package/build/filters/FilterTypes.d.ts +0 -3
  42. package/build/filters/geosjonFeatures.d.ts +0 -8
  43. package/build/filters/index.d.ts +0 -6
  44. package/build/filters/tileFeatures.d.ts +0 -20
  45. package/build/filters/tileFeaturesGeometries.d.ts +0 -13
  46. package/build/filters/tileFeaturesSpatialIndex.d.ts +0 -10
  47. package/build/operations/aggregation.d.ts +0 -8
  48. package/build/operations/applySorting.d.ts +0 -20
  49. package/build/operations/groupBy.d.ts +0 -15
  50. package/build/operations/groupByDate.d.ts +0 -11
  51. package/build/operations/histogram.d.ts +0 -13
  52. package/build/operations/index.d.ts +0 -6
  53. package/build/operations/scatterPlot.d.ts +0 -14
  54. package/build/utils/dateUtils.d.ts +0 -10
  55. package/build/utils/getTileFormat.d.ts +0 -3
  56. package/build/utils/makeIntervalComplete.d.ts +0 -2
  57. package/build/utils/transformTileCoordsToWGS84.d.ts +0 -8
  58. package/build/utils/transformToTileCoords.d.ts +0 -9
  59. package/build/widget-sources/widget-remote-source.d.ts +0 -18
  60. package/build/widget-sources/widget-tileset-source.d.ts +0 -76
  61. package/src/filters/Filter.ts +0 -169
  62. package/src/filters/FilterTypes.ts +0 -109
  63. package/src/filters/geosjonFeatures.ts +0 -32
  64. package/src/filters/index.ts +0 -6
  65. package/src/filters/tileFeatures.ts +0 -56
  66. package/src/filters/tileFeaturesGeometries.ts +0 -444
  67. package/src/filters/tileFeaturesSpatialIndex.ts +0 -119
  68. package/src/operations/aggregation.ts +0 -154
  69. package/src/operations/applySorting.ts +0 -109
  70. package/src/operations/groupBy.ts +0 -59
  71. package/src/operations/groupByDate.ts +0 -98
  72. package/src/operations/histogram.ts +0 -66
  73. package/src/operations/index.ts +0 -6
  74. package/src/operations/scatterPlot.ts +0 -50
  75. package/src/utils/dateUtils.ts +0 -28
  76. package/src/utils/getTileFormat.ts +0 -9
  77. package/src/utils/makeIntervalComplete.ts +0 -17
  78. package/src/utils/transformTileCoordsToWGS84.ts +0 -77
  79. package/src/utils/transformToTileCoords.ts +0 -85
  80. package/src/widget-sources/widget-source.ts +0 -160
  81. package/src/widget-sources/widget-tileset-source.ts +0 -407
@@ -1,154 +0,0 @@
1
- import {AggregationType} from '../types';
2
- import {FeatureData} from '../types-internal';
3
-
4
- /** @internalRemarks Source: @carto/react-core */
5
- export type AggregationFunction = (
6
- values: unknown[] | FeatureData[],
7
- keys?: string[] | string,
8
- joinOperation?: AggregationType
9
- ) => number;
10
-
11
- /** @internalRemarks Source: @carto/react-core */
12
- export const aggregationFunctions: Record<
13
- Exclude<AggregationType, 'custom'>,
14
- AggregationFunction
15
- > = {
16
- count: (values) => values.length,
17
- min: (...args) => applyAggregationFunction(min, ...args),
18
- max: (...args) => applyAggregationFunction(max, ...args),
19
- sum: (...args) => applyAggregationFunction(sum, ...args),
20
- avg: (...args) => applyAggregationFunction(avg, ...args),
21
- };
22
-
23
- /** @internalRemarks Source: @carto/react-core */
24
- export function aggregate(
25
- feature: FeatureData,
26
- keys?: string[],
27
- operation?: AggregationType
28
- ): unknown {
29
- if (!keys?.length) {
30
- throw new Error('Cannot aggregate a feature without having keys');
31
- } else if (keys.length === 1) {
32
- const value = feature[keys[0]];
33
- return isPotentiallyValidNumber(value) ? Number(value) : value;
34
- }
35
-
36
- const aggregationFn =
37
- aggregationFunctions[operation as Exclude<AggregationType, 'custom'>];
38
-
39
- if (!aggregationFn) {
40
- throw new Error(`${operation} isn't a valid aggregation function`);
41
- }
42
-
43
- return aggregationFn(
44
- keys.map((column) => {
45
- const value = feature[column];
46
- return isPotentiallyValidNumber(value) ? Number(value) : value;
47
- })
48
- );
49
- }
50
-
51
- /*
52
- * Forced casting to Number (just of non empty strings) allows to work-around
53
- * some specific situations, where a big numeric field is transformed into a string when generating the tileset(eg.PG)
54
- */
55
- function isPotentiallyValidNumber(value: unknown): boolean {
56
- return typeof value === 'string' && value.trim().length > 0;
57
- }
58
-
59
- const applyAggregationFunction = (
60
- aggFn: AggregationFunction,
61
- values: unknown[] | FeatureData[],
62
- keys?: string[] | string,
63
- operation?: AggregationType
64
- ) => {
65
- const normalizedKeys = normalizeKeys(keys);
66
- const elements =
67
- (normalizedKeys?.length || 0) <= 1
68
- ? filterFalsyElements(values as unknown[], normalizedKeys || [])
69
- : values;
70
- return aggFn(elements, keys, operation);
71
- };
72
-
73
- function filterFalsyElements(
74
- values: unknown[] | FeatureData[],
75
- keys: string[]
76
- ) {
77
- const filterFn = (value: unknown) => value !== null && value !== undefined;
78
-
79
- if (!keys?.length) {
80
- return values.filter(filterFn);
81
- }
82
-
83
- return (values as FeatureData[]).filter((v) => filterFn(v[keys[0]]));
84
- }
85
-
86
- // Aggregation functions
87
- function avg(
88
- values: unknown[] | FeatureData[],
89
- keys?: string[] | string,
90
- joinOperation?: AggregationType
91
- ): number {
92
- return sum(values, keys, joinOperation) / (values.length || 1);
93
- }
94
-
95
- function sum(
96
- values: unknown[] | FeatureData[],
97
- keys?: string[] | string,
98
- joinOperation?: AggregationType
99
- ): number {
100
- const normalizedKeys = normalizeKeys(keys);
101
-
102
- if (normalizedKeys) {
103
- return (values as FeatureData[]).reduce(
104
- (a, b) => a + (aggregate(b, normalizedKeys, joinOperation) as number),
105
- 0
106
- );
107
- }
108
-
109
- return values.reduce((a: number, b: unknown) => a + (b as number), 0);
110
- }
111
-
112
- function min(
113
- values: unknown[] | FeatureData[],
114
- keys?: string[] | string,
115
- joinOperation?: AggregationType
116
- ): number {
117
- const normalizedKeys = normalizeKeys(keys);
118
- if (normalizedKeys) {
119
- return (values as FeatureData[]).reduce(
120
- (a, b) =>
121
- Math.min(a, aggregate(b, normalizedKeys, joinOperation) as number),
122
- Infinity
123
- );
124
- }
125
- return Math.min(...(values as number[]));
126
- }
127
-
128
- function max(
129
- values: unknown[] | FeatureData[],
130
- keys?: string[] | string,
131
- joinOperation?: AggregationType
132
- ): number {
133
- const normalizedKeys = normalizeKeys(keys);
134
- if (normalizedKeys) {
135
- return (values as FeatureData[]).reduce(
136
- (a, b) =>
137
- Math.max(a, aggregate(b, normalizedKeys, joinOperation) as number),
138
- -Infinity
139
- );
140
- }
141
- return Math.max(...(values as number[]));
142
- }
143
-
144
- // Aux
145
-
146
- // Keys can come as a string (one column) or a strings array (multiple column)
147
- // Use always an array to make the code easier
148
- function normalizeKeys(keys: unknown): string[] | undefined {
149
- return Array.isArray(keys)
150
- ? keys
151
- : typeof keys === 'string'
152
- ? [keys]
153
- : undefined;
154
- }
@@ -1,109 +0,0 @@
1
- import {firstBy} from 'thenby';
2
- import {SortDirection} from '../types';
3
- import {FeatureData} from '../types-internal';
4
-
5
- // TODO(cleanup): Could this be simplified?
6
- type SortColumns = string | string[] | object[];
7
-
8
- interface SortOptions {
9
- sortBy?: SortColumns;
10
- sortByDirection?: SortDirection;
11
- sortByColumnType?: 'number' | 'string' | 'date';
12
- }
13
-
14
- /**
15
- * Apply sort structure to a collection of features
16
- * @param features
17
- * @param [sortOptions]
18
- * @param [sortOptions.sortBy] - One or more columns to sort by
19
- * @param [sortOptions.sortByDirection] - Direction by the columns will be sorted
20
- * @param [sortOptions.sortByColumnType] - Column type
21
- * @internal
22
- * @internalRemarks Source: @carto/react-core
23
- */
24
- export function applySorting(
25
- features: FeatureData[],
26
- {
27
- sortBy,
28
- sortByDirection = 'asc',
29
- sortByColumnType = 'string',
30
- }: SortOptions = {}
31
- ): FeatureData[] {
32
- // If sortBy is undefined, pass all features
33
- if (sortBy === undefined) {
34
- return features;
35
- }
36
-
37
- // sortOptions exists, but are bad formatted
38
- const isValidSortBy =
39
- (Array.isArray(sortBy) && sortBy.length) || // sortBy can be an array of columns
40
- typeof sortBy === 'string'; // or just one column
41
-
42
- if (!isValidSortBy) {
43
- throw new Error('Sorting options are bad formatted');
44
- }
45
- const sortFn = createSortFn({
46
- sortBy,
47
- sortByDirection,
48
- sortByColumnType: sortByColumnType || 'string',
49
- });
50
- return features.sort(sortFn);
51
- }
52
-
53
- // Aux
54
- function createSortFn({
55
- sortBy,
56
- sortByDirection,
57
- sortByColumnType,
58
- }: Required<SortOptions>) {
59
- const [firstSortOption, ...othersSortOptions] = normalizeSortByOptions({
60
- sortBy,
61
- sortByDirection,
62
- sortByColumnType,
63
- }) as Parameters<typeof firstBy>[];
64
-
65
- let sortFn = firstBy(...firstSortOption);
66
- for (let sortOptions of othersSortOptions) {
67
- sortFn = sortFn.thenBy(...sortOptions);
68
- }
69
-
70
- return sortFn;
71
- }
72
-
73
- function normalizeSortByOptions({
74
- sortBy,
75
- sortByDirection,
76
- sortByColumnType,
77
- }: Required<SortOptions>) {
78
- const numberFormat = sortByColumnType === 'number' && {
79
- cmp: (a: number, b: number) => a - b,
80
- };
81
- if (!Array.isArray(sortBy)) {
82
- sortBy = [sortBy];
83
- }
84
- return sortBy.map((sortByEl) => {
85
- // sortByEl is 'column'
86
- if (typeof sortByEl === 'string') {
87
- return [sortByEl, {direction: sortByDirection, ...numberFormat}];
88
- }
89
-
90
- if (Array.isArray(sortByEl)) {
91
- // sortBy is ['column']
92
- if (sortByEl[1] === undefined) {
93
- return [sortByEl, {direction: sortByDirection, ...numberFormat}];
94
- }
95
-
96
- // sortBy is ['column', { ... }]
97
- if (typeof sortByEl[1] === 'object') {
98
- const othersSortOptions = numberFormat
99
- ? {...numberFormat, ...sortByEl[1]}
100
- : sortByEl[1];
101
- return [
102
- sortByEl[0],
103
- {direction: sortByDirection, ...othersSortOptions},
104
- ];
105
- }
106
- }
107
- return sortByEl;
108
- });
109
- }
@@ -1,59 +0,0 @@
1
- import {aggregationFunctions, aggregate} from './aggregation.js';
2
- import {AggregationType} from '../types';
3
- import {FeatureData} from '../types-internal';
4
-
5
- /** @internalRemarks Source: @carto/react-core */
6
- export type GroupByFeature = {
7
- name: string;
8
- value: number;
9
- }[];
10
-
11
- /** @internalRemarks Source: @carto/react-core */
12
- export function groupValuesByColumn({
13
- data,
14
- valuesColumns,
15
- joinOperation,
16
- keysColumn,
17
- operation,
18
- }: {
19
- data: FeatureData[];
20
- valuesColumns?: string[];
21
- joinOperation?: AggregationType;
22
- keysColumn: string;
23
- operation: AggregationType;
24
- }): GroupByFeature | null {
25
- if (Array.isArray(data) && data.length === 0) {
26
- return null;
27
- }
28
- const groups = data.reduce((accumulator, item) => {
29
- const group = item[keysColumn];
30
-
31
- const values = accumulator.get(group) || [];
32
- accumulator.set(group, values);
33
-
34
- const aggregatedValue = aggregate(item, valuesColumns, joinOperation);
35
-
36
- const isValid =
37
- (operation === 'count' ? true : aggregatedValue !== null) &&
38
- aggregatedValue !== undefined;
39
-
40
- if (isValid) {
41
- values.push(aggregatedValue);
42
- accumulator.set(group, values);
43
- }
44
-
45
- return accumulator;
46
- }, new Map()); // We use a map to be able to maintain the type in the key value
47
-
48
- const targetOperation =
49
- aggregationFunctions[operation as Exclude<AggregationType, 'custom'>];
50
-
51
- if (targetOperation) {
52
- return Array.from(groups).map(([name, value]) => ({
53
- name,
54
- value: targetOperation(value),
55
- }));
56
- }
57
-
58
- return [];
59
- }
@@ -1,98 +0,0 @@
1
- import {AggregationType, GroupDateType} from '../types.js';
2
- import {getUTCMonday} from '../utils/dateUtils.js';
3
- import {aggregate, aggregationFunctions} from './aggregation.js';
4
- import {GroupByFeature} from './groupBy.js';
5
-
6
- const GROUP_KEY_FN_MAPPING: Record<GroupDateType, (date: Date) => number> = {
7
- year: (date: Date) => Date.UTC(date.getUTCFullYear()),
8
- month: (date: Date) => Date.UTC(date.getUTCFullYear(), date.getUTCMonth()),
9
- week: (date: Date) => getUTCMonday(date),
10
- day: (date: Date) =>
11
- Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()),
12
- hour: (date: Date) =>
13
- Date.UTC(
14
- date.getUTCFullYear(),
15
- date.getUTCMonth(),
16
- date.getUTCDate(),
17
- date.getUTCHours()
18
- ),
19
- minute: (date: Date) =>
20
- Date.UTC(
21
- date.getUTCFullYear(),
22
- date.getUTCMonth(),
23
- date.getUTCDate(),
24
- date.getUTCHours(),
25
- date.getUTCMinutes()
26
- ),
27
- second: (date: Date) =>
28
- Date.UTC(
29
- date.getUTCFullYear(),
30
- date.getUTCMonth(),
31
- date.getUTCDate(),
32
- date.getUTCHours(),
33
- date.getUTCMinutes(),
34
- date.getUTCSeconds()
35
- ),
36
- };
37
-
38
- /** @internalRemarks Source: @carto/react-core */
39
- export function groupValuesByDateColumn({
40
- data,
41
- valuesColumns,
42
- joinOperation,
43
- keysColumn,
44
- groupType,
45
- operation,
46
- }: {
47
- data: Record<string, unknown>[];
48
- valuesColumns?: string[];
49
- joinOperation?: Exclude<AggregationType, 'custom'>;
50
- keysColumn: string;
51
- groupType: GroupDateType;
52
- operation?: Exclude<AggregationType, 'custom'>;
53
- }): GroupByFeature | null {
54
- if (Array.isArray(data) && data.length === 0) {
55
- return null;
56
- }
57
-
58
- const groupKeyFn = GROUP_KEY_FN_MAPPING[groupType];
59
-
60
- if (!groupKeyFn) {
61
- return null;
62
- }
63
-
64
- const groups = data.reduce((acc, item) => {
65
- const value = item[keysColumn];
66
- const formattedValue = new Date(value as number);
67
- const groupKey = groupKeyFn(formattedValue);
68
-
69
- if (!isNaN(groupKey)) {
70
- let groupedValues = acc.get(groupKey);
71
- if (!groupedValues) {
72
- groupedValues = [];
73
- acc.set(groupKey, groupedValues);
74
- }
75
-
76
- const aggregatedValue = aggregate(item, valuesColumns, joinOperation);
77
-
78
- const isValid = aggregatedValue !== null && aggregatedValue !== undefined;
79
-
80
- if (isValid) {
81
- groupedValues.push(aggregatedValue);
82
- acc.set(groupKey, groupedValues);
83
- }
84
- }
85
-
86
- return acc;
87
- }, new Map());
88
-
89
- const targetOperation =
90
- aggregationFunctions[operation as Exclude<AggregationType, 'custom'>];
91
-
92
- return [...groups.entries()]
93
- .map(([name, value]) => ({
94
- name,
95
- value: targetOperation(value),
96
- }))
97
- .sort((a, b) => a.name - b.name);
98
- }
@@ -1,66 +0,0 @@
1
- import {aggregate, aggregationFunctions} from './aggregation';
2
- import {AggregationType} from '../types';
3
- import {FeatureData} from '../types-internal';
4
-
5
- /**
6
- * Histogram computation.
7
- * @internalRemarks Source: @carto/react-core
8
- */
9
- export function histogram({
10
- data,
11
- valuesColumns,
12
- joinOperation,
13
- ticks,
14
- operation,
15
- }: {
16
- data: FeatureData[];
17
- valuesColumns?: string[];
18
- joinOperation?: Exclude<AggregationType, 'custom'>;
19
- ticks: number[];
20
- operation: Exclude<AggregationType, 'custom'>;
21
- }): number[] {
22
- if (Array.isArray(data) && data.length === 0) {
23
- return [];
24
- }
25
-
26
- const binsContainer = [Number.MIN_SAFE_INTEGER, ...ticks].map(
27
- (tick, index, arr) => ({
28
- bin: index,
29
- start: tick,
30
- end: index === arr.length - 1 ? Number.MAX_SAFE_INTEGER : arr[index + 1],
31
- values: [] as number[],
32
- })
33
- );
34
-
35
- data.forEach((feature) => {
36
- const featureValue = aggregate(
37
- feature,
38
- valuesColumns,
39
- joinOperation
40
- ) as number;
41
-
42
- const isValid = featureValue !== null && featureValue !== undefined;
43
-
44
- if (!isValid) {
45
- return;
46
- }
47
-
48
- const binContainer = binsContainer.find(
49
- (bin) => bin.start <= featureValue && bin.end > featureValue
50
- );
51
-
52
- if (!binContainer) {
53
- return;
54
- }
55
-
56
- binContainer.values.push(featureValue);
57
- });
58
-
59
- const targetOperation = aggregationFunctions[operation];
60
- const transformedBins = binsContainer.map(
61
- (binContainer) => binContainer.values
62
- );
63
- return transformedBins.map((values) =>
64
- values.length ? targetOperation(values) : 0
65
- );
66
- }
@@ -1,6 +0,0 @@
1
- export * from './aggregation.js';
2
- export * from './applySorting.js';
3
- export * from './groupBy.js';
4
- export * from './groupByDate.js';
5
- export * from './histogram.js';
6
- export * from './scatterPlot.js';
@@ -1,50 +0,0 @@
1
- import {aggregate} from './aggregation';
2
- import {FeatureData} from '../types-internal';
3
- import {AggregationType} from '../types';
4
-
5
- export type ScatterPlotFeature = [number, number][];
6
-
7
- /**
8
- * Filters invalid features and formats data.
9
- * @internalRemarks Source: @carto/react-core
10
- */
11
- export function scatterPlot({
12
- data,
13
- xAxisColumns,
14
- xAxisJoinOperation,
15
- yAxisColumns,
16
- yAxisJoinOperation,
17
- }: {
18
- data: FeatureData[];
19
- xAxisColumns: string[];
20
- xAxisJoinOperation?: AggregationType;
21
- yAxisColumns: string[];
22
- yAxisJoinOperation?: AggregationType;
23
- }): ScatterPlotFeature {
24
- return data.reduce(
25
- (acc, feature) => {
26
- const xValue = aggregate(
27
- feature,
28
- xAxisColumns,
29
- xAxisJoinOperation
30
- ) as number;
31
-
32
- const xIsValid = xValue !== null && xValue !== undefined;
33
-
34
- const yValue = aggregate(
35
- feature,
36
- yAxisColumns,
37
- yAxisJoinOperation
38
- ) as number;
39
-
40
- const yIsValid = yValue !== null && yValue !== undefined;
41
-
42
- if (xIsValid && yIsValid) {
43
- acc.push([xValue, yValue]);
44
- }
45
-
46
- return acc;
47
- },
48
- [] as [number, number][]
49
- );
50
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * Returns midnight (local time) on the Monday preceeding a given date, in
3
- * milliseconds since the UNIX epoch.
4
- */
5
- export function getMonday(date: number | Date): number {
6
- const dateCp = new Date(date);
7
- const day = dateCp.getDay();
8
- const diff = dateCp.getDate() - day + (day ? 1 : -6); // adjust when day is sunday
9
- dateCp.setDate(diff);
10
- dateCp.setHours(0, 0, 0, 0);
11
- return dateCp.getTime();
12
- }
13
-
14
- /**
15
- * Returns midnight (UTC) on the Monday preceeding a given date, in
16
- * milliseconds since the UNIX epoch.
17
- */
18
- export function getUTCMonday(date: number | Date): number {
19
- const dateCp = new Date(date);
20
- const day = dateCp.getUTCDay();
21
- const diff = dateCp.getUTCDate() - day + (day ? 1 : -6); // adjust when day is sunday
22
- dateCp.setUTCDate(diff);
23
- return Date.UTC(
24
- dateCp.getUTCFullYear(),
25
- dateCp.getUTCMonth(),
26
- dateCp.getUTCDate()
27
- );
28
- }
@@ -1,9 +0,0 @@
1
- import {TileFormat} from '../constants.js';
2
- import {Tilejson} from '../sources/types.js';
3
-
4
- export function getTileFormat(tilejson: Tilejson): TileFormat {
5
- const tileParams = new URL(tilejson.tiles[0]).searchParams;
6
- return tileParams.get('formatTiles') === 'mvt'
7
- ? TileFormat.MVT
8
- : TileFormat.BINARY;
9
- }
@@ -1,17 +0,0 @@
1
- import {FilterInterval, FilterIntervalComplete} from '../types';
2
-
3
- export function makeIntervalComplete(
4
- intervals: FilterInterval[]
5
- ): FilterIntervalComplete[] {
6
- return intervals.map((val) => {
7
- if (val[0] === undefined || val[0] === null) {
8
- return [Number.MIN_SAFE_INTEGER, val[1]];
9
- }
10
-
11
- if (val[1] === undefined || val[1] === null) {
12
- return [val[0], Number.MAX_SAFE_INTEGER];
13
- }
14
-
15
- return val;
16
- }) as FilterIntervalComplete[];
17
- }
@@ -1,77 +0,0 @@
1
- import {lerp} from '@math.gl/core';
2
- import {lngLatToWorld, worldToLngLat} from '@math.gl/web-mercator';
3
- import {BBox, GeoJsonGeometryTypes, Geometry, Position} from 'geojson';
4
-
5
- type TransformFn = (coordinates: any[], bbox: Position[]) => any[];
6
-
7
- const TRANSFORM_FN: Record<
8
- Exclude<GeoJsonGeometryTypes, 'GeometryCollection'>,
9
- TransformFn
10
- > = {
11
- Point: transformPoint,
12
- MultiPoint: transformMultiPoint,
13
- LineString: transformLineString,
14
- MultiLineString: transformMultiLineString,
15
- Polygon: transformPolygon,
16
- MultiPolygon: transformMultiPolygon,
17
- };
18
-
19
- /**
20
- * Transform tile coords to WGS84 coordinates.
21
- *
22
- * @param geometry - any valid geojson geometry
23
- * @param bbox - geojson bbox
24
- */
25
- export function transformTileCoordsToWGS84<T extends Geometry>(
26
- geometry: T,
27
- bbox: BBox
28
- ): T {
29
- const [west, south, east, north] = bbox;
30
- const nw = lngLatToWorld([west, north]);
31
- const se = lngLatToWorld([east, south]);
32
- const projectedBbox = [nw, se];
33
-
34
- if (geometry.type === 'GeometryCollection') {
35
- throw new Error('Unsupported geometry type GeometryCollection');
36
- }
37
-
38
- const transformFn = TRANSFORM_FN[geometry.type];
39
- const coordinates = transformFn(geometry.coordinates, projectedBbox);
40
- return {...geometry, coordinates};
41
- }
42
-
43
- function transformPoint([pointX, pointY]: Position, [nw, se]: Position[]) {
44
- const x = lerp(nw[0], se[0], pointX);
45
- const y = lerp(nw[1], se[1], pointY);
46
-
47
- return worldToLngLat([x, y]);
48
- }
49
-
50
- function getPoints(geometry: Position[], bbox: Position[]) {
51
- return geometry.map((g) => transformPoint(g, bbox));
52
- }
53
-
54
- function transformMultiPoint(multiPoint: Position[], bbox: Position[]) {
55
- return getPoints(multiPoint, bbox);
56
- }
57
-
58
- function transformLineString(line: Position[], bbox: Position[]) {
59
- return getPoints(line, bbox);
60
- }
61
-
62
- function transformMultiLineString(
63
- multiLineString: Position[][],
64
- bbox: Position[]
65
- ) {
66
- return multiLineString.map((lineString) =>
67
- transformLineString(lineString, bbox)
68
- );
69
- }
70
-
71
- function transformPolygon(polygon: Position[][], bbox: Position[]) {
72
- return polygon.map((polygonRing) => getPoints(polygonRing, bbox));
73
- }
74
-
75
- function transformMultiPolygon(multiPolygon: Position[][][], bbox: Position[]) {
76
- return multiPolygon.map((polygon) => transformPolygon(polygon, bbox));
77
- }