@deck.gl/carto 8.8.0-alpha.5 → 8.8.0-beta.2

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 (109) hide show
  1. package/dist/dist.dev.js +13886 -13809
  2. package/dist/es5/api/layer-map.js +7 -5
  3. package/dist/es5/api/layer-map.js.map +1 -1
  4. package/dist/es5/layers/carto-layer.js.map +1 -1
  5. package/dist/es5/layers/carto-tile-layer.js.map +1 -1
  6. package/dist/es5/layers/h3-tile-layer.js +20 -10
  7. package/dist/es5/layers/h3-tile-layer.js.map +1 -1
  8. package/dist/es5/layers/h3-tileset-2d.js +4 -8
  9. package/dist/es5/layers/h3-tileset-2d.js.map +1 -1
  10. package/dist/es5/layers/quadkey-tile-layer.js +23 -12
  11. package/dist/es5/layers/quadkey-tile-layer.js.map +1 -1
  12. package/dist/es5/layers/quadkey-tileset-2d.js.map +1 -1
  13. package/dist/es5/layers/spatial-index-tile-layer.js +3 -0
  14. package/dist/es5/layers/spatial-index-tile-layer.js.map +1 -1
  15. package/dist/esm/api/layer-map.js +8 -6
  16. package/dist/esm/api/layer-map.js.map +1 -1
  17. package/dist/esm/layers/carto-layer.js.map +1 -1
  18. package/dist/esm/layers/carto-tile-layer.js.map +1 -1
  19. package/dist/esm/layers/h3-tile-layer.js +12 -6
  20. package/dist/esm/layers/h3-tile-layer.js.map +1 -1
  21. package/dist/esm/layers/h3-tileset-2d.js +5 -9
  22. package/dist/esm/layers/h3-tileset-2d.js.map +1 -1
  23. package/dist/esm/layers/quadkey-tile-layer.js +15 -8
  24. package/dist/esm/layers/quadkey-tile-layer.js.map +1 -1
  25. package/dist/esm/layers/quadkey-tileset-2d.js.map +1 -1
  26. package/dist/esm/layers/spatial-index-tile-layer.js +3 -0
  27. package/dist/esm/layers/spatial-index-tile-layer.js.map +1 -1
  28. package/dist.min.js +4 -4
  29. package/package.json +10 -9
  30. package/src/api/layer-map.ts +16 -7
  31. package/src/layers/carto-layer.ts +19 -7
  32. package/src/layers/carto-tile-layer.ts +3 -3
  33. package/src/layers/h3-tile-layer.ts +79 -0
  34. package/src/layers/{h3-tileset-2d.js → h3-tileset-2d.ts} +29 -26
  35. package/src/layers/quadkey-tile-layer.ts +69 -0
  36. package/src/layers/{quadkey-tileset-2d.js → quadkey-tileset-2d.ts} +10 -5
  37. package/src/layers/{spatial-index-tile-layer.js → spatial-index-tile-layer.ts} +9 -6
  38. package/typed/api/index.d.ts +4 -0
  39. package/typed/api/index.d.ts.map +1 -0
  40. package/typed/api/index.js +3 -0
  41. package/typed/api/layer-map.d.ts +54 -0
  42. package/typed/api/layer-map.d.ts.map +1 -0
  43. package/typed/api/layer-map.js +264 -0
  44. package/typed/api/maps-api-common.d.ts +65 -0
  45. package/typed/api/maps-api-common.d.ts.map +1 -0
  46. package/typed/api/maps-api-common.js +50 -0
  47. package/typed/api/maps-client.d.ts +18 -0
  48. package/typed/api/maps-client.d.ts.map +1 -0
  49. package/typed/api/maps-client.js +125 -0
  50. package/typed/api/maps-v3-client.d.ts +45 -0
  51. package/typed/api/maps-v3-client.d.ts.map +1 -0
  52. package/typed/api/maps-v3-client.js +304 -0
  53. package/typed/api/parseMap.d.ts +11 -0
  54. package/typed/api/parseMap.d.ts.map +1 -0
  55. package/typed/api/parseMap.js +178 -0
  56. package/typed/basemap.d.ts +10 -0
  57. package/typed/basemap.d.ts.map +1 -0
  58. package/typed/basemap.js +9 -0
  59. package/typed/config.d.ts +26 -0
  60. package/typed/config.d.ts.map +1 -0
  61. package/typed/config.js +35 -0
  62. package/typed/index.d.ts +12 -0
  63. package/typed/index.d.ts.map +1 -0
  64. package/typed/index.js +10 -0
  65. package/typed/layers/carto-layer.d.ts +96 -0
  66. package/typed/layers/carto-layer.d.ts.map +1 -0
  67. package/typed/layers/carto-layer.js +173 -0
  68. package/typed/layers/carto-tile-layer.d.ts +30 -0
  69. package/typed/layers/carto-tile-layer.d.ts.map +1 -0
  70. package/typed/layers/carto-tile-layer.js +105 -0
  71. package/typed/layers/h3-tile-layer.d.ts +21 -0
  72. package/typed/layers/h3-tile-layer.d.ts.map +1 -0
  73. package/typed/layers/h3-tile-layer.js +47 -0
  74. package/typed/layers/h3-tileset-2d.d.ts +18 -0
  75. package/typed/layers/h3-tileset-2d.d.ts.map +1 -0
  76. package/typed/layers/h3-tileset-2d.js +85 -0
  77. package/typed/layers/quadkey-tile-layer.d.ts +21 -0
  78. package/typed/layers/quadkey-tile-layer.d.ts.map +1 -0
  79. package/typed/layers/quadkey-tile-layer.js +42 -0
  80. package/typed/layers/quadkey-tileset-2d.d.ts +15 -0
  81. package/typed/layers/quadkey-tileset-2d.d.ts.map +1 -0
  82. package/typed/layers/quadkey-tileset-2d.js +36 -0
  83. package/typed/layers/schema/carto-tile.d.ts +44 -0
  84. package/typed/layers/schema/carto-tile.d.ts.map +1 -0
  85. package/typed/layers/schema/carto-tile.js +161 -0
  86. package/typed/layers/spatial-index-tile-layer.d.ts +12 -0
  87. package/typed/layers/spatial-index-tile-layer.d.ts.map +1 -0
  88. package/typed/layers/spatial-index-tile-layer.js +40 -0
  89. package/typed/package.json +6 -0
  90. package/typed/style/color-bins-style.d.ts +9 -0
  91. package/typed/style/color-bins-style.d.ts.map +1 -0
  92. package/typed/style/color-bins-style.js +12 -0
  93. package/typed/style/color-categories-style.d.ts +10 -0
  94. package/typed/style/color-categories-style.d.ts.map +1 -0
  95. package/typed/style/color-categories-style.js +16 -0
  96. package/typed/style/color-continuous-style.d.ts +9 -0
  97. package/typed/style/color-continuous-style.d.ts.map +1 -0
  98. package/typed/style/color-continuous-style.js +12 -0
  99. package/typed/style/palette.d.ts +7 -0
  100. package/typed/style/palette.d.ts.map +1 -0
  101. package/typed/style/palette.js +62 -0
  102. package/typed/style/utils.d.ts +8 -0
  103. package/typed/style/utils.d.ts.map +1 -0
  104. package/typed/style/utils.js +15 -0
  105. package/typed/utils.d.ts +2 -0
  106. package/typed/utils.d.ts.map +1 -0
  107. package/typed/utils.js +4 -0
  108. package/src/layers/h3-tile-layer.js +0 -52
  109. package/src/layers/quadkey-tile-layer.js +0 -47
@@ -0,0 +1,96 @@
1
+ import { CompositeLayer, Layer, CompositeLayerProps, LayerProps, ChangeFlags } from '@deck.gl/core/typed';
2
+ import { Format, MapType, TileFormat } from '../api/maps-api-common';
3
+ import { Credentials } from '../config';
4
+ /** All properties supported by CartoLayer. */
5
+ export declare type CartoLayerProps<DataT = any> = _CartoLayerProps & CompositeLayerProps<DataT>;
6
+ /** Properties added by CartoLayer. */
7
+ declare type _CartoLayerProps = {
8
+ /**
9
+ * Either a SQL query or a name of dataset/tileset.
10
+ */
11
+ data: string;
12
+ /**
13
+ * Data type.
14
+ *
15
+ * Possible values are:
16
+ * * `MAP_TYPES.QUERY`, if data is a SQL query.
17
+ * * `MAP_TYPES.TILESET`, if data is a tileset name.
18
+ * * `MAP_TYPES.TABLE`, if data is a dataset name. Only supported with API v3.
19
+ */
20
+ type: MapType;
21
+ /**
22
+ * Name of the connection registered in the CARTO workspace.
23
+ *
24
+ * Required when apiVersion is `API_VERSIONS.V3`.
25
+ */
26
+ connection?: string;
27
+ /**
28
+ * Use to override the default data format.
29
+ *
30
+ * Only supported when apiVersion is `API_VERSIONS.V3`.
31
+ *
32
+ * Possible values are: `FORMATS.GEOJSON`, `FORMATS.JSON` and `FORMATS.TILEJSON`.
33
+ */
34
+ format?: Format;
35
+ /**
36
+ * Use to override the default tile data format.
37
+ *
38
+ * Only supported when apiVersion is `API_VERSIONS.V3` and format is `FORMATS.TILEJSON`.
39
+ *
40
+ * Possible values are: `TILE_FORMATS.BINARY`, `TILE_FORMATS.GEOJSON` and `TILE_FORMATS.MVT`.
41
+ */
42
+ formatTiles?: TileFormat;
43
+ /**
44
+ * Name of the geo_column in the CARTO platform.
45
+ *
46
+ * Use this override the default column (`'geom'`), from which the geometry information should be fetched.
47
+ *
48
+ * Only supported when apiVersion is `API_VERSIONS.V3` and type is `MAP_TYPES.TABLE`.
49
+ */
50
+ geoColumn?: string;
51
+ /**
52
+ * Names of columns to fetch.
53
+ *
54
+ * By default, all columns are fetched
55
+ *
56
+ * Only supported when apiVersion is `API_VERSIONS.V3` and type is `MAP_TYPES.TABLE`.
57
+ */
58
+ columns?: string[];
59
+ /**
60
+ * A string pointing to a unique attribute at the result of the query.
61
+ *
62
+ * A unique attribute is needed for highlighting with vector tiles when a feature is split across two or more tiles.
63
+ */
64
+ uniqueIdProperty?: string;
65
+ /**
66
+ * Optional. Overrides the configuration to connect with CARTO.
67
+ *
68
+ * @see Credentials
69
+ */
70
+ credentials?: Credentials;
71
+ /**
72
+ * Called when the request to the CARTO Maps API failed.
73
+ *
74
+ * By default the Error is thrown.
75
+ */
76
+ onDataError?: (err: unknown) => void;
77
+ clientId?: string;
78
+ };
79
+ export default class CartoLayer<ExtraProps = {}> extends CompositeLayer<Required<_CartoLayerProps> & ExtraProps> {
80
+ static layerName: string;
81
+ static defaultProps: any;
82
+ initializeState(): void;
83
+ get isLoaded(): boolean;
84
+ _checkProps(props: CartoLayerProps): void;
85
+ updateState({ props, oldProps, changeFlags }: {
86
+ props: CartoLayerProps;
87
+ oldProps: CartoLayerProps;
88
+ context: any;
89
+ changeFlags: ChangeFlags;
90
+ }): void;
91
+ _updateData(): Promise<void>;
92
+ _getSubLayerAndProps(): [any, LayerProps];
93
+ renderLayers(): Layer | null;
94
+ }
95
+ export {};
96
+ //# sourceMappingURL=carto-layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"carto-layer.d.ts","sourceRoot":"","sources":["../../src/layers/carto-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,EAEL,mBAAmB,EACnB,UAAU,EACV,WAAW,EACZ,MAAM,eAAe,CAAC;AAOvB,OAAO,EAEL,MAAM,EAGN,OAAO,EAEP,UAAU,EAEX,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAGL,WAAW,EAEZ,MAAM,WAAW,CAAC;AA4CnB,8CAA8C;AAC9C,oBAAY,eAAe,CAAC,KAAK,GAAG,GAAG,IAAI,gBAAgB,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;AAEzF,sCAAsC;AACtC,aAAK,gBAAgB,GAAG;IACtB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;OAOG;IACH,IAAI,EAAE,OAAO,CAAC;IAEd;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,UAAU,CAAC;IAEzB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IAErC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,UAAU,CAAC,UAAU,GAAG,EAAE,CAAE,SAAQ,cAAc,CACrE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,UAAU,CACxC;IACC,MAAM,CAAC,SAAS,SAAgB;IAChC,MAAM,CAAC,YAAY,MAAuB;IAE1C,eAAe,IAAI,IAAI;IAOvB,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,WAAW,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAuCzC,WAAW,CAAC,EACV,KAAK,EACL,QAAQ,EACR,WAAW,EACZ,EAAE;QACD,KAAK,EAAE,eAAe,CAAC;QACvB,QAAQ,EAAE,eAAe,CAAC;QAC1B,OAAO,EAAE,GAAG,CAAC;QACb,WAAW,EAAE,WAAW,CAAC;KAC1B,GAAG,IAAI;IAmBF,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAqClC,oBAAoB,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC;IAqCzC,YAAY,IAAI,KAAK,GAAG,IAAI;CAqB7B"}
@@ -0,0 +1,173 @@
1
+ import { CompositeLayer, log } from '@deck.gl/core';
2
+ import CartoTileLayer from './carto-tile-layer';
3
+ import H3TileLayer from './h3-tile-layer';
4
+ import QuadkeyTileLayer from './quadkey-tile-layer';
5
+ import { MVTLayer } from '@deck.gl/geo-layers';
6
+ import { GeoJsonLayer } from '@deck.gl/layers';
7
+ import { fetchLayerData, getDataV2, API_VERSIONS } from '../api';
8
+ import { COLUMNS_SUPPORT, FORMATS, GEO_COLUMN_SUPPORT, MAP_TYPES, TILE_FORMATS } from '../api/maps-api-common';
9
+ import { getDefaultCredentials } from '../config';
10
+ import { assert } from '../utils';
11
+ const defaultProps = {
12
+ // (String, required): data resource to load. table name, sql query or tileset name.
13
+ data: null,
14
+ // (Enum (MAP_TYPES), required)
15
+ type: null,
16
+ onDataLoad: { type: 'function', value: data => { }, compare: false },
17
+ onDataError: { type: 'function', value: null, compare: false, optional: true },
18
+ uniqueIdProperty: 'cartodb_id',
19
+ // override carto credentials for the layer, set to null to read from default
20
+ credentials: null,
21
+ /*********************/
22
+ /* API v3 PARAMETERS */
23
+ /**********************/
24
+ // (String, required): connection name at CARTO platform
25
+ connection: null,
26
+ // (String, optional): format of data
27
+ format: null,
28
+ // (String, optional): force format of data for tiles
29
+ formatTiles: null,
30
+ // (String, optional): clientId identifier used for internal tracing, place here a string to identify the client who is doing the request.
31
+ clientId: null,
32
+ // (String, optional): name of the `geo_column` in the CARTO platform. Use this override the default column ('geom'), from which the geometry information should be fetched.
33
+ geoColumn: null,
34
+ // (Array<String>, optional): names of columns to fetch. By default, all columns are fetched.
35
+ columns: { type: 'array', value: null },
36
+ // (String, optional): aggregration SQL expression. Only used for spatial index datasets
37
+ aggregationExp: null,
38
+ // (Number, optional): aggregration resolution level. Only used for spatial index datasets, defaults to 6 for quadkeys, 4 for h3
39
+ aggregationResLevel: null
40
+ };
41
+ export default class CartoLayer extends CompositeLayer {
42
+ initializeState() {
43
+ this.state = {
44
+ data: null,
45
+ apiVersion: null
46
+ };
47
+ }
48
+ get isLoaded() {
49
+ return this.getSubLayers().length > 0 && super.isLoaded;
50
+ }
51
+ _checkProps(props) {
52
+ const { type, credentials, connection, geoColumn, columns } = props;
53
+ const localCreds = { ...getDefaultCredentials(), ...credentials };
54
+ const { apiVersion } = localCreds;
55
+ log.assert(Object.values(API_VERSIONS).includes(apiVersion), `Invalid apiVersion ${apiVersion}. Use API_VERSIONS enum.`);
56
+ if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
57
+ log.assert(type === MAP_TYPES.QUERY || type === MAP_TYPES.TILESET, `Invalid type ${type}. Use type MAP_TYPES.QUERY or MAP_TYPES.TILESET for apiVersion ${apiVersion}`);
58
+ log.assert(!connection, `Connection prop is not supported for apiVersion ${apiVersion}`);
59
+ log.assert(!geoColumn, `geoColumn prop is not supported for apiVersion ${apiVersion}`);
60
+ log.assert(!columns, `columns prop is not supported for apiVersion ${apiVersion}`);
61
+ }
62
+ else if (apiVersion === API_VERSIONS.V3) {
63
+ log.assert(connection, 'Missing mandatory connection parameter');
64
+ log.assert(Object.values(MAP_TYPES).includes(type), `Invalid type ${type}. Use MAP_TYPES enum.`);
65
+ if (!COLUMNS_SUPPORT.includes(type)) {
66
+ log.assert(!columns, `columns prop is only supported for types: ${COLUMNS_SUPPORT.join()}`);
67
+ }
68
+ if (!GEO_COLUMN_SUPPORT.includes(type)) {
69
+ log.assert(!geoColumn, `geoColumn prop is only supported for types: ${GEO_COLUMN_SUPPORT.join()}`);
70
+ }
71
+ if (columns) {
72
+ log.assert(Array.isArray(columns), 'columns prop must be an Array');
73
+ }
74
+ }
75
+ }
76
+ updateState({ props, oldProps, changeFlags }) {
77
+ this._checkProps(props);
78
+ const shouldUpdateData = changeFlags.dataChanged ||
79
+ props.connection !== oldProps.connection ||
80
+ props.geoColumn !== oldProps.geoColumn ||
81
+ props.format !== oldProps.format ||
82
+ props.formatTiles !== oldProps.formatTiles ||
83
+ props.type !== oldProps.type ||
84
+ JSON.stringify(props.columns) !== JSON.stringify(oldProps.columns) ||
85
+ JSON.stringify(props.credentials) !== JSON.stringify(oldProps.credentials);
86
+ if (shouldUpdateData) {
87
+ this.setState({ data: null, apiVersion: null });
88
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
89
+ this._updateData();
90
+ }
91
+ }
92
+ async _updateData() {
93
+ try {
94
+ const { type, data: source, clientId, credentials, connection, ...rest } = this.props;
95
+ const localConfig = { ...getDefaultCredentials(), ...credentials };
96
+ const { apiVersion } = localConfig;
97
+ let result;
98
+ if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
99
+ result = {
100
+ data: await getDataV2({ type, source, credentials: credentials })
101
+ };
102
+ }
103
+ else {
104
+ result = await fetchLayerData({
105
+ type,
106
+ source,
107
+ clientId,
108
+ credentials: credentials,
109
+ connection,
110
+ ...rest
111
+ });
112
+ }
113
+ this.setState({ ...result, apiVersion });
114
+ this.props.onDataLoad?.(result.data, {
115
+ propName: 'data',
116
+ layer: this
117
+ });
118
+ }
119
+ catch (err) {
120
+ if (this.props.onDataError) {
121
+ this.props.onDataError(err);
122
+ }
123
+ else {
124
+ throw err;
125
+ }
126
+ }
127
+ }
128
+ _getSubLayerAndProps() {
129
+ assert(this.state);
130
+ const { data, format, apiVersion } = this.state;
131
+ const { uniqueIdProperty } = defaultProps;
132
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
133
+ const { data: _notUsed, ...propsNoData } = this.props;
134
+ // @ts-expect-error 'uniqueIdProperty' is specified more than once, so this usage will be overwritten.
135
+ const props = { uniqueIdProperty, ...propsNoData };
136
+ if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
137
+ return [MVTLayer, props];
138
+ }
139
+ if (format === FORMATS.TILEJSON) {
140
+ /* global URL */
141
+ const tileUrl = new URL(data.tiles[0]);
142
+ props.formatTiles =
143
+ props.formatTiles ||
144
+ tileUrl.searchParams.get('formatTiles') ||
145
+ TILE_FORMATS.MVT;
146
+ if (data.scheme === 'h3') {
147
+ return [H3TileLayer, props];
148
+ }
149
+ if (data.scheme === 'quadkey') {
150
+ return [QuadkeyTileLayer, props];
151
+ }
152
+ return props.formatTiles === TILE_FORMATS.MVT ? [MVTLayer, props] : [CartoTileLayer, props];
153
+ }
154
+ // It's a geojson layer
155
+ return [GeoJsonLayer, props];
156
+ }
157
+ renderLayers() {
158
+ assert(this.state);
159
+ const { data } = this.state;
160
+ if (!data)
161
+ return null;
162
+ const { updateTriggers } = this.props;
163
+ const [layer, props] = this._getSubLayerAndProps();
164
+ // eslint-disable-next-line new-cap
165
+ return new layer(props, this.getSubLayerProps({
166
+ id: `carto-${layer.layerName}`,
167
+ data,
168
+ updateTriggers
169
+ }));
170
+ }
171
+ }
172
+ CartoLayer.layerName = 'CartoLayer';
173
+ CartoLayer.defaultProps = defaultProps;
@@ -0,0 +1,30 @@
1
+ import { DefaultProps } from '@deck.gl/core/typed';
2
+ import { MVTLayer, MVTLayerProps, TileLayer, _Tile2DHeader, _TileLoadProps as TileLoadProps } from '@deck.gl/geo-layers/typed';
3
+ import { GeoJsonLayer } from '@deck.gl/layers/typed';
4
+ import { TileFormat } from '../api/maps-api-common';
5
+ import type { Feature } from 'geojson';
6
+ /** All properties supported by CartoTileLayer. */
7
+ export declare type CartoTileLayerProps<DataT extends Feature = Feature> = _CartoTileLayerProps & MVTLayerProps<DataT>;
8
+ /** Properties added by CartoTileLayer. */
9
+ declare type _CartoTileLayerProps = {
10
+ /** Use to override the default tile data format.
11
+ *
12
+ * Possible values are: `TILE_FORMATS.BINARY`, `TILE_FORMATS.GEOJSON` and `TILE_FORMATS.MVT`.
13
+ *
14
+ * Only supported when `apiVersion` is `API_VERSIONS.V3` and `format` is `FORMATS.TILEJSON`.
15
+ */
16
+ formatTiles?: TileFormat;
17
+ };
18
+ export default class CartoTileLayer<DataT extends Feature = Feature, ExtraProps = {}> extends MVTLayer<DataT, Required<_CartoTileLayerProps> & ExtraProps> {
19
+ static layerName: string;
20
+ static defaultProps: DefaultProps<CartoTileLayerProps<Feature<import("geojson").Geometry, import("geojson").GeoJsonProperties>>>;
21
+ getTileData(tile: TileLoadProps): any;
22
+ renderSubLayers(props: TileLayer['props'] & {
23
+ id: string;
24
+ data: any;
25
+ _offset: number;
26
+ tile: _Tile2DHeader;
27
+ }): GeoJsonLayer | null;
28
+ }
29
+ export {};
30
+ //# sourceMappingURL=carto-tile-layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"carto-tile-layer.d.ts","sourceRoot":"","sources":["../../src/layers/carto-tile-layer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAM,YAAY,EAAC,MAAM,eAAe,CAAC;AAEhD,OAAO,EACL,QAAQ,EACR,aAAa,EACb,SAAS,EAET,aAAa,EACb,cAAc,IAAI,aAAa,EAChC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAC,UAAU,EAAe,MAAM,wBAAwB,CAAC;AAGhE,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAqErC,kDAAkD;AAClD,oBAAY,mBAAmB,CAAC,KAAK,SAAS,OAAO,GAAG,OAAO,IAAI,oBAAoB,GACrF,aAAa,CAAC,KAAK,CAAC,CAAC;AAEvB,0CAA0C;AAC1C,aAAK,oBAAoB,GAAG;IAC1B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,UAAU,CAAC;CAC1B,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,cAAc,CACjC,KAAK,SAAS,OAAO,GAAG,OAAO,EAC/B,UAAU,GAAG,EAAE,CACf,SAAQ,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,oBAAoB,CAAC,GAAG,UAAU,CAAC;IACpE,MAAM,CAAC,SAAS,SAAoB;IACpC,MAAM,CAAC,YAAY,8GAAgB;IAEnC,WAAW,CAAC,IAAI,EAAE,aAAa;IA0B/B,eAAe,CACb,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG;QAC1B,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,GAAG,CAAC;QACV,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,aAAa,CAAC;KACrB,GACA,YAAY,GAAG,IAAI;CAkBvB"}
@@ -0,0 +1,105 @@
1
+ /* global TextDecoder */
2
+ import Protobuf from 'pbf';
3
+ import { log } from '@deck.gl/core';
4
+ import { ClipExtension } from '@deck.gl/extensions';
5
+ import { MVTLayer, _getURLFromTemplate } from '@deck.gl/geo-layers';
6
+ import { GeoJsonLayer } from '@deck.gl/layers';
7
+ import { geojsonToBinary } from '@loaders.gl/gis';
8
+ import { TileReader } from './schema/carto-tile';
9
+ import { TILE_FORMATS } from '../api/maps-api-common';
10
+ function parseJSON(arrayBuffer) {
11
+ return JSON.parse(new TextDecoder().decode(arrayBuffer));
12
+ }
13
+ function parsePbf(buffer) {
14
+ const pbf = new Protobuf(buffer);
15
+ const tile = TileReader.read(pbf);
16
+ return tile;
17
+ }
18
+ function unpackProperties(properties) {
19
+ if (!properties || !properties.length) {
20
+ return [];
21
+ }
22
+ return properties.map(item => {
23
+ const currentRecord = {};
24
+ item.data.forEach(({ key, value }) => {
25
+ currentRecord[key] = value;
26
+ });
27
+ return currentRecord;
28
+ });
29
+ }
30
+ function parseCartoTile(arrayBuffer, options) {
31
+ if (!arrayBuffer)
32
+ return null;
33
+ const formatTiles = options && options.cartoTile && options.cartoTile.formatTiles;
34
+ if (formatTiles === TILE_FORMATS.GEOJSON)
35
+ return geojsonToBinary(parseJSON(arrayBuffer).features);
36
+ const tile = parsePbf(arrayBuffer);
37
+ const { points, lines, polygons } = tile;
38
+ const data = {
39
+ points: { ...points, properties: unpackProperties(points.properties) },
40
+ lines: { ...lines, properties: unpackProperties(lines.properties) },
41
+ polygons: { ...polygons, properties: unpackProperties(polygons.properties) }
42
+ };
43
+ // Note: there is slight, difference in `numericProps` type, however geojson/mvtlayer can cope with this
44
+ return data;
45
+ }
46
+ const defaultTileFormat = TILE_FORMATS.BINARY;
47
+ const CartoTileLoader = {
48
+ name: 'CARTO Tile',
49
+ version: '1',
50
+ id: 'cartoTile',
51
+ module: 'carto',
52
+ extensions: ['pbf'],
53
+ mimeTypes: ['application/x-protobuf'],
54
+ category: 'geometry',
55
+ worker: false,
56
+ parse: async (arrayBuffer, options) => parseCartoTile(arrayBuffer, options),
57
+ parseSync: parseCartoTile,
58
+ options: {
59
+ cartoTile: {
60
+ formatTiles: defaultTileFormat
61
+ }
62
+ }
63
+ };
64
+ const defaultProps = {
65
+ ...MVTLayer.defaultProps,
66
+ formatTiles: defaultTileFormat,
67
+ loaders: [CartoTileLoader]
68
+ };
69
+ export default class CartoTileLayer extends MVTLayer {
70
+ getTileData(tile) {
71
+ const url = _getURLFromTemplate(this.state.data, tile);
72
+ if (!url) {
73
+ return Promise.reject('Invalid URL');
74
+ }
75
+ let loadOptions = this.getLoadOptions();
76
+ const { fetch, formatTiles } = this.props;
77
+ const { signal } = tile;
78
+ loadOptions = {
79
+ ...loadOptions,
80
+ mimeType: 'application/x-protobuf'
81
+ };
82
+ if (formatTiles) {
83
+ log.assert(Object.values(TILE_FORMATS).includes(formatTiles), `Invalid value for formatTiles: ${formatTiles}. Use value from TILE_FORMATS`);
84
+ loadOptions.cartoTile = { formatTiles };
85
+ }
86
+ return fetch(url, { propName: 'data', layer: this, loadOptions, signal });
87
+ }
88
+ renderSubLayers(props) {
89
+ if (props.data === null) {
90
+ return null;
91
+ }
92
+ const tileBbox = props.tile.bbox;
93
+ const { west, south, east, north } = tileBbox;
94
+ const subLayerProps = {
95
+ ...props,
96
+ autoHighlight: false,
97
+ extensions: [new ClipExtension(), ...(props.extensions || [])],
98
+ clipBounds: [west, south, east, north]
99
+ };
100
+ const subLayer = new GeoJsonLayer(subLayerProps);
101
+ return subLayer;
102
+ }
103
+ }
104
+ CartoTileLayer.layerName = 'CartoTileLayer';
105
+ CartoTileLayer.defaultProps = defaultProps;
@@ -0,0 +1,21 @@
1
+ import { CompositeLayer, CompositeLayerProps, Layer, LayersList, UpdateParameters, DefaultProps } from '@deck.gl/core/typed';
2
+ /** All properties supported by H3TileLayer. */
3
+ export declare type H3TileLayerProps<DataT = any> = _H3TileLayerProps<DataT> & CompositeLayerProps<DataT>;
4
+ declare type H3HexagonLayerProps<DataT = any> = Record<string, any>;
5
+ /** Properties added by H3TileLayer. */
6
+ declare type _H3TileLayerProps<DataT> = H3HexagonLayerProps<DataT> & {
7
+ aggregationResLevel?: number;
8
+ };
9
+ export default class H3TileLayer<DataT = any, ExtraPropsT = {}> extends CompositeLayer<ExtraPropsT & Required<_H3TileLayerProps<DataT>>> {
10
+ static layerName: string;
11
+ static defaultProps: DefaultProps<H3HexagonLayerProps<any>>;
12
+ state: {
13
+ tileJSON: any;
14
+ data: any;
15
+ };
16
+ initializeState(): void;
17
+ updateState({ changeFlags }: UpdateParameters<this>): void;
18
+ renderLayers(): Layer | null | LayersList;
19
+ }
20
+ export {};
21
+ //# sourceMappingURL=h3-tile-layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"h3-tile-layer.d.ts","sourceRoot":"","sources":["../../src/layers/h3-tile-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,KAAK,EACL,UAAU,EACV,gBAAgB,EAChB,YAAY,EACb,MAAM,eAAe,CAAC;AAqBvB,+CAA+C;AAC/C,oBAAY,gBAAgB,CAAC,KAAK,GAAG,GAAG,IAAI,iBAAiB,CAAC,KAAK,CAAC,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;AAIlG,aAAK,mBAAmB,CAAC,KAAK,GAAG,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE5D,uCAAuC;AACvC,aAAK,iBAAiB,CAAC,KAAK,IAAI,mBAAmB,CAAC,KAAK,CAAC,GAAG;IAC3D,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,WAAW,CAAC,KAAK,GAAG,GAAG,EAAE,WAAW,GAAG,EAAE,CAAE,SAAQ,cAAc,CACpF,WAAW,GAAG,QAAQ,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CACjD;IACC,MAAM,CAAC,SAAS,SAAiB;IACjC,MAAM,CAAC,YAAY,yCAAgB;IAEnC,KAAK,EAAG;QACN,QAAQ,EAAE,GAAG,CAAC;QACd,IAAI,EAAE,GAAG,CAAC;KACX,CAAC;IAEF,eAAe,IAAI,IAAI;IAIvB,WAAW,CAAC,EAAC,WAAW,EAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,IAAI;IASxD,YAAY,IAAI,KAAK,GAAG,IAAI,GAAG,UAAU;CAc1C"}
@@ -0,0 +1,47 @@
1
+ import { CompositeLayer } from '@deck.gl/core';
2
+ import { H3HexagonLayer } from '@deck.gl/geo-layers';
3
+ import H3Tileset2D from './h3-tileset-2d';
4
+ import SpatialIndexTileLayer from './spatial-index-tile-layer';
5
+ const renderSubLayers = props => {
6
+ const { data } = props;
7
+ const { index } = props.tile;
8
+ if (!data || !data.length)
9
+ return null;
10
+ return new H3HexagonLayer(props, {
11
+ getHexagon: d => d.id,
12
+ centerHexagon: index,
13
+ highPrecision: true
14
+ });
15
+ };
16
+ const defaultProps = {
17
+ aggregationResLevel: 4
18
+ };
19
+ export default class H3TileLayer extends CompositeLayer {
20
+ initializeState() {
21
+ this.setState({ data: null, tileJSON: null });
22
+ }
23
+ updateState({ changeFlags }) {
24
+ if (changeFlags.dataChanged) {
25
+ let { data } = this.props;
26
+ const tileJSON = data;
27
+ data = tileJSON.tiles;
28
+ this.setState({ data, tileJSON });
29
+ }
30
+ }
31
+ renderLayers() {
32
+ const { data, tileJSON } = this.state;
33
+ const maxZoom = parseInt(tileJSON.maxresolution);
34
+ return [
35
+ new SpatialIndexTileLayer(this.props, {
36
+ id: `h3-tile-layer-${this.props.id}`,
37
+ data,
38
+ // @ts-expect-error Tileset2D should be generic over TileIndex
39
+ TilesetClass: H3Tileset2D,
40
+ renderSubLayers,
41
+ maxZoom
42
+ })
43
+ ];
44
+ }
45
+ }
46
+ H3TileLayer.layerName = 'H3TileLayer';
47
+ H3TileLayer.defaultProps = defaultProps;
@@ -0,0 +1,18 @@
1
+ import { _Tileset2D as Tileset2D, GeoBoundingBox } from '@deck.gl/geo-layers/typed';
2
+ export declare type H3TileIndex = {
3
+ i: string;
4
+ };
5
+ export default class H3Tileset2D extends Tileset2D {
6
+ getTileIndices({ viewport, minZoom, maxZoom }: {
7
+ viewport: any;
8
+ minZoom: any;
9
+ maxZoom: any;
10
+ }): H3TileIndex[];
11
+ getTileId({ i }: H3TileIndex): string;
12
+ getTileMetadata({ i }: H3TileIndex): {
13
+ bbox: GeoBoundingBox;
14
+ };
15
+ getTileZoom({ i }: H3TileIndex): number;
16
+ getParentIndex(index: H3TileIndex): H3TileIndex;
17
+ }
18
+ //# sourceMappingURL=h3-tileset-2d.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"h3-tileset-2d.d.ts","sourceRoot":"","sources":["../../src/layers/h3-tileset-2d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,IAAI,SAAS,EAAE,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAG5E,oBAAY,WAAW,GAAG;IAAC,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC;AA8DtC,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,SAAS;IAEhD,cAAc,CAAC,EAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAC;;;;KAAA,GAAG,WAAW,EAAE;IAuB3D,SAAS,CAAC,EAAC,CAAC,EAAC,EAAE,WAAW,GAAG,MAAM;IAKnC,eAAe,CAAC,EAAC,CAAC,EAAC,EAAE,WAAW;;;IAKhC,WAAW,CAAC,EAAC,CAAC,EAAC,EAAE,WAAW,GAAG,MAAM;IAKrC,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW;CAKhD"}
@@ -0,0 +1,85 @@
1
+ import { _Tileset2D as Tileset2D } from '@deck.gl/geo-layers';
2
+ import { polyfill, geoToH3, h3GetResolution, h3ToGeoBoundary, h3ToParent, kRing } from 'h3-js';
3
+ function getHexagonsInBoundingBox({ west, north, east, south }, resolution) {
4
+ if (Math.abs(east - west) > 180) {
5
+ // This is a known issue in h3-js: polyfill does not work correctly
6
+ // when longitude span is larger than 180 degrees.
7
+ return [
8
+ ...new Set(getHexagonsInBoundingBox({ west, north, east: 0, south }, resolution).concat(getHexagonsInBoundingBox({ west: 0, north, east, south }, resolution)))
9
+ ];
10
+ }
11
+ // `polyfill()` fills based on hexagon center, which means tiles vanish
12
+ // prematurely. Get more accurate coverage by oversampling
13
+ const oversample = 2;
14
+ const h3Indices = polyfill([
15
+ [
16
+ [west, north],
17
+ [west, south],
18
+ [east, south],
19
+ [east, north],
20
+ [west, north]
21
+ ]
22
+ ], resolution + oversample, true);
23
+ return oversample ? [...new Set(h3Indices.map(i => h3ToParent(i, resolution)))] : h3Indices;
24
+ }
25
+ function tileToBoundingBox(index) {
26
+ const coordinates = h3ToGeoBoundary(index);
27
+ const latitudes = coordinates.map(c => c[0]);
28
+ const longitudes = coordinates.map(c => c[1]);
29
+ const west = Math.min(...longitudes);
30
+ const south = Math.min(...latitudes);
31
+ const east = Math.max(...longitudes);
32
+ const north = Math.max(...latitudes);
33
+ return { west, south, east, north };
34
+ }
35
+ // Resolution conversion function. Takes a WebMercatorViewport and returns
36
+ // a H3 resolution such that the screen space size of the hexagons is
37
+ // similar
38
+ // Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
39
+ const BIAS = 2;
40
+ function getHexagonResolution(viewport) {
41
+ const hexagonScaleFactor = (2 / 3) * viewport.zoom;
42
+ const latitudeScaleFactor = Math.log(1 / Math.cos((Math.PI * viewport.latitude) / 180));
43
+ // Clip and bias
44
+ return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS));
45
+ }
46
+ export default class H3Tileset2D extends Tileset2D {
47
+ // @ts-expect-error Tileset2D should be generic over TileIndex
48
+ getTileIndices({ viewport, minZoom, maxZoom }) {
49
+ const [east, south, west, north] = viewport.getBounds();
50
+ let z = getHexagonResolution(viewport);
51
+ let indices;
52
+ if (typeof minZoom === 'number' && Number.isFinite(minZoom) && z < minZoom) {
53
+ z = minZoom;
54
+ }
55
+ if (typeof maxZoom === 'number' && Number.isFinite(maxZoom) && z > maxZoom) {
56
+ z = maxZoom;
57
+ // Once we are at max zoom, getHexagonsInBoundingBox doesn't work, simply
58
+ // get a ring centered on the hexagon in the viewport center
59
+ const center = geoToH3(viewport.latitude, viewport.longitude, maxZoom);
60
+ indices = kRing(center, 1);
61
+ }
62
+ else {
63
+ indices = getHexagonsInBoundingBox({ west, north, east, south }, z);
64
+ }
65
+ return indices.map(i => ({ i }));
66
+ }
67
+ // @ts-expect-error Tileset2D should be generic over TileIndex
68
+ getTileId({ i }) {
69
+ return i;
70
+ }
71
+ // @ts-expect-error Tileset2D should be generic over TileIndex
72
+ getTileMetadata({ i }) {
73
+ return { bbox: tileToBoundingBox(i) };
74
+ }
75
+ // @ts-expect-error Tileset2D should be generic over TileIndex
76
+ getTileZoom({ i }) {
77
+ return h3GetResolution(i);
78
+ }
79
+ // @ts-expect-error Tileset2D should be generic over TileIndex
80
+ getParentIndex(index) {
81
+ const resolution = h3GetResolution(index.i);
82
+ const i = h3ToParent(index.i, resolution - 1);
83
+ return { i };
84
+ }
85
+ }
@@ -0,0 +1,21 @@
1
+ import { CompositeLayer, CompositeLayerProps, Layer, LayersList, UpdateParameters, DefaultProps } from '@deck.gl/core/typed';
2
+ import { QuadkeyLayerProps } from '@deck.gl/geo-layers/typed';
3
+ /** All properties supported by QuadkeyTileLayer. */
4
+ export declare type QuadkeyTileLayerProps<DataT = any> = _QuadkeyTileLayerProps<DataT> & CompositeLayerProps<DataT>;
5
+ /** Properties added by QuadkeyTileLayer. */
6
+ declare type _QuadkeyTileLayerProps<DataT> = QuadkeyLayerProps<DataT> & {
7
+ aggregationResLevel?: number;
8
+ };
9
+ export default class QuadkeyTileLayer<DataT = any, ExtraProps = {}> extends CompositeLayer<ExtraProps & Required<_QuadkeyTileLayerProps<DataT>>> {
10
+ static layerName: string;
11
+ static defaultProps: DefaultProps<QuadkeyTileLayerProps<any>>;
12
+ state: {
13
+ tileJSON: any;
14
+ data: any;
15
+ };
16
+ initializeState(): void;
17
+ updateState({ changeFlags }: UpdateParameters<this>): void;
18
+ renderLayers(): Layer | null | LayersList;
19
+ }
20
+ export {};
21
+ //# sourceMappingURL=quadkey-tile-layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quadkey-tile-layer.d.ts","sourceRoot":"","sources":["../../src/layers/quadkey-tile-layer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,KAAK,EACL,UAAU,EACV,gBAAgB,EAChB,YAAY,EACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAe,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAcpE,oDAAoD;AACpD,oBAAY,qBAAqB,CAAC,KAAK,GAAG,GAAG,IAAI,sBAAsB,CAAC,KAAK,CAAC,GAC5E,mBAAmB,CAAC,KAAK,CAAC,CAAC;AAE7B,4CAA4C;AAC5C,aAAK,sBAAsB,CAAC,KAAK,IAAI,iBAAiB,CAAC,KAAK,CAAC,GAAG;IAC9D,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,gBAAgB,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,GAAG,EAAE,CAAE,SAAQ,cAAc,CACxF,UAAU,GAAG,QAAQ,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,CACrD;IACC,MAAM,CAAC,SAAS,SAAsB;IACtC,MAAM,CAAC,YAAY,2CAAgB;IAEnC,KAAK,EAAG;QACN,QAAQ,EAAE,GAAG,CAAC;QACd,IAAI,EAAE,GAAG,CAAC;KACX,CAAC;IACF,eAAe,IAAI,IAAI;IAIvB,WAAW,CAAC,EAAC,WAAW,EAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,IAAI;IASxD,YAAY,IAAI,KAAK,GAAG,IAAI,GAAG,UAAU;CAc1C"}
@@ -0,0 +1,42 @@
1
+ import { CompositeLayer } from '@deck.gl/core';
2
+ import { QuadkeyLayer } from '@deck.gl/geo-layers';
3
+ import QuadkeyTileset2D from './quadkey-tileset-2d';
4
+ import SpatialIndexTileLayer from './spatial-index-tile-layer';
5
+ const renderSubLayers = props => {
6
+ const { data } = props;
7
+ if (!data || !data.length)
8
+ return null;
9
+ return new QuadkeyLayer(props, { getQuadkey: d => d.id });
10
+ };
11
+ const defaultProps = {
12
+ aggregationResLevel: 6
13
+ };
14
+ export default class QuadkeyTileLayer extends CompositeLayer {
15
+ initializeState() {
16
+ this.setState({ data: null, tileJSON: null });
17
+ }
18
+ updateState({ changeFlags }) {
19
+ if (changeFlags.dataChanged) {
20
+ let { data } = this.props;
21
+ const tileJSON = data;
22
+ data = tileJSON.tiles;
23
+ this.setState({ data, tileJSON });
24
+ }
25
+ }
26
+ renderLayers() {
27
+ const { data, tileJSON } = this.state;
28
+ const maxZoom = parseInt(tileJSON?.maxresolution);
29
+ return [
30
+ new SpatialIndexTileLayer(this.props, {
31
+ id: `quadkey-tile-layer-${this.props.id}`,
32
+ data,
33
+ // TODO: Tileset2D should be generic over TileIndex type
34
+ TilesetClass: QuadkeyTileset2D,
35
+ renderSubLayers,
36
+ maxZoom
37
+ })
38
+ ];
39
+ }
40
+ }
41
+ QuadkeyTileLayer.layerName = 'QuadkeyTileLayer';
42
+ QuadkeyTileLayer.defaultProps = defaultProps;