@deck.gl/carto 8.9.4 → 8.9.5

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 (113) hide show
  1. package/dist/dist.dev.js +359 -174
  2. package/dist/es5/api/layer-map.js +44 -44
  3. package/dist/es5/api/layer-map.js.map +1 -1
  4. package/dist/es5/api/maps-v3-client.js +22 -4
  5. package/dist/es5/api/maps-v3-client.js.map +1 -1
  6. package/dist/es5/api/parseMap.js +64 -48
  7. package/dist/es5/api/parseMap.js.map +1 -1
  8. package/dist/es5/index.js +8 -0
  9. package/dist/es5/index.js.map +1 -1
  10. package/dist/es5/layers/point-label-layer.js +268 -0
  11. package/dist/es5/layers/point-label-layer.js.map +1 -0
  12. package/dist/es5/layers/schema/carto-spatial-tile-loader.js +1 -9
  13. package/dist/es5/layers/schema/carto-spatial-tile-loader.js.map +1 -1
  14. package/dist/es5/layers/schema/carto-spatial-tile.js +5 -31
  15. package/dist/es5/layers/schema/carto-spatial-tile.js.map +1 -1
  16. package/dist/es5/layers/schema/carto-tile.js +12 -6
  17. package/dist/es5/layers/schema/carto-tile.js.map +1 -1
  18. package/dist/es5/layers/schema/carto-vector-tile-loader.js +1 -21
  19. package/dist/es5/layers/schema/carto-vector-tile-loader.js.map +1 -1
  20. package/dist/es5/layers/schema/fast-pbf.js +22 -0
  21. package/dist/es5/layers/schema/fast-pbf.js.map +1 -0
  22. package/dist/es5/layers/schema/tile-loader-utils.js +0 -17
  23. package/dist/es5/layers/schema/tile-loader-utils.js.map +1 -1
  24. package/dist/es5/layers/spatial-index-tile-layer.js +19 -1
  25. package/dist/es5/layers/spatial-index-tile-layer.js.map +1 -1
  26. package/dist/esm/api/layer-map.js +29 -21
  27. package/dist/esm/api/layer-map.js.map +1 -1
  28. package/dist/esm/api/maps-v3-client.js +12 -1
  29. package/dist/esm/api/maps-v3-client.js.map +1 -1
  30. package/dist/esm/api/parseMap.js +59 -44
  31. package/dist/esm/api/parseMap.js.map +1 -1
  32. package/dist/esm/index.js +1 -0
  33. package/dist/esm/index.js.map +1 -1
  34. package/dist/esm/layers/point-label-layer.js +198 -0
  35. package/dist/esm/layers/point-label-layer.js.map +1 -0
  36. package/dist/esm/layers/schema/carto-spatial-tile-loader.js +2 -4
  37. package/dist/esm/layers/schema/carto-spatial-tile-loader.js.map +1 -1
  38. package/dist/esm/layers/schema/carto-spatial-tile.js +3 -28
  39. package/dist/esm/layers/schema/carto-spatial-tile.js.map +1 -1
  40. package/dist/esm/layers/schema/carto-tile.js +12 -6
  41. package/dist/esm/layers/schema/carto-tile.js.map +1 -1
  42. package/dist/esm/layers/schema/carto-vector-tile-loader.js +2 -18
  43. package/dist/esm/layers/schema/carto-vector-tile-loader.js.map +1 -1
  44. package/dist/esm/layers/schema/fast-pbf.js +13 -0
  45. package/dist/esm/layers/schema/fast-pbf.js.map +1 -0
  46. package/dist/esm/layers/schema/tile-loader-utils.js +0 -16
  47. package/dist/esm/layers/schema/tile-loader-utils.js.map +1 -1
  48. package/dist/esm/layers/spatial-index-tile-layer.js +21 -1
  49. package/dist/esm/layers/spatial-index-tile-layer.js.map +1 -1
  50. package/dist.min.js +24 -23
  51. package/package.json +2 -2
  52. package/src/api/layer-map.ts +21 -25
  53. package/src/api/maps-v3-client.ts +19 -4
  54. package/src/api/parseMap.ts +67 -44
  55. package/src/api/types.ts +1 -0
  56. package/src/index.ts +1 -0
  57. package/src/layers/point-label-layer.ts +266 -0
  58. package/src/layers/schema/carto-spatial-tile-loader.ts +2 -5
  59. package/src/layers/schema/carto-spatial-tile.ts +5 -30
  60. package/src/layers/schema/carto-tile.ts +11 -12
  61. package/src/layers/schema/carto-vector-tile-loader.ts +2 -9
  62. package/src/layers/schema/fast-pbf.ts +13 -0
  63. package/src/layers/schema/tile-loader-utils.ts +0 -15
  64. package/src/layers/spatial-index-tile-layer.ts +22 -1
  65. package/typed/api/layer-map.d.ts +1 -2
  66. package/typed/api/layer-map.d.ts.map +1 -1
  67. package/typed/api/maps-v3-client.d.ts +4 -1
  68. package/typed/api/maps-v3-client.d.ts.map +1 -1
  69. package/typed/api/parseMap.d.ts +1 -1
  70. package/typed/api/parseMap.d.ts.map +1 -1
  71. package/typed/api/types.d.ts +1 -0
  72. package/typed/api/types.d.ts.map +1 -1
  73. package/typed/index.d.ts +1 -0
  74. package/typed/index.d.ts.map +1 -1
  75. package/typed/layers/point-label-layer.d.ts +56 -0
  76. package/typed/layers/point-label-layer.d.ts.map +1 -0
  77. package/typed/layers/schema/carto-spa-tile.d.ts +57 -0
  78. package/typed/layers/schema/carto-spa-tile.d.ts.map +1 -0
  79. package/typed/layers/schema/carto-spatial-tile-loader.d.ts.map +1 -1
  80. package/typed/layers/schema/carto-spatial-tile.d.ts +2 -2
  81. package/typed/layers/schema/carto-spatial-tile.d.ts.map +1 -1
  82. package/typed/layers/schema/carto-tile.d.ts +2 -9
  83. package/typed/layers/schema/carto-tile.d.ts.map +1 -1
  84. package/typed/layers/schema/carto-vector-tile-loader.d.ts.map +1 -1
  85. package/typed/layers/schema/fast-pbf.d.ts +3 -0
  86. package/typed/layers/schema/fast-pbf.d.ts.map +1 -0
  87. package/typed/layers/schema/tile-loader-utils.d.ts +0 -3
  88. package/typed/layers/schema/tile-loader-utils.d.ts.map +1 -1
  89. package/typed/layers/spatial-index-tile-layer.d.ts +1 -0
  90. package/typed/layers/spatial-index-tile-layer.d.ts.map +1 -1
  91. package/typed/api/index.js +0 -3
  92. package/typed/api/layer-map.js +0 -264
  93. package/typed/api/maps-api-common.js +0 -50
  94. package/typed/api/maps-client.js +0 -125
  95. package/typed/api/maps-v3-client.js +0 -304
  96. package/typed/api/parseMap.js +0 -178
  97. package/typed/basemap.js +0 -9
  98. package/typed/config.js +0 -35
  99. package/typed/index.js +0 -10
  100. package/typed/layers/carto-layer.js +0 -173
  101. package/typed/layers/carto-tile-layer.js +0 -105
  102. package/typed/layers/h3-tile-layer.js +0 -47
  103. package/typed/layers/h3-tileset-2d.js +0 -85
  104. package/typed/layers/quadkey-tile-layer.js +0 -42
  105. package/typed/layers/quadkey-tileset-2d.js +0 -36
  106. package/typed/layers/schema/carto-tile.js +0 -161
  107. package/typed/layers/spatial-index-tile-layer.js +0 -40
  108. package/typed/style/color-bins-style.js +0 -12
  109. package/typed/style/color-categories-style.js +0 -16
  110. package/typed/style/color-continuous-style.js +0 -12
  111. package/typed/style/palette.js +0 -62
  112. package/typed/style/utils.js +0 -15
  113. package/typed/utils.js +0 -4
@@ -1,173 +0,0 @@
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;
@@ -1,105 +0,0 @@
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;
@@ -1,47 +0,0 @@
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;
@@ -1,85 +0,0 @@
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
- }
@@ -1,42 +0,0 @@
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;
@@ -1,36 +0,0 @@
1
- import { _Tileset2D as Tileset2D } from '@deck.gl/geo-layers';
2
- function tileToQuadkey(tile) {
3
- let index = '';
4
- for (let z = tile.z; z > 0; z--) {
5
- let b = 0;
6
- const mask = 1 << (z - 1);
7
- if ((tile.x & mask) !== 0)
8
- b++;
9
- if ((tile.y & mask) !== 0)
10
- b += 2;
11
- index += b.toString();
12
- }
13
- return { i: index };
14
- }
15
- export default class QuadkeyTileset2D extends Tileset2D {
16
- // @ts-expect-error for spatial indices, TileSet2d should be parametrized by TileIndexT
17
- getTileIndices(opts) {
18
- return super.getTileIndices(opts).map(tileToQuadkey);
19
- }
20
- // @ts-expect-error TileIndex must be generic
21
- getTileId({ i }) {
22
- return i;
23
- }
24
- getTileMetadata() {
25
- return {};
26
- }
27
- // @ts-expect-error TileIndex must be generic
28
- getTileZoom({ i }) {
29
- return i.length;
30
- }
31
- // @ts-expect-error TileIndex must be generic
32
- getParentIndex(index) {
33
- const i = index.i.slice(0, -1);
34
- return { i };
35
- }
36
- }
@@ -1,161 +0,0 @@
1
- class KeyValueObjectReader {
2
- static read(pbf, end) {
3
- return pbf.readFields(KeyValueObjectReader._readField, { key: '', value: '' }, end);
4
- }
5
- static _readField(tag, obj, pbf) {
6
- if (tag === 1)
7
- obj.key = pbf.readString();
8
- else if (tag === 2)
9
- obj.value = pbf.readString();
10
- }
11
- }
12
- class PropertiesReader {
13
- static read(pbf, end) {
14
- return pbf.readFields(PropertiesReader._readField, { data: [] }, end);
15
- }
16
- static _readField(tag, obj, pbf) {
17
- if (tag === 1)
18
- obj.data.push(KeyValueObjectReader.read(pbf, pbf.readVarint() + pbf.pos));
19
- }
20
- }
21
- class DoublesReader {
22
- static read(pbf, end) {
23
- // TODO perhaps we can do better and directly map from the source
24
- // ArrayBuffer using ArrayBuffer.slice()
25
- const { value, size } = pbf.readFields(DoublesReader._readField, { value: [], size: 0 }, end);
26
- return { value: new Float32Array(value), size };
27
- }
28
- static _readField(tag, obj, pbf) {
29
- if (tag === 1)
30
- pbf.readPackedDouble(obj.value);
31
- else if (tag === 2)
32
- obj.size = pbf.readVarint(true);
33
- }
34
- }
35
- class IntsReader {
36
- static read(pbf, end) {
37
- const { value, size } = pbf.readFields(IntsReader._readField, { value: [], size: 0 }, end);
38
- return { value: new Uint32Array(value), size };
39
- }
40
- static _readField(tag, obj, pbf) {
41
- if (tag === 1)
42
- pbf.readPackedVarint(obj.value);
43
- else if (tag === 2)
44
- obj.size = pbf.readVarint(true);
45
- }
46
- }
47
- class NumericPropReader {
48
- static read(pbf, end) {
49
- return pbf.readFields(NumericPropReader._readField, { value: [] }, end);
50
- }
51
- static _readField(tag, obj, pbf) {
52
- if (tag === 1)
53
- pbf.readPackedDouble(obj.value);
54
- }
55
- }
56
- class NumericPropKeyValueReader {
57
- static read(pbf, end) {
58
- return pbf.readFields(NumericPropKeyValueReader._readField, { key: '', value: null }, end);
59
- }
60
- static _readField(tag, obj, pbf) {
61
- if (tag === 1)
62
- obj.key = pbf.readString();
63
- else if (tag === 2)
64
- obj.value = NumericPropReader.read(pbf, pbf.readVarint() + pbf.pos);
65
- }
66
- }
67
- class PointsReader {
68
- static read(pbf, end) {
69
- return pbf.readFields(PointsReader._readField, { positions: null, globalFeatureIds: null, featureIds: null, properties: [], numericProps: {} }, end);
70
- }
71
- static _readField(tag, obj, pbf) {
72
- if (tag === 1)
73
- obj.positions = DoublesReader.read(pbf, pbf.readVarint() + pbf.pos);
74
- else if (tag === 2)
75
- obj.globalFeatureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
76
- else if (tag === 3)
77
- obj.featureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
78
- else if (tag === 4)
79
- obj.properties.push(PropertiesReader.read(pbf, pbf.readVarint() + pbf.pos));
80
- else if (tag === 5) {
81
- const entry = NumericPropKeyValueReader.read(pbf, pbf.readVarint() + pbf.pos);
82
- obj.numericProps[entry.key] = entry.value;
83
- }
84
- }
85
- }
86
- // Lines ========================================
87
- class LinesReader {
88
- static read(pbf, end) {
89
- return pbf.readFields(LinesReader._readField, {
90
- positions: null,
91
- pathIndices: null,
92
- globalFeatureIds: null,
93
- featureIds: null,
94
- properties: [],
95
- numericProps: {}
96
- }, end);
97
- }
98
- static _readField(tag, obj, pbf) {
99
- if (tag === 1)
100
- obj.positions = DoublesReader.read(pbf, pbf.readVarint() + pbf.pos);
101
- else if (tag === 2)
102
- obj.pathIndices = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
103
- else if (tag === 3)
104
- obj.globalFeatureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
105
- else if (tag === 4)
106
- obj.featureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
107
- else if (tag === 5)
108
- obj.properties.push(PropertiesReader.read(pbf, pbf.readVarint() + pbf.pos));
109
- else if (tag === 6) {
110
- const entry = NumericPropKeyValueReader.read(pbf, pbf.readVarint() + pbf.pos);
111
- obj.numericProps[entry.key] = entry.value;
112
- }
113
- }
114
- }
115
- class PolygonsReader {
116
- static read(pbf, end) {
117
- return pbf.readFields(PolygonsReader._readField, {
118
- positions: null,
119
- polygonIndices: null,
120
- globalFeatureIds: null,
121
- featureIds: null,
122
- primitivePolygonIndices: null,
123
- triangles: null,
124
- properties: [],
125
- numericProps: {}
126
- }, end);
127
- }
128
- static _readField(tag, obj, pbf) {
129
- if (tag === 1)
130
- obj.positions = DoublesReader.read(pbf, pbf.readVarint() + pbf.pos);
131
- else if (tag === 2)
132
- obj.polygonIndices = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
133
- else if (tag === 3)
134
- obj.globalFeatureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
135
- else if (tag === 4)
136
- obj.featureIds = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
137
- else if (tag === 5)
138
- obj.primitivePolygonIndices = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
139
- else if (tag === 6)
140
- obj.triangles = IntsReader.read(pbf, pbf.readVarint() + pbf.pos);
141
- else if (tag === 7)
142
- obj.properties.push(PropertiesReader.read(pbf, pbf.readVarint() + pbf.pos));
143
- else if (tag === 8) {
144
- const entry = NumericPropKeyValueReader.read(pbf, pbf.readVarint() + pbf.pos);
145
- obj.numericProps[entry.key] = entry.value;
146
- }
147
- }
148
- }
149
- export class TileReader {
150
- static read(pbf, end) {
151
- return pbf.readFields(TileReader._readField, { points: null, lines: null, polygons: null }, end);
152
- }
153
- static _readField(tag, obj, pbf) {
154
- if (tag === 1)
155
- obj.points = PointsReader.read(pbf, pbf.readVarint() + pbf.pos);
156
- else if (tag === 2)
157
- obj.lines = LinesReader.read(pbf, pbf.readVarint() + pbf.pos);
158
- else if (tag === 3)
159
- obj.polygons = PolygonsReader.read(pbf, pbf.readVarint() + pbf.pos);
160
- }
161
- }