@deck.gl/carto 8.8.6 → 8.8.9
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/dist/dist.dev.js +36391 -28108
- package/dist/es5/api/maps-v3-client.js +31 -24
- package/dist/es5/api/maps-v3-client.js.map +1 -1
- package/dist/es5/layers/carto-layer.js +5 -0
- package/dist/es5/layers/carto-layer.js.map +1 -1
- package/dist/es5/layers/carto-tile-layer.js +1 -1
- package/dist/es5/layers/carto-tile-layer.js.map +1 -1
- package/dist/es5/layers/quadbin-utils.js +2 -0
- package/dist/es5/layers/quadbin-utils.js.map +1 -1
- package/dist/es5/layers/schema/carto-spatial-tile-loader.js +99 -0
- package/dist/es5/layers/schema/carto-spatial-tile-loader.js.map +1 -0
- package/dist/es5/layers/schema/carto-spatial-tile.js +117 -0
- package/dist/es5/layers/schema/carto-spatial-tile.js.map +1 -0
- package/dist/es5/layers/schema/carto-tile.js +5 -1
- package/dist/es5/layers/schema/carto-tile.js.map +1 -1
- package/dist/es5/layers/schema/spatialjson-utils.js +41 -0
- package/dist/es5/layers/schema/spatialjson-utils.js.map +1 -0
- package/dist/es5/layers/spatial-index-tile-layer.js +6 -0
- package/dist/es5/layers/spatial-index-tile-layer.js.map +1 -1
- package/dist/esm/api/maps-v3-client.js +19 -6
- package/dist/esm/api/maps-v3-client.js.map +1 -1
- package/dist/esm/layers/carto-layer.js +5 -0
- package/dist/esm/layers/carto-layer.js.map +1 -1
- package/dist/esm/layers/carto-tile-layer.js +1 -1
- package/dist/esm/layers/carto-tile-layer.js.map +1 -1
- package/dist/esm/layers/quadbin-utils.js +2 -5
- package/dist/esm/layers/quadbin-utils.js.map +1 -1
- package/dist/esm/layers/schema/carto-spatial-tile-loader.js +56 -0
- package/dist/esm/layers/schema/carto-spatial-tile-loader.js.map +1 -0
- package/dist/esm/layers/schema/carto-spatial-tile.js +72 -0
- package/dist/esm/layers/schema/carto-spatial-tile.js.map +1 -0
- package/dist/esm/layers/schema/carto-tile.js +2 -2
- package/dist/esm/layers/schema/carto-tile.js.map +1 -1
- package/dist/esm/layers/schema/spatialjson-utils.js +26 -0
- package/dist/esm/layers/schema/spatialjson-utils.js.map +1 -0
- package/dist/esm/layers/spatial-index-tile-layer.js +3 -0
- package/dist/esm/layers/spatial-index-tile-layer.js.map +1 -1
- package/dist.min.js +4 -4
- package/package.json +2 -2
- package/src/api/maps-v3-client.ts +33 -10
- package/src/layers/carto-layer.ts +7 -1
- package/src/layers/carto-tile-layer.ts +6 -3
- package/src/layers/quadbin-utils.ts +2 -2
- package/src/layers/schema/carto-spatial-tile-loader.ts +59 -0
- package/src/layers/schema/carto-spatial-tile.ts +83 -0
- package/src/layers/schema/carto-tile.ts +6 -6
- package/src/layers/schema/spatialjson-utils.ts +35 -0
- package/src/layers/spatial-index-tile-layer.ts +4 -0
- package/typed/api/index.js +3 -0
- package/typed/api/layer-map.js +264 -0
- package/typed/api/maps-api-common.js +50 -0
- package/typed/api/maps-client.js +125 -0
- package/typed/api/maps-v3-client.d.ts +6 -3
- package/typed/api/maps-v3-client.d.ts.map +1 -1
- package/typed/api/maps-v3-client.js +304 -0
- package/typed/api/parseMap.js +178 -0
- package/typed/basemap.js +9 -0
- package/typed/config.js +35 -0
- package/typed/index.js +10 -0
- package/typed/layers/carto-layer.d.ts +3 -0
- package/typed/layers/carto-layer.d.ts.map +1 -1
- package/typed/layers/carto-layer.js +173 -0
- package/typed/layers/carto-tile-layer.d.ts.map +1 -1
- package/typed/layers/carto-tile-layer.js +105 -0
- package/typed/layers/h3-tile-layer.js +47 -0
- package/typed/layers/h3-tileset-2d.js +85 -0
- package/typed/layers/quadbin-utils.d.ts +2 -0
- package/typed/layers/quadbin-utils.d.ts.map +1 -1
- package/typed/layers/quadkey-tile-layer.js +42 -0
- package/typed/layers/quadkey-tileset-2d.js +36 -0
- package/typed/layers/schema/carto-spatial-tile-loader.d.ts +4 -0
- package/typed/layers/schema/carto-spatial-tile-loader.d.ts.map +1 -0
- package/typed/layers/schema/carto-spatial-tile.d.ts +21 -0
- package/typed/layers/schema/carto-spatial-tile.d.ts.map +1 -0
- package/typed/layers/schema/carto-tile.d.ts +15 -3
- package/typed/layers/schema/carto-tile.d.ts.map +1 -1
- package/typed/layers/schema/carto-tile.js +161 -0
- package/typed/layers/schema/spatialjson-utils.d.ts +25 -0
- package/typed/layers/schema/spatialjson-utils.d.ts.map +1 -0
- package/typed/layers/spatial-index-tile-layer.d.ts.map +1 -1
- package/typed/layers/spatial-index-tile-layer.js +40 -0
- package/typed/style/color-bins-style.js +12 -0
- package/typed/style/color-categories-style.js +16 -0
- package/typed/style/color-continuous-style.js +12 -0
- package/typed/style/palette.js +62 -0
- package/typed/style/utils.js +15 -0
- package/typed/utils.js +4 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@deck.gl/carto",
|
|
3
3
|
"description": "CARTO official integration with Deck.gl. Build geospatial applications using CARTO and Deck.gl.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "8.8.
|
|
5
|
+
"version": "8.8.9",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"@deck.gl/layers": "^8.0.0",
|
|
62
62
|
"@loaders.gl/core": "^3.0.0"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "1cceaed3dad056c3fb51864e7f56585271ed1e5a"
|
|
65
65
|
}
|
|
@@ -29,9 +29,11 @@ import {assert} from '../utils';
|
|
|
29
29
|
const MAX_GET_LENGTH = 2048;
|
|
30
30
|
const DEFAULT_CLIENT = 'deck-gl-carto';
|
|
31
31
|
|
|
32
|
+
export type Headers = Record<string, string>;
|
|
32
33
|
interface RequestParams {
|
|
33
34
|
method?: string;
|
|
34
35
|
url: string;
|
|
36
|
+
headers?: Headers;
|
|
35
37
|
accessToken?: string;
|
|
36
38
|
body?: any;
|
|
37
39
|
}
|
|
@@ -39,8 +41,15 @@ interface RequestParams {
|
|
|
39
41
|
/**
|
|
40
42
|
* Request against Maps API
|
|
41
43
|
*/
|
|
42
|
-
async function request({
|
|
43
|
-
|
|
44
|
+
async function request({
|
|
45
|
+
method,
|
|
46
|
+
url,
|
|
47
|
+
headers: customHeaders,
|
|
48
|
+
accessToken,
|
|
49
|
+
body
|
|
50
|
+
}: RequestParams): Promise<Response> {
|
|
51
|
+
const headers: Headers = {
|
|
52
|
+
...customHeaders,
|
|
44
53
|
Accept: 'application/json'
|
|
45
54
|
};
|
|
46
55
|
|
|
@@ -67,10 +76,11 @@ async function request({method, url, accessToken, body}: RequestParams): Promise
|
|
|
67
76
|
async function requestJson<T = unknown>({
|
|
68
77
|
method,
|
|
69
78
|
url,
|
|
79
|
+
headers,
|
|
70
80
|
accessToken,
|
|
71
81
|
body
|
|
72
82
|
}: RequestParams): Promise<T> {
|
|
73
|
-
const response = await request({method, url, accessToken, body});
|
|
83
|
+
const response = await request({method, url, headers, accessToken, body});
|
|
74
84
|
const json = await response.json();
|
|
75
85
|
|
|
76
86
|
if (!response.ok) {
|
|
@@ -121,6 +131,7 @@ type FetchLayerDataParams = {
|
|
|
121
131
|
clientId?: string;
|
|
122
132
|
format?: Format;
|
|
123
133
|
formatTiles?: TileFormat;
|
|
134
|
+
headers?: Headers;
|
|
124
135
|
aggregationExp?: string;
|
|
125
136
|
aggregationResLevel?: number;
|
|
126
137
|
queryParameters?: QueryParameters;
|
|
@@ -180,6 +191,7 @@ export async function mapInstantiation({
|
|
|
180
191
|
geoColumn,
|
|
181
192
|
columns,
|
|
182
193
|
clientId,
|
|
194
|
+
headers,
|
|
183
195
|
aggregationExp,
|
|
184
196
|
aggregationResLevel,
|
|
185
197
|
queryParameters
|
|
@@ -204,10 +216,10 @@ export async function mapInstantiation({
|
|
|
204
216
|
client: clientId || DEFAULT_CLIENT,
|
|
205
217
|
queryParameters
|
|
206
218
|
});
|
|
207
|
-
return await requestJson({method: 'POST', url: baseUrl, accessToken, body});
|
|
219
|
+
return await requestJson({method: 'POST', url: baseUrl, headers, accessToken, body});
|
|
208
220
|
}
|
|
209
221
|
|
|
210
|
-
return await requestJson({url, accessToken});
|
|
222
|
+
return await requestJson({url, headers, accessToken});
|
|
211
223
|
}
|
|
212
224
|
|
|
213
225
|
function getUrlFromMetadata(metadata: MapInstantiation, format: Format): string | null {
|
|
@@ -277,6 +289,7 @@ export async function fetchLayerData({
|
|
|
277
289
|
format,
|
|
278
290
|
formatTiles,
|
|
279
291
|
clientId,
|
|
292
|
+
headers,
|
|
280
293
|
aggregationExp,
|
|
281
294
|
aggregationResLevel,
|
|
282
295
|
queryParameters
|
|
@@ -293,6 +306,7 @@ export async function fetchLayerData({
|
|
|
293
306
|
format,
|
|
294
307
|
formatTiles,
|
|
295
308
|
clientId,
|
|
309
|
+
headers,
|
|
296
310
|
aggregationExp,
|
|
297
311
|
aggregationResLevel,
|
|
298
312
|
queryParameters
|
|
@@ -313,6 +327,7 @@ async function _fetchDataUrl({
|
|
|
313
327
|
format,
|
|
314
328
|
formatTiles,
|
|
315
329
|
clientId,
|
|
330
|
+
headers,
|
|
316
331
|
aggregationExp,
|
|
317
332
|
aggregationResLevel,
|
|
318
333
|
queryParameters
|
|
@@ -347,6 +362,7 @@ async function _fetchDataUrl({
|
|
|
347
362
|
geoColumn,
|
|
348
363
|
columns,
|
|
349
364
|
clientId,
|
|
365
|
+
headers,
|
|
350
366
|
aggregationExp,
|
|
351
367
|
aggregationResLevel,
|
|
352
368
|
queryParameters
|
|
@@ -389,6 +405,7 @@ async function _fetchMapDataset(
|
|
|
389
405
|
accessToken: string,
|
|
390
406
|
credentials: CloudNativeCredentials,
|
|
391
407
|
clientId?: string,
|
|
408
|
+
headers?: Headers,
|
|
392
409
|
queryParameters?: QueryParameters
|
|
393
410
|
) {
|
|
394
411
|
const {
|
|
@@ -411,6 +428,7 @@ async function _fetchMapDataset(
|
|
|
411
428
|
columns,
|
|
412
429
|
format,
|
|
413
430
|
geoColumn,
|
|
431
|
+
headers,
|
|
414
432
|
source,
|
|
415
433
|
type,
|
|
416
434
|
queryParameters
|
|
@@ -457,9 +475,12 @@ async function _fetchTilestats(
|
|
|
457
475
|
async function fillInMapDatasets(
|
|
458
476
|
{datasets, token},
|
|
459
477
|
clientId: string,
|
|
460
|
-
credentials: CloudNativeCredentials
|
|
478
|
+
credentials: CloudNativeCredentials,
|
|
479
|
+
headers?: Headers
|
|
461
480
|
) {
|
|
462
|
-
const promises = datasets.map(dataset =>
|
|
481
|
+
const promises = datasets.map(dataset =>
|
|
482
|
+
_fetchMapDataset(dataset, token, credentials, clientId, headers)
|
|
483
|
+
);
|
|
463
484
|
return await Promise.all(promises);
|
|
464
485
|
}
|
|
465
486
|
|
|
@@ -503,12 +524,14 @@ export async function fetchMap({
|
|
|
503
524
|
cartoMapId,
|
|
504
525
|
clientId,
|
|
505
526
|
credentials,
|
|
527
|
+
headers,
|
|
506
528
|
autoRefresh,
|
|
507
529
|
onNewData
|
|
508
530
|
}: {
|
|
509
531
|
cartoMapId: string;
|
|
510
532
|
clientId: string;
|
|
511
533
|
credentials?: CloudNativeCredentials;
|
|
534
|
+
headers?: Headers;
|
|
512
535
|
autoRefresh?: number;
|
|
513
536
|
onNewData?: (map: any) => void;
|
|
514
537
|
}) {
|
|
@@ -537,7 +560,7 @@ export async function fetchMap({
|
|
|
537
560
|
}
|
|
538
561
|
|
|
539
562
|
const url = `${localCreds.mapsUrl}/public/${cartoMapId}`;
|
|
540
|
-
const map = await requestJson<any>({url, accessToken});
|
|
563
|
+
const map = await requestJson<any>({url, headers, accessToken});
|
|
541
564
|
|
|
542
565
|
// Periodically check if the data has changed. Note that this
|
|
543
566
|
// will not update when a map is published.
|
|
@@ -545,7 +568,7 @@ export async function fetchMap({
|
|
|
545
568
|
if (autoRefresh) {
|
|
546
569
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
547
570
|
const intervalId = setInterval(async () => {
|
|
548
|
-
const changed = await fillInMapDatasets(map, clientId, localCreds);
|
|
571
|
+
const changed = await fillInMapDatasets(map, clientId, localCreds, headers);
|
|
549
572
|
if (onNewData && changed.some(v => v === true)) {
|
|
550
573
|
onNewData(parseMap(map));
|
|
551
574
|
}
|
|
@@ -566,7 +589,7 @@ export async function fetchMap({
|
|
|
566
589
|
});
|
|
567
590
|
|
|
568
591
|
// Mutates map.datasets so that dataset.data contains data
|
|
569
|
-
await fillInMapDatasets(map, clientId, localCreds);
|
|
592
|
+
await fillInMapDatasets(map, clientId, localCreds, headers);
|
|
570
593
|
|
|
571
594
|
// Mutates attributes in visualChannels to contain tile stats
|
|
572
595
|
await fillInTileStats(map, localCreds);
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
Credentials,
|
|
26
26
|
getDefaultCredentials
|
|
27
27
|
} from '../config';
|
|
28
|
-
import {FetchLayerDataResult} from '../api/maps-v3-client';
|
|
28
|
+
import {FetchLayerDataResult, Headers} from '../api/maps-v3-client';
|
|
29
29
|
import {assert} from '../utils';
|
|
30
30
|
|
|
31
31
|
const defaultProps = {
|
|
@@ -61,6 +61,9 @@ const defaultProps = {
|
|
|
61
61
|
// (Array<String>, optional): names of columns to fetch. By default, all columns are fetched.
|
|
62
62
|
columns: {type: 'array', value: null},
|
|
63
63
|
|
|
64
|
+
// (Headers, optional): Custom headers to include in the map instantiation request.
|
|
65
|
+
headers: {type: 'object', value: {}, optional: true},
|
|
66
|
+
|
|
64
67
|
// (String, optional): aggregation SQL expression. Only used for spatial index datasets
|
|
65
68
|
aggregationExp: null,
|
|
66
69
|
|
|
@@ -148,6 +151,9 @@ type _CartoLayerProps = {
|
|
|
148
151
|
|
|
149
152
|
clientId?: string;
|
|
150
153
|
|
|
154
|
+
/** Custom headers to include in the map instantiation request **/
|
|
155
|
+
headers?: Headers;
|
|
156
|
+
|
|
151
157
|
/** Aggregation SQL expression. Only used for spatial index datasets **/
|
|
152
158
|
aggregationExp?: string;
|
|
153
159
|
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from '@deck.gl/geo-layers';
|
|
13
13
|
import {GeoJsonLayer} from '@deck.gl/layers';
|
|
14
14
|
import {geojsonToBinary} from '@loaders.gl/gis';
|
|
15
|
-
import {
|
|
15
|
+
import {KeyValueProperties, Tile, TileReader} from './schema/carto-tile';
|
|
16
16
|
import {TileFormat, TILE_FORMATS} from '../api/maps-api-common';
|
|
17
17
|
import {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
18
18
|
import type {BinaryFeatures} from '@loaders.gl/schema';
|
|
@@ -28,7 +28,7 @@ function parsePbf(buffer: ArrayBuffer): Tile {
|
|
|
28
28
|
return tile;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function unpackProperties(properties:
|
|
31
|
+
function unpackProperties(properties: KeyValueProperties[]) {
|
|
32
32
|
if (!properties || !properties.length) {
|
|
33
33
|
return [];
|
|
34
34
|
}
|
|
@@ -67,7 +67,10 @@ const CartoTileLoader: LoaderWithParser = {
|
|
|
67
67
|
id: 'cartoTile',
|
|
68
68
|
module: 'carto',
|
|
69
69
|
extensions: ['pbf'],
|
|
70
|
-
mimeTypes: [
|
|
70
|
+
mimeTypes: [
|
|
71
|
+
'application/vnd.carto-vector-tile',
|
|
72
|
+
'application/x-protobuf' // Back-compatibility
|
|
73
|
+
],
|
|
71
74
|
category: 'geometry',
|
|
72
75
|
worker: false,
|
|
73
76
|
parse: async (arrayBuffer, options) => parseCartoTile(arrayBuffer, options),
|
|
@@ -12,11 +12,11 @@ const B = [
|
|
|
12
12
|
];
|
|
13
13
|
const S = [0n, 1n, 2n, 4n, 8n, 16n];
|
|
14
14
|
|
|
15
|
-
function indexToBigInt(index: string): bigint {
|
|
15
|
+
export function indexToBigInt(index: string): bigint {
|
|
16
16
|
return BigInt(`0x${index}`);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
function bigIntToIndex(quadbin: bigint): string {
|
|
19
|
+
export function bigIntToIndex(quadbin: bigint): string {
|
|
20
20
|
return quadbin.toString(16);
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import Protobuf from 'pbf';
|
|
2
|
+
import {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
3
|
+
|
|
4
|
+
import {KeyValueProperties} from './carto-tile';
|
|
5
|
+
import {binaryToSpatialjson, Properties, SpatialJson} from './spatialjson-utils';
|
|
6
|
+
import {Tile, TileReader} from './carto-spatial-tile';
|
|
7
|
+
|
|
8
|
+
const CartoSpatialTileLoader: LoaderWithParser = {
|
|
9
|
+
name: 'CARTO Spatial Tile',
|
|
10
|
+
version: '1',
|
|
11
|
+
id: 'cartoSpatialTile',
|
|
12
|
+
module: 'carto',
|
|
13
|
+
extensions: ['pbf'],
|
|
14
|
+
mimeTypes: [
|
|
15
|
+
'application/vnd.carto-spatial-tile',
|
|
16
|
+
'application/x-protobuf' // Back-compatibility
|
|
17
|
+
],
|
|
18
|
+
category: 'geometry',
|
|
19
|
+
worker: false,
|
|
20
|
+
parse: async (arrayBuffer, options) => parseCartoSpatialTile(arrayBuffer, options),
|
|
21
|
+
parseSync: parseCartoSpatialTile,
|
|
22
|
+
options: {}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function parsePbf(buffer: ArrayBuffer): Tile {
|
|
26
|
+
const pbf = new Protobuf(buffer);
|
|
27
|
+
const tile = TileReader.read(pbf);
|
|
28
|
+
return tile;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function unpackProperties(properties: KeyValueProperties[]): Properties[] {
|
|
32
|
+
if (!properties || !properties.length) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
return properties.map(item => {
|
|
36
|
+
const currentRecord: Properties = {};
|
|
37
|
+
item.data.forEach(({key, value}) => {
|
|
38
|
+
currentRecord[key] = value;
|
|
39
|
+
});
|
|
40
|
+
return currentRecord;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function parseCartoSpatialTile(
|
|
45
|
+
arrayBuffer: ArrayBuffer,
|
|
46
|
+
options?: LoaderOptions
|
|
47
|
+
): SpatialJson | null {
|
|
48
|
+
if (!arrayBuffer) return null;
|
|
49
|
+
const tile = parsePbf(arrayBuffer);
|
|
50
|
+
|
|
51
|
+
const {cells} = tile;
|
|
52
|
+
const data = {
|
|
53
|
+
cells: {...cells, properties: unpackProperties(cells.properties)}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return binaryToSpatialjson(data);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default CartoSpatialTileLoader;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {Indices, IndexScheme} from './spatialjson-utils';
|
|
2
|
+
import {
|
|
3
|
+
KeyValueProperties,
|
|
4
|
+
NumericProp,
|
|
5
|
+
NumericPropKeyValueReader,
|
|
6
|
+
PropertiesReader
|
|
7
|
+
} from './carto-tile';
|
|
8
|
+
|
|
9
|
+
// Indices =====================================
|
|
10
|
+
|
|
11
|
+
export class IndicesReader {
|
|
12
|
+
static read(pbf, end?: number): Indices {
|
|
13
|
+
const {value} = pbf.readFields(IndicesReader._readField, {value: []}, end);
|
|
14
|
+
return {value: new BigUint64Array(value)};
|
|
15
|
+
}
|
|
16
|
+
static _readField(this: void, tag: number, obj, pbf) {
|
|
17
|
+
if (tag === 1) readPackedFixed64(pbf, obj.value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Cells =========================================
|
|
22
|
+
|
|
23
|
+
interface Cells {
|
|
24
|
+
indices: Indices;
|
|
25
|
+
properties: KeyValueProperties[];
|
|
26
|
+
numericProps: Record<string, NumericProp>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class CellsReader {
|
|
30
|
+
static read(pbf, end?: number): Cells {
|
|
31
|
+
return pbf.readFields(
|
|
32
|
+
CellsReader._readField,
|
|
33
|
+
{indices: null, properties: [], numericProps: {}},
|
|
34
|
+
end
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
static _readField(this: void, tag: number, obj: Cells, pbf) {
|
|
38
|
+
if (tag === 1) obj.indices = IndicesReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
39
|
+
else if (tag === 2) obj.properties.push(PropertiesReader.read(pbf, pbf.readVarint() + pbf.pos));
|
|
40
|
+
else if (tag === 3) {
|
|
41
|
+
const entry = NumericPropKeyValueReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
42
|
+
obj.numericProps[entry.key] = entry.value;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Tile ========================================
|
|
48
|
+
|
|
49
|
+
// TODO this type is very similar to SpatialBinary, should align
|
|
50
|
+
export interface Tile {
|
|
51
|
+
scheme: IndexScheme;
|
|
52
|
+
cells: Cells;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export class TileReader {
|
|
56
|
+
static read(pbf, end?: number): Tile {
|
|
57
|
+
return pbf.readFields(TileReader._readField, {scheme: 0, cells: null}, end);
|
|
58
|
+
}
|
|
59
|
+
static _readField(this: void, tag: number, obj: Tile, pbf) {
|
|
60
|
+
if (tag === 1) obj.scheme = pbf.readVarint();
|
|
61
|
+
else if (tag === 2) obj.cells = CellsReader.read(pbf, pbf.readVarint() + pbf.pos);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// pbf doesn't support BigInt natively, implement support for packed fixed64 type
|
|
66
|
+
const SHIFT_LEFT_32 = BigInt((1 << 16) * (1 << 16));
|
|
67
|
+
|
|
68
|
+
function readPackedEnd(pbf) {
|
|
69
|
+
return pbf.type === 2 ? pbf.readVarint() + pbf.pos : pbf.pos + 1;
|
|
70
|
+
}
|
|
71
|
+
function readFixed64(pbf) {
|
|
72
|
+
const a = BigInt(pbf.readFixed32());
|
|
73
|
+
const b = BigInt(pbf.readFixed32());
|
|
74
|
+
return a + b * SHIFT_LEFT_32;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function readPackedFixed64(pbf, arr) {
|
|
78
|
+
if (pbf.type !== 2) return arr.push(readFixed64(pbf));
|
|
79
|
+
const end = readPackedEnd(pbf);
|
|
80
|
+
arr = arr || [];
|
|
81
|
+
while (pbf.pos < end) arr.push(readFixed64(pbf));
|
|
82
|
+
return arr;
|
|
83
|
+
}
|
|
@@ -16,15 +16,15 @@ class KeyValueObjectReader {
|
|
|
16
16
|
|
|
17
17
|
// Properties ========================================
|
|
18
18
|
|
|
19
|
-
export interface
|
|
19
|
+
export interface KeyValueProperties {
|
|
20
20
|
data: KeyValueObject[];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
class PropertiesReader {
|
|
23
|
+
export class PropertiesReader {
|
|
24
24
|
static read(pbf, end?: number) {
|
|
25
25
|
return pbf.readFields(PropertiesReader._readField, {data: []}, end);
|
|
26
26
|
}
|
|
27
|
-
static _readField(this: void, tag: number, obj:
|
|
27
|
+
static _readField(this: void, tag: number, obj: KeyValueProperties, pbf) {
|
|
28
28
|
if (tag === 1) obj.data.push(KeyValueObjectReader.read(pbf, pbf.readVarint() + pbf.pos));
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -69,7 +69,7 @@ class IntsReader {
|
|
|
69
69
|
|
|
70
70
|
// NumericProp ========================================
|
|
71
71
|
|
|
72
|
-
interface NumericProp {
|
|
72
|
+
export interface NumericProp {
|
|
73
73
|
value: number[];
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -88,7 +88,7 @@ interface NumbericPropKeyValue {
|
|
|
88
88
|
value: NumericProp;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
class NumericPropKeyValueReader {
|
|
91
|
+
export class NumericPropKeyValueReader {
|
|
92
92
|
static read(pbf, end?: number): NumbericPropKeyValue {
|
|
93
93
|
return pbf.readFields(NumericPropKeyValueReader._readField, {key: '', value: null}, end);
|
|
94
94
|
}
|
|
@@ -104,7 +104,7 @@ interface Points {
|
|
|
104
104
|
positions: Doubles;
|
|
105
105
|
globalFeatureIds: Ints;
|
|
106
106
|
featureIds: Ints;
|
|
107
|
-
properties:
|
|
107
|
+
properties: KeyValueProperties[];
|
|
108
108
|
numericProps: Record<string, NumericProp>;
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {bigIntToIndex} from '../quadbin-utils';
|
|
2
|
+
|
|
3
|
+
export type IndexScheme = 'h3' | 'quadbin';
|
|
4
|
+
type TypedArray = Float32Array | Float64Array;
|
|
5
|
+
|
|
6
|
+
export type Indices = {value: BigUint64Array};
|
|
7
|
+
export type NumericProps = Record<string, {value: number[] | TypedArray}>;
|
|
8
|
+
export type Properties = Record<string, string | number | boolean | null>;
|
|
9
|
+
export type Cells = {
|
|
10
|
+
indices: Indices;
|
|
11
|
+
numericProps: NumericProps;
|
|
12
|
+
properties: Properties[];
|
|
13
|
+
};
|
|
14
|
+
export type SpatialBinary = {scheme?: IndexScheme; cells: Cells};
|
|
15
|
+
export type SpatialJson = {
|
|
16
|
+
id: string;
|
|
17
|
+
properties: Properties;
|
|
18
|
+
}[];
|
|
19
|
+
|
|
20
|
+
export function binaryToSpatialjson(binary: SpatialBinary): SpatialJson {
|
|
21
|
+
const {cells} = binary;
|
|
22
|
+
const count = cells.indices.value.length;
|
|
23
|
+
const spatial: any[] = [];
|
|
24
|
+
for (let i = 0; i < count; i++) {
|
|
25
|
+
const id = bigIntToIndex(cells.indices.value[i]);
|
|
26
|
+
|
|
27
|
+
const properties = {...cells.properties[i]};
|
|
28
|
+
for (const key of Object.keys(cells.numericProps)) {
|
|
29
|
+
properties[key] = cells.numericProps[key].value[i];
|
|
30
|
+
}
|
|
31
|
+
spatial.push({id, properties});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return spatial;
|
|
35
|
+
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {registerLoaders} from '@loaders.gl/core';
|
|
2
|
+
import CartoSpatialTileLoader from './schema/carto-spatial-tile-loader';
|
|
3
|
+
registerLoaders([CartoSpatialTileLoader]);
|
|
4
|
+
|
|
1
5
|
import {PickingInfo} from '@deck.gl/core';
|
|
2
6
|
import {TileLayer, _Tile2DHeader as Tile2DHeader} from '@deck.gl/geo-layers';
|
|
3
7
|
|