@deck.gl/geo-layers 8.8.23 → 8.8.24

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 (55) hide show
  1. package/dist/dist.dev.js +1661 -1648
  2. package/dist/es5/tile-layer/tileset-2d.js +122 -102
  3. package/dist/es5/tile-layer/tileset-2d.js.map +1 -1
  4. package/dist/es5/tile-layer/utils.js +15 -16
  5. package/dist/es5/tile-layer/utils.js.map +1 -1
  6. package/dist/esm/tile-layer/tileset-2d.js +17 -6
  7. package/dist/esm/tile-layer/tileset-2d.js.map +1 -1
  8. package/dist/esm/tile-layer/utils.js +14 -18
  9. package/dist/esm/tile-layer/utils.js.map +1 -1
  10. package/dist.min.js +1 -1
  11. package/package.json +2 -2
  12. package/src/tile-layer/tileset-2d.ts +15 -7
  13. package/src/tile-layer/utils.ts +20 -8
  14. package/typed/geo-cell-layer/GeoCellLayer.js +49 -0
  15. package/typed/great-circle-layer/great-circle-layer.js +29 -0
  16. package/typed/h3-layers/h3-cluster-layer.js +33 -0
  17. package/typed/h3-layers/h3-hexagon-layer.js +251 -0
  18. package/typed/index.js +33 -0
  19. package/typed/mesh-layer/mesh-layer-fragment.glsl.js +55 -0
  20. package/typed/mesh-layer/mesh-layer-vertex.glsl.js +80 -0
  21. package/typed/mesh-layer/mesh-layer.js +110 -0
  22. package/typed/mvt-layer/coordinate-transform.js +41 -0
  23. package/typed/mvt-layer/find-index-binary.js +96 -0
  24. package/typed/mvt-layer/mvt-layer.js +297 -0
  25. package/typed/quadkey-layer/quadkey-layer.js +18 -0
  26. package/typed/quadkey-layer/quadkey-utils.js +26 -0
  27. package/typed/s2-layer/s2-geometry.js +123 -0
  28. package/typed/s2-layer/s2-layer.js +37 -0
  29. package/typed/s2-layer/s2-utils.js +88 -0
  30. package/typed/terrain-layer/terrain-layer.js +226 -0
  31. package/typed/tile-3d-layer/tile-3d-layer.js +294 -0
  32. package/typed/tile-layer/tile-2d-header.js +113 -0
  33. package/typed/tile-layer/tile-2d-traversal.js +181 -0
  34. package/typed/tile-layer/tile-layer.js +192 -0
  35. package/typed/tile-layer/tileset-2d.d.ts.map +1 -1
  36. package/typed/tile-layer/tileset-2d.js +399 -0
  37. package/typed/tile-layer/types.js +1 -0
  38. package/typed/tile-layer/utils.d.ts +1 -1
  39. package/typed/tile-layer/utils.d.ts.map +1 -1
  40. package/typed/tile-layer/utils.js +197 -0
  41. package/typed/tileset-2d/index.d.ts +6 -0
  42. package/typed/tileset-2d/index.d.ts.map +1 -0
  43. package/typed/tileset-2d/memoize.d.ts +7 -0
  44. package/typed/tileset-2d/memoize.d.ts.map +1 -0
  45. package/typed/tileset-2d/tile-2d-header.d.ts +39 -0
  46. package/typed/tileset-2d/tile-2d-header.d.ts.map +1 -0
  47. package/typed/tileset-2d/tile-2d-traversal.d.ts +4 -0
  48. package/typed/tileset-2d/tile-2d-traversal.d.ts.map +1 -0
  49. package/typed/tileset-2d/tileset-2d.d.ts +121 -0
  50. package/typed/tileset-2d/tileset-2d.d.ts.map +1 -0
  51. package/typed/tileset-2d/types.d.ts +30 -0
  52. package/typed/tileset-2d/types.d.ts.map +1 -0
  53. package/typed/tileset-2d/utils.d.ts +51 -0
  54. package/typed/tileset-2d/utils.d.ts.map +1 -0
  55. package/typed/trips-layer/trips-layer.js +92 -0
@@ -0,0 +1,110 @@
1
+ import { GLTFMaterialParser } from '@luma.gl/experimental';
2
+ import { Model, pbr } from '@luma.gl/core';
3
+ import GL from '@luma.gl/constants';
4
+ import { SimpleMeshLayer } from '@deck.gl/mesh-layers';
5
+ import vs from './mesh-layer-vertex.glsl';
6
+ import fs from './mesh-layer-fragment.glsl';
7
+ function validateGeometryAttributes(attributes) {
8
+ const hasColorAttribute = attributes.COLOR_0 || attributes.colors;
9
+ if (!hasColorAttribute) {
10
+ attributes.colors = { constant: true, value: new Float32Array([1, 1, 1]) };
11
+ }
12
+ }
13
+ const defaultProps = {
14
+ // PBR material object. _lighting must be pbr for this to work
15
+ pbrMaterial: { type: 'object', value: null },
16
+ featureIds: { type: 'array', value: null, optional: true }
17
+ };
18
+ export default class _MeshLayer extends SimpleMeshLayer {
19
+ getShaders() {
20
+ const shaders = super.getShaders();
21
+ const modules = shaders.modules;
22
+ modules.push(pbr);
23
+ return { ...shaders, vs, fs };
24
+ }
25
+ initializeState() {
26
+ const { featureIds } = this.props;
27
+ super.initializeState();
28
+ if (featureIds) {
29
+ this.state.attributeManager.add({
30
+ featureIdsPickingColors: {
31
+ type: GL.UNSIGNED_BYTE,
32
+ size: 3,
33
+ noAlloc: true,
34
+ update: this.calculateFeatureIdsPickingColors
35
+ }
36
+ });
37
+ }
38
+ }
39
+ updateState({ props, oldProps, changeFlags }) {
40
+ super.updateState({ props, oldProps, changeFlags });
41
+ if (props.pbrMaterial !== oldProps.pbrMaterial) {
42
+ this.updatePbrMaterialUniforms(props.pbrMaterial);
43
+ }
44
+ }
45
+ draw(opts) {
46
+ const { featureIds } = this.props;
47
+ if (!this.state.model) {
48
+ return;
49
+ }
50
+ this.state.model.setUniforms({
51
+ // Needed for PBR (TODO: find better way to get it)
52
+ u_Camera: this.state.model.getUniforms().project_uCameraPosition,
53
+ u_pickFeatureIds: Boolean(featureIds)
54
+ });
55
+ super.draw(opts);
56
+ }
57
+ getModel(mesh) {
58
+ const { id, pbrMaterial } = this.props;
59
+ const materialParser = this.parseMaterial(pbrMaterial, mesh);
60
+ const shaders = this.getShaders();
61
+ validateGeometryAttributes(mesh.attributes);
62
+ const model = new Model(this.context.gl, {
63
+ ...this.getShaders(),
64
+ id,
65
+ geometry: mesh,
66
+ defines: {
67
+ ...shaders.defines,
68
+ ...materialParser?.defines,
69
+ HAS_UV_REGIONS: mesh.attributes.uvRegions
70
+ },
71
+ parameters: materialParser?.parameters,
72
+ isInstanced: true
73
+ });
74
+ return model;
75
+ }
76
+ updatePbrMaterialUniforms(pbrMaterial) {
77
+ const { model } = this.state;
78
+ if (model) {
79
+ const { mesh } = this.props;
80
+ const materialParser = this.parseMaterial(pbrMaterial, mesh);
81
+ model.setUniforms(materialParser.uniforms);
82
+ }
83
+ }
84
+ parseMaterial(pbrMaterial, mesh) {
85
+ const unlit = Boolean(pbrMaterial.pbrMetallicRoughness && pbrMaterial.pbrMetallicRoughness.baseColorTexture);
86
+ const materialParser = new GLTFMaterialParser(this.context.gl, {
87
+ attributes: { NORMAL: mesh.attributes.normals, TEXCOORD_0: mesh.attributes.texCoords },
88
+ material: { unlit, ...pbrMaterial },
89
+ pbrDebug: false,
90
+ imageBasedLightingEnvironment: null,
91
+ lights: true,
92
+ useTangents: false
93
+ });
94
+ return materialParser;
95
+ }
96
+ calculateFeatureIdsPickingColors(attribute) {
97
+ const { featureIds } = this.props;
98
+ const value = new Uint8ClampedArray(featureIds.length * attribute.size);
99
+ const pickingColor = [];
100
+ for (let index = 0; index < featureIds.length; index++) {
101
+ this.encodePickingColor(featureIds[index], pickingColor);
102
+ value[index * 3] = pickingColor[0];
103
+ value[index * 3 + 1] = pickingColor[1];
104
+ value[index * 3 + 2] = pickingColor[2];
105
+ }
106
+ attribute.value = value;
107
+ }
108
+ }
109
+ _MeshLayer.layerName = '_MeshLayer';
110
+ _MeshLayer.defaultProps = defaultProps;
@@ -0,0 +1,41 @@
1
+ import { lerp } from '@math.gl/core';
2
+ const availableTransformations = {
3
+ Point,
4
+ MultiPoint,
5
+ LineString,
6
+ MultiLineString,
7
+ Polygon,
8
+ MultiPolygon
9
+ };
10
+ function Point([pointX, pointY], [nw, se], viewport) {
11
+ const x = lerp(nw[0], se[0], pointX);
12
+ const y = lerp(nw[1], se[1], pointY);
13
+ return viewport.unprojectFlat([x, y]);
14
+ }
15
+ function getPoints(geometry, bbox, viewport) {
16
+ return geometry.map(g => Point(g, bbox, viewport));
17
+ }
18
+ function MultiPoint(multiPoint, bbox, viewport) {
19
+ return getPoints(multiPoint, bbox, viewport);
20
+ }
21
+ function LineString(line, bbox, viewport) {
22
+ return getPoints(line, bbox, viewport);
23
+ }
24
+ function MultiLineString(multiLineString, bbox, viewport) {
25
+ return multiLineString.map(lineString => LineString(lineString, bbox, viewport));
26
+ }
27
+ function Polygon(polygon, bbox, viewport) {
28
+ return polygon.map(polygonRing => getPoints(polygonRing, bbox, viewport));
29
+ }
30
+ function MultiPolygon(multiPolygon, bbox, viewport) {
31
+ return multiPolygon.map(polygon => Polygon(polygon, bbox, viewport));
32
+ }
33
+ export function transform(geometry, bbox, viewport) {
34
+ const nw = viewport.projectFlat([bbox.west, bbox.north]);
35
+ const se = viewport.projectFlat([bbox.east, bbox.south]);
36
+ const projectedBbox = [nw, se];
37
+ return {
38
+ ...geometry,
39
+ coordinates: availableTransformations[geometry.type](geometry.coordinates, projectedBbox, viewport)
40
+ };
41
+ }
@@ -0,0 +1,96 @@
1
+ const GEOM_TYPES = ['points', 'lines', 'polygons'];
2
+ /**
3
+ * Return the index of feature (numericProps or featureIds) for given feature id
4
+ * Example: findIndexBinary(data, 'id', 33) will return the index in the array of numericProps
5
+ * of the feature 33.
6
+ * @param {Object} data - The data in binary format
7
+ * @param {String} uniqueIdProperty - Name of the unique id property
8
+ * @param {Number|String} featureId - feature id to find
9
+ * @param {String} layerName - the layer to search in
10
+ */
11
+ export default function findIndexBinary(data, uniqueIdProperty, featureId, layerName) {
12
+ for (const gt of GEOM_TYPES) {
13
+ const index = data[gt] && findIndexByType(data[gt], uniqueIdProperty, featureId, layerName);
14
+ if (index >= 0) {
15
+ return index;
16
+ }
17
+ }
18
+ return -1;
19
+ }
20
+ function findIndexByType(geomData, uniqueIdProperty, featureId, layerName) {
21
+ const featureIds = geomData.featureIds.value;
22
+ if (!featureIds.length) {
23
+ return -1;
24
+ }
25
+ let startFeatureIndex = 0;
26
+ let endFeatureIndex = featureIds[featureIds.length - 1] + 1;
27
+ if (layerName) {
28
+ const layerRange = getLayerRange(geomData, layerName);
29
+ if (layerRange) {
30
+ startFeatureIndex = layerRange[0];
31
+ endFeatureIndex = layerRange[1] + 1;
32
+ }
33
+ else {
34
+ return -1;
35
+ }
36
+ }
37
+ // Look for the uniqueIdProperty
38
+ let featureIndex = -1;
39
+ if (uniqueIdProperty in geomData.numericProps) {
40
+ const vertexIndex = geomData.numericProps[uniqueIdProperty].value.findIndex((x, i) => x === featureId && featureIds[i] >= startFeatureIndex && featureIds[i] < endFeatureIndex);
41
+ return vertexIndex >= 0 ? geomData.globalFeatureIds.value[vertexIndex] : -1;
42
+ }
43
+ else if (uniqueIdProperty) {
44
+ featureIndex = findIndex(geomData.properties, elem => elem[uniqueIdProperty] === featureId, startFeatureIndex, endFeatureIndex);
45
+ }
46
+ else if (geomData.fields) {
47
+ featureIndex = findIndex(geomData.fields, (elem) => elem.id === featureId, startFeatureIndex, endFeatureIndex);
48
+ }
49
+ return featureIndex >= 0 ? getGlobalFeatureId(geomData, featureIndex) : -1;
50
+ }
51
+ // Returns [firstFeatureIndex, lastFeatureIndex]
52
+ // MVTLoader parses tiles layer-by-layer, so each layer is a continuous range
53
+ function getLayerRange(geomData, layerName) {
54
+ if (!geomData.__layers) {
55
+ // Cache a map from properties.layerName to index ranges
56
+ const layerNames = {};
57
+ const { properties } = geomData;
58
+ for (let i = 0; i < properties.length; i++) {
59
+ const { layerName: key } = properties[i];
60
+ if (!key) {
61
+ // ignore
62
+ }
63
+ else if (layerNames[key]) {
64
+ layerNames[key][1] = i;
65
+ }
66
+ else {
67
+ layerNames[key] = [i, i];
68
+ }
69
+ }
70
+ geomData.__layers = layerNames;
71
+ }
72
+ return geomData.__layers[layerName];
73
+ }
74
+ // Returns global feature id
75
+ function getGlobalFeatureId(geomData, featureIndex) {
76
+ if (!geomData.__ids) {
77
+ // Cache a map from featureId to globalFeatureId
78
+ const result = [];
79
+ const featureIds = geomData.featureIds.value;
80
+ const globalFeatureIds = geomData.globalFeatureIds.value;
81
+ for (let i = 0; i < featureIds.length; i++) {
82
+ result[featureIds[i]] = globalFeatureIds[i];
83
+ }
84
+ geomData.__ids = result;
85
+ }
86
+ return geomData.__ids[featureIndex];
87
+ }
88
+ // Like array.findIndex, but only search within a range
89
+ function findIndex(array, predicate, startIndex, endIndex) {
90
+ for (let i = startIndex; i < endIndex; i++) {
91
+ if (predicate(array[i], i)) {
92
+ return i;
93
+ }
94
+ }
95
+ return -1;
96
+ }
@@ -0,0 +1,297 @@
1
+ import { log, COORDINATE_SYSTEM } from '@deck.gl/core';
2
+ import { GeoJsonLayer } from '@deck.gl/layers';
3
+ import { Matrix4 } from '@math.gl/core';
4
+ import { MVTWorkerLoader } from '@loaders.gl/mvt';
5
+ import { binaryToGeojson } from '@loaders.gl/gis';
6
+ import { ClipExtension } from '@deck.gl/extensions';
7
+ import TileLayer from '../tile-layer/tile-layer';
8
+ import { getURLFromTemplate, isGeoBoundingBox, isURLTemplate } from '../tile-layer/utils';
9
+ import { transform } from './coordinate-transform';
10
+ import findIndexBinary from './find-index-binary';
11
+ const WORLD_SIZE = 512;
12
+ const defaultProps = {
13
+ ...GeoJsonLayer.defaultProps,
14
+ uniqueIdProperty: { type: 'string', value: '' },
15
+ highlightedFeatureId: null,
16
+ loaders: [MVTWorkerLoader],
17
+ binary: true
18
+ };
19
+ export default class MVTLayer extends TileLayer {
20
+ initializeState() {
21
+ super.initializeState();
22
+ // GlobeView doesn't work well with binary data
23
+ const binary = this.context.viewport.resolution !== undefined ? false : this.props.binary;
24
+ this.setState({
25
+ binary,
26
+ data: null,
27
+ tileJSON: null
28
+ });
29
+ }
30
+ get isLoaded() {
31
+ return this.state && this.state.data && this.state.tileset && super.isLoaded;
32
+ }
33
+ updateState({ props, oldProps, context, changeFlags }) {
34
+ if (changeFlags.dataChanged) {
35
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
36
+ this._updateTileData();
37
+ }
38
+ if (this.state?.data) {
39
+ super.updateState({ props, oldProps, context, changeFlags });
40
+ this._setWGS84PropertyForTiles();
41
+ }
42
+ const { highlightColor } = props;
43
+ if (highlightColor !== oldProps.highlightColor && Array.isArray(highlightColor)) {
44
+ this.setState({ highlightColor });
45
+ }
46
+ }
47
+ /* eslint-disable complexity */
48
+ async _updateTileData() {
49
+ let data = this.props.data;
50
+ let tileJSON = null;
51
+ if (typeof data === 'string' && !isURLTemplate(data)) {
52
+ const { onDataLoad, fetch } = this.props;
53
+ this.setState({ data: null, tileJSON: null });
54
+ try {
55
+ tileJSON = await fetch(data, { propName: 'data', layer: this, loaders: [] });
56
+ }
57
+ catch (error) {
58
+ this.raiseError(error, 'loading TileJSON');
59
+ data = null;
60
+ }
61
+ if (onDataLoad) {
62
+ onDataLoad(tileJSON, { propName: 'data', layer: this });
63
+ }
64
+ }
65
+ else if (data.tilejson) {
66
+ tileJSON = data;
67
+ }
68
+ if (tileJSON) {
69
+ data = tileJSON.tiles;
70
+ }
71
+ this.setState({ data, tileJSON });
72
+ }
73
+ _getTilesetOptions() {
74
+ const opts = super._getTilesetOptions();
75
+ const tileJSON = this.state.tileJSON;
76
+ const { minZoom, maxZoom } = this.props;
77
+ if (tileJSON) {
78
+ if (Number.isFinite(tileJSON.minzoom) && tileJSON.minzoom > minZoom) {
79
+ opts.minZoom = tileJSON.minzoom;
80
+ }
81
+ if (Number.isFinite(tileJSON.maxzoom) &&
82
+ (!Number.isFinite(maxZoom) || tileJSON.maxzoom < maxZoom)) {
83
+ opts.maxZoom = tileJSON.maxzoom;
84
+ }
85
+ }
86
+ return opts;
87
+ }
88
+ /* eslint-disable complexity */
89
+ renderLayers() {
90
+ if (!this.state?.data)
91
+ return null;
92
+ return super.renderLayers();
93
+ }
94
+ getTileData(loadProps) {
95
+ const { data, binary } = this.state;
96
+ const { index, signal } = loadProps;
97
+ const url = getURLFromTemplate(data, loadProps);
98
+ if (!url) {
99
+ return Promise.reject('Invalid URL');
100
+ }
101
+ let loadOptions = this.getLoadOptions();
102
+ const { fetch } = this.props;
103
+ loadOptions = {
104
+ ...loadOptions,
105
+ mimeType: 'application/x-protobuf',
106
+ mvt: {
107
+ ...loadOptions?.mvt,
108
+ coordinates: this.context.viewport.resolution ? 'wgs84' : 'local',
109
+ tileIndex: index
110
+ // Local worker debug
111
+ // workerUrl: `modules/mvt/dist/mvt-loader.worker.js`
112
+ // Set worker to null to skip web workers
113
+ // workerUrl: null
114
+ },
115
+ gis: binary ? { format: 'binary' } : {}
116
+ };
117
+ return fetch(url, { propName: 'data', layer: this, loadOptions, signal });
118
+ }
119
+ renderSubLayers(props) {
120
+ const { x, y, z } = props.tile.index;
121
+ const worldScale = Math.pow(2, z);
122
+ const xScale = WORLD_SIZE / worldScale;
123
+ const yScale = -xScale;
124
+ const xOffset = (WORLD_SIZE * x) / worldScale;
125
+ const yOffset = WORLD_SIZE * (1 - y / worldScale);
126
+ const modelMatrix = new Matrix4().scale([xScale, yScale, 1]);
127
+ props.autoHighlight = false;
128
+ if (!this.context.viewport.resolution) {
129
+ props.modelMatrix = modelMatrix;
130
+ props.coordinateOrigin = [xOffset, yOffset, 0];
131
+ props.coordinateSystem = COORDINATE_SYSTEM.CARTESIAN;
132
+ props.extensions = [...(props.extensions || []), new ClipExtension()];
133
+ }
134
+ const subLayers = super.renderSubLayers(props);
135
+ if (this.state.binary && !(subLayers instanceof GeoJsonLayer)) {
136
+ log.warn('renderSubLayers() must return GeoJsonLayer when using binary:true')();
137
+ }
138
+ return subLayers;
139
+ }
140
+ _updateAutoHighlight(info) {
141
+ const { uniqueIdProperty } = this.props;
142
+ const { hoveredFeatureId, hoveredFeatureLayerName } = this.state;
143
+ const hoveredFeature = info.object;
144
+ let newHoveredFeatureId;
145
+ let newHoveredFeatureLayerName;
146
+ if (hoveredFeature) {
147
+ newHoveredFeatureId = getFeatureUniqueId(hoveredFeature, uniqueIdProperty);
148
+ newHoveredFeatureLayerName = getFeatureLayerName(hoveredFeature);
149
+ }
150
+ let { highlightColor } = this.props;
151
+ if (typeof highlightColor === 'function') {
152
+ highlightColor = highlightColor(info);
153
+ }
154
+ if (hoveredFeatureId !== newHoveredFeatureId ||
155
+ hoveredFeatureLayerName !== newHoveredFeatureLayerName) {
156
+ this.setState({
157
+ highlightColor,
158
+ hoveredFeatureId: newHoveredFeatureId,
159
+ hoveredFeatureLayerName: newHoveredFeatureLayerName
160
+ });
161
+ }
162
+ }
163
+ getPickingInfo(params) {
164
+ const info = super.getPickingInfo(params);
165
+ const isWGS84 = Boolean(this.context.viewport.resolution);
166
+ if (this.state.binary && info.index !== -1) {
167
+ const { data } = params.sourceLayer.props;
168
+ info.object = binaryToGeojson(data, { globalFeatureId: info.index });
169
+ }
170
+ if (info.object && !isWGS84) {
171
+ info.object = transformTileCoordsToWGS84(info.object, info.tile.bbox, this.context.viewport);
172
+ }
173
+ return info;
174
+ }
175
+ getSubLayerPropsByTile(tile) {
176
+ return {
177
+ highlightedObjectIndex: this.getHighlightedObjectIndex(tile),
178
+ highlightColor: this.state.highlightColor
179
+ };
180
+ }
181
+ getHighlightedObjectIndex(tile) {
182
+ const { hoveredFeatureId, hoveredFeatureLayerName, binary } = this.state;
183
+ const { uniqueIdProperty, highlightedFeatureId } = this.props;
184
+ const data = tile.content;
185
+ const isHighlighted = isFeatureIdDefined(highlightedFeatureId);
186
+ const isFeatureIdPresent = isFeatureIdDefined(hoveredFeatureId) || isHighlighted;
187
+ if (!isFeatureIdPresent) {
188
+ return -1;
189
+ }
190
+ const featureIdToHighlight = isHighlighted ? highlightedFeatureId : hoveredFeatureId;
191
+ // Iterable data
192
+ if (Array.isArray(data)) {
193
+ return data.findIndex(feature => {
194
+ const isMatchingId = getFeatureUniqueId(feature, uniqueIdProperty) === featureIdToHighlight;
195
+ const isMatchingLayer = isHighlighted || getFeatureLayerName(feature) === hoveredFeatureLayerName;
196
+ return isMatchingId && isMatchingLayer;
197
+ });
198
+ // Non-iterable data
199
+ }
200
+ else if (data && binary) {
201
+ // Get the feature index of the selected item to highlight
202
+ return findIndexBinary(data, uniqueIdProperty, featureIdToHighlight, isHighlighted ? '' : hoveredFeatureLayerName);
203
+ }
204
+ return -1;
205
+ }
206
+ _pickObjects(maxObjects) {
207
+ const { deck, viewport } = this.context;
208
+ const width = viewport.width;
209
+ const height = viewport.height;
210
+ const x = viewport.x;
211
+ const y = viewport.y;
212
+ const layerIds = [this.id];
213
+ return deck.pickObjects({ x, y, width, height, layerIds, maxObjects });
214
+ }
215
+ /** Get the rendered features in the current viewport. */
216
+ getRenderedFeatures(maxFeatures = null) {
217
+ const features = this._pickObjects(maxFeatures);
218
+ const featureCache = new Set();
219
+ const renderedFeatures = [];
220
+ for (const f of features) {
221
+ const featureId = getFeatureUniqueId(f.object, this.props.uniqueIdProperty);
222
+ if (featureId === undefined) {
223
+ // we have no id for the feature, we just add to the list
224
+ renderedFeatures.push(f.object);
225
+ }
226
+ else if (!featureCache.has(featureId)) {
227
+ // Add removing duplicates
228
+ featureCache.add(featureId);
229
+ renderedFeatures.push(f.object);
230
+ }
231
+ }
232
+ return renderedFeatures;
233
+ }
234
+ _setWGS84PropertyForTiles() {
235
+ const propName = 'dataInWGS84';
236
+ const tileset = this.state.tileset;
237
+ // @ts-expect-error selectedTiles are always initialized when tile is being processed
238
+ tileset.selectedTiles.forEach((tile) => {
239
+ if (!tile.hasOwnProperty(propName)) {
240
+ // eslint-disable-next-line accessor-pairs
241
+ Object.defineProperty(tile, propName, {
242
+ get: () => {
243
+ // Still loading or encountered an error
244
+ if (!tile.content) {
245
+ return null;
246
+ }
247
+ if (this.state.binary && Array.isArray(tile.content) && !tile.content.length) {
248
+ // TODO: @loaders.gl/mvt returns [] when no content. It should return a valid empty binary.
249
+ // https://github.com/visgl/loaders.gl/pull/1137
250
+ return [];
251
+ }
252
+ const { bbox } = tile;
253
+ if (tile._contentWGS84 === undefined && isGeoBoundingBox(bbox)) {
254
+ // Create a cache to transform only once
255
+ const content = this.state.binary ? binaryToGeojson(tile.content) : tile.content;
256
+ tile._contentWGS84 = content.map(feature => transformTileCoordsToWGS84(feature, bbox, this.context.viewport));
257
+ }
258
+ return tile._contentWGS84;
259
+ }
260
+ });
261
+ }
262
+ });
263
+ }
264
+ }
265
+ MVTLayer.layerName = 'MVTLayer';
266
+ MVTLayer.defaultProps = defaultProps;
267
+ function getFeatureUniqueId(feature, uniqueIdProperty) {
268
+ if (feature.properties && uniqueIdProperty) {
269
+ return feature.properties[uniqueIdProperty];
270
+ }
271
+ if ('id' in feature) {
272
+ return feature.id;
273
+ }
274
+ return undefined;
275
+ }
276
+ function getFeatureLayerName(feature) {
277
+ return feature.properties?.layerName || null;
278
+ }
279
+ function isFeatureIdDefined(value) {
280
+ return value !== undefined && value !== null && value !== '';
281
+ }
282
+ function transformTileCoordsToWGS84(object, bbox, viewport) {
283
+ const feature = {
284
+ ...object,
285
+ geometry: {
286
+ type: object.geometry.type
287
+ }
288
+ };
289
+ // eslint-disable-next-line accessor-pairs
290
+ Object.defineProperty(feature.geometry, 'coordinates', {
291
+ get: () => {
292
+ const wgs84Geom = transform(object.geometry, bbox, viewport);
293
+ return wgs84Geom.coordinates;
294
+ }
295
+ });
296
+ return feature;
297
+ }
@@ -0,0 +1,18 @@
1
+ import GeoCellLayer from '../geo-cell-layer/GeoCellLayer';
2
+ import { getQuadkeyPolygon } from './quadkey-utils';
3
+ const defaultProps = {
4
+ getQuadkey: { type: 'accessor', value: d => d.quadkey }
5
+ };
6
+ export default class QuadkeyLayer extends GeoCellLayer {
7
+ indexToBounds() {
8
+ const { data, getQuadkey } = this.props;
9
+ return {
10
+ data,
11
+ _normalize: false,
12
+ positionFormat: 'XY',
13
+ getPolygon: (x, objectInfo) => getQuadkeyPolygon(getQuadkey(x, objectInfo))
14
+ };
15
+ }
16
+ }
17
+ QuadkeyLayer.layerName = 'QuadkeyLayer';
18
+ QuadkeyLayer.defaultProps = defaultProps;
@@ -0,0 +1,26 @@
1
+ import { worldToLngLat } from '@math.gl/web-mercator';
2
+ const TILE_SIZE = 512;
3
+ export function quadkeyToWorldBounds(quadkey) {
4
+ let x = 0;
5
+ let y = 0;
6
+ let mask = 1 << quadkey.length;
7
+ const scale = mask / TILE_SIZE;
8
+ for (let i = 0; i < quadkey.length; i++) {
9
+ mask >>= 1;
10
+ const q = parseInt(quadkey[i]);
11
+ if (q % 2)
12
+ x |= mask;
13
+ if (q > 1)
14
+ y |= mask;
15
+ }
16
+ return [
17
+ [x / scale, TILE_SIZE - y / scale],
18
+ [(x + 0.99) / scale, TILE_SIZE - (y + 0.99) / scale]
19
+ ];
20
+ }
21
+ export function getQuadkeyPolygon(quadkey) {
22
+ const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
23
+ const [w, n] = worldToLngLat(topLeft);
24
+ const [e, s] = worldToLngLat(bottomRight);
25
+ return [e, n, e, s, w, s, w, n, e, n];
26
+ }