@deck.gl/geo-layers 8.8.0-beta.5 → 8.8.0

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.
@@ -0,0 +1,88 @@
1
+ // s2-geometry is a pure JavaScript port of Google/Niantic's S2 Geometry library
2
+ // which is perfect since it works in the browser.
3
+ import { toHilbertQuadkey, FromHilbertQuadKey, IJToST, STToUV, FaceUVToXYZ, XYZToLngLat } from './s2-geometry';
4
+ import Long from 'long';
5
+ /**
6
+ * Given an S2 token this function convert the token to 64 bit id
7
+ https://github.com/google/s2-geometry-library-java/blob/c04b68bf3197a9c34082327eeb3aec7ab7c85da1/src/com/google/common/geometry/S2CellId.java#L439
8
+ * */
9
+ function getIdFromToken(token) {
10
+ // pad token with zeros to make the length 16
11
+ const paddedToken = token.padEnd(16, '0');
12
+ return Long.fromString(paddedToken, 16);
13
+ }
14
+ const MAX_RESOLUTION = 100;
15
+ /* Adapted from s2-geometry's S2Cell.getCornerLatLngs */
16
+ /* eslint-disable max-statements */
17
+ function getGeoBounds({ face, ij, level }) {
18
+ const offsets = [
19
+ [0, 0],
20
+ [0, 1],
21
+ [1, 1],
22
+ [1, 0],
23
+ [0, 0]
24
+ ];
25
+ // The S2 cell edge is curved: http://s2geometry.io/
26
+ // This is more prominent at lower levels
27
+ // resolution is the number of segments to generate per edge.
28
+ // We exponentially reduce resolution as level increases so it doesn't affect perf
29
+ // when there are a large number of cells
30
+ const resolution = Math.max(1, Math.ceil(MAX_RESOLUTION * Math.pow(2, -level)));
31
+ const result = new Float64Array(4 * resolution * 2 + 2);
32
+ let ptIndex = 0;
33
+ let prevLng = 0;
34
+ for (let i = 0; i < 4; i++) {
35
+ const offset = offsets[i].slice(0);
36
+ const nextOffset = offsets[i + 1];
37
+ const stepI = (nextOffset[0] - offset[0]) / resolution;
38
+ const stepJ = (nextOffset[1] - offset[1]) / resolution;
39
+ for (let j = 0; j < resolution; j++) {
40
+ offset[0] += stepI;
41
+ offset[1] += stepJ;
42
+ // Cell can be represented by coordinates IJ, ST, UV, XYZ
43
+ // http://s2geometry.io/devguide/s2cell_hierarchy#coordinate-systems
44
+ const st = IJToST(ij, level, offset);
45
+ const uv = STToUV(st);
46
+ const xyz = FaceUVToXYZ(face, uv);
47
+ const lngLat = XYZToLngLat(xyz);
48
+ // Adjust longitude for Web Mercator projection
49
+ if (Math.abs(lngLat[1]) > 89.999) {
50
+ lngLat[0] = prevLng;
51
+ }
52
+ const deltaLng = lngLat[0] - prevLng;
53
+ lngLat[0] += deltaLng > 180 ? -360 : deltaLng < -180 ? 360 : 0;
54
+ result[ptIndex++] = lngLat[0];
55
+ result[ptIndex++] = lngLat[1];
56
+ prevLng = lngLat[0];
57
+ }
58
+ }
59
+ // close the loop
60
+ result[ptIndex++] = result[0];
61
+ result[ptIndex++] = result[1];
62
+ return result;
63
+ }
64
+ /* eslint-enable max-statements */
65
+ export function getS2QuadKey(token) {
66
+ if (typeof token === 'string') {
67
+ if (token.indexOf('/') > 0) {
68
+ // is Hilbert quad key
69
+ return token;
70
+ }
71
+ // is S2 token
72
+ token = getIdFromToken(token);
73
+ }
74
+ // is Long id
75
+ return toHilbertQuadkey(token.toString());
76
+ }
77
+ /**
78
+ * Get a polygon with corner coordinates for an s2 cell
79
+ * @param {*} cell - This can be an S2 key or token
80
+ * @return {Array} - a simple polygon in array format: [[lng, lat], ...]
81
+ * - each coordinate is an array [lng, lat]
82
+ * - the polygon is closed, i.e. last coordinate is a copy of the first coordinate
83
+ */
84
+ export function getS2Polygon(token) {
85
+ const key = getS2QuadKey(token);
86
+ const s2cell = FromHilbertQuadKey(key);
87
+ return getGeoBounds(s2cell);
88
+ }
@@ -0,0 +1,226 @@
1
+ // Copyright (c) 2015 - 2017 Uber Technologies, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ import { CompositeLayer, log } from '@deck.gl/core';
21
+ import { SimpleMeshLayer } from '@deck.gl/mesh-layers';
22
+ import { COORDINATE_SYSTEM } from '@deck.gl/core';
23
+ import { TerrainWorkerLoader } from '@loaders.gl/terrain';
24
+ import TileLayer from '../tile-layer/tile-layer';
25
+ import { urlType, getURLFromTemplate } from '../tile-layer/utils';
26
+ const DUMMY_DATA = [1];
27
+ const defaultProps = {
28
+ ...TileLayer.defaultProps,
29
+ // Image url that encodes height data
30
+ elevationData: urlType,
31
+ // Image url to use as texture
32
+ texture: { ...urlType, optional: true },
33
+ // Martini error tolerance in meters, smaller number -> more detailed mesh
34
+ meshMaxError: { type: 'number', value: 4.0 },
35
+ // Bounding box of the terrain image, [minX, minY, maxX, maxY] in world coordinates
36
+ bounds: { type: 'array', value: null, optional: true, compare: true },
37
+ // Color to use if texture is unavailable
38
+ color: { type: 'color', value: [255, 255, 255] },
39
+ // Object to decode height data, from (r, g, b) to height in meters
40
+ elevationDecoder: {
41
+ type: 'object',
42
+ value: {
43
+ rScaler: 1,
44
+ gScaler: 0,
45
+ bScaler: 0,
46
+ offset: 0
47
+ }
48
+ },
49
+ // Supply url to local terrain worker bundle. Only required if running offline and cannot access CDN.
50
+ workerUrl: { type: 'string', value: null },
51
+ // Same as SimpleMeshLayer wireframe
52
+ wireframe: false,
53
+ material: true,
54
+ loaders: [TerrainWorkerLoader]
55
+ };
56
+ // Turns array of templates into a single string to work around shallow change
57
+ function urlTemplateToUpdateTrigger(template) {
58
+ if (Array.isArray(template)) {
59
+ return template.join(';');
60
+ }
61
+ return template;
62
+ }
63
+ /**
64
+ * state: {
65
+ * isTiled: True renders TileLayer of many SimpleMeshLayers, false renders one SimpleMeshLayer
66
+ * terrain: Mesh object. Only defined when isTiled is false.
67
+ * }
68
+ */
69
+ export default class TerrainLayer extends CompositeLayer {
70
+ updateState({ props, oldProps }) {
71
+ const elevationDataChanged = props.elevationData !== oldProps.elevationData;
72
+ if (elevationDataChanged) {
73
+ const { elevationData } = props;
74
+ const isTiled = elevationData &&
75
+ (Array.isArray(elevationData) ||
76
+ (elevationData.includes('{x}') && elevationData.includes('{y}')));
77
+ this.setState({ isTiled });
78
+ }
79
+ // Reloading for single terrain mesh
80
+ const shouldReload = elevationDataChanged ||
81
+ props.meshMaxError !== oldProps.meshMaxError ||
82
+ props.elevationDecoder !== oldProps.elevationDecoder ||
83
+ props.bounds !== oldProps.bounds;
84
+ if (!this.state.isTiled && shouldReload) {
85
+ const terrain = this.loadTerrain(props);
86
+ this.setState({ terrain });
87
+ }
88
+ // TODO - remove in v9
89
+ if (props.workerUrl) {
90
+ log.removed('workerUrl', 'loadOptions.terrain.workerUrl')();
91
+ }
92
+ }
93
+ loadTerrain({ elevationData, bounds, elevationDecoder, meshMaxError, signal }) {
94
+ if (!elevationData) {
95
+ return null;
96
+ }
97
+ let loadOptions = this.getLoadOptions();
98
+ loadOptions = {
99
+ ...loadOptions,
100
+ terrain: {
101
+ skirtHeight: this.state.isTiled ? meshMaxError * 2 : 0,
102
+ ...loadOptions?.terrain,
103
+ bounds,
104
+ meshMaxError,
105
+ elevationDecoder
106
+ }
107
+ };
108
+ const { fetch } = this.props;
109
+ return fetch(elevationData, { propName: 'elevationData', layer: this, loadOptions, signal });
110
+ }
111
+ getTiledTerrainData(tile) {
112
+ const { elevationData, fetch, texture, elevationDecoder, meshMaxError } = this.props;
113
+ const { viewport } = this.context;
114
+ const dataUrl = getURLFromTemplate(elevationData, tile);
115
+ const textureUrl = getURLFromTemplate(texture, tile);
116
+ const { bbox, signal } = tile;
117
+ const bottomLeft = viewport.isGeospatial
118
+ ? viewport.projectFlat([bbox.west, bbox.south])
119
+ : [bbox.left, bbox.bottom];
120
+ const topRight = viewport.isGeospatial
121
+ ? viewport.projectFlat([bbox.east, bbox.north])
122
+ : [bbox.right, bbox.top];
123
+ const bounds = [bottomLeft[0], bottomLeft[1], topRight[0], topRight[1]];
124
+ const terrain = this.loadTerrain({
125
+ elevationData: dataUrl,
126
+ bounds,
127
+ elevationDecoder,
128
+ meshMaxError,
129
+ signal
130
+ });
131
+ const surface = textureUrl
132
+ ? // If surface image fails to load, the tile should still be displayed
133
+ fetch(textureUrl, { propName: 'texture', layer: this, loaders: [], signal }).catch(_ => null)
134
+ : Promise.resolve(null);
135
+ return Promise.all([terrain, surface]);
136
+ }
137
+ renderSubLayers(props) {
138
+ const SubLayerClass = this.getSubLayerClass('mesh', SimpleMeshLayer);
139
+ const { data, color } = props;
140
+ if (!data) {
141
+ return null;
142
+ }
143
+ const [mesh, texture] = data;
144
+ return new SubLayerClass(props, {
145
+ data: DUMMY_DATA,
146
+ mesh,
147
+ texture,
148
+ _instanced: false,
149
+ coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
150
+ getPosition: d => [0, 0, 0],
151
+ getColor: color
152
+ });
153
+ }
154
+ // Update zRange of viewport
155
+ onViewportLoad(tiles) {
156
+ if (!tiles) {
157
+ return;
158
+ }
159
+ const { zRange } = this.state;
160
+ const ranges = tiles
161
+ .map(tile => tile.content)
162
+ .filter(Boolean)
163
+ .map(arr => {
164
+ const bounds = arr[0].header.boundingBox;
165
+ return bounds.map(bound => bound[2]);
166
+ });
167
+ if (ranges.length === 0) {
168
+ return;
169
+ }
170
+ const minZ = Math.min(...ranges.map(x => x[0]));
171
+ const maxZ = Math.max(...ranges.map(x => x[1]));
172
+ if (!zRange || minZ < zRange[0] || maxZ > zRange[1]) {
173
+ this.setState({ zRange: [minZ, maxZ] });
174
+ }
175
+ }
176
+ renderLayers() {
177
+ const { color, material, elevationData, texture, wireframe, meshMaxError, elevationDecoder, tileSize, maxZoom, minZoom, extent, maxRequests, onTileLoad, onTileUnload, onTileError, maxCacheSize, maxCacheByteSize, refinementStrategy } = this.props;
178
+ if (this.state.isTiled) {
179
+ return new TileLayer(this.getSubLayerProps({
180
+ id: 'tiles'
181
+ }), {
182
+ wireframe,
183
+ color,
184
+ material,
185
+ getTileData: this.getTiledTerrainData.bind(this),
186
+ renderSubLayers: this.renderSubLayers.bind(this),
187
+ updateTriggers: {
188
+ getTileData: {
189
+ elevationData: urlTemplateToUpdateTrigger(elevationData),
190
+ texture: urlTemplateToUpdateTrigger(texture),
191
+ meshMaxError,
192
+ elevationDecoder
193
+ }
194
+ },
195
+ onViewportLoad: this.onViewportLoad.bind(this),
196
+ zRange: this.state.zRange || null,
197
+ tileSize,
198
+ maxZoom,
199
+ minZoom,
200
+ extent,
201
+ maxRequests,
202
+ onTileLoad,
203
+ onTileUnload,
204
+ onTileError,
205
+ maxCacheSize,
206
+ maxCacheByteSize,
207
+ refinementStrategy
208
+ });
209
+ }
210
+ const SubLayerClass = this.getSubLayerClass('mesh', SimpleMeshLayer);
211
+ return new SubLayerClass(this.getSubLayerProps({
212
+ id: 'mesh'
213
+ }), {
214
+ data: DUMMY_DATA,
215
+ mesh: this.state.terrain,
216
+ texture,
217
+ _instanced: false,
218
+ getPosition: d => [0, 0, 0],
219
+ getColor: color,
220
+ material,
221
+ wireframe
222
+ });
223
+ }
224
+ }
225
+ TerrainLayer.layerName = 'TerrainLayer';
226
+ TerrainLayer.defaultProps = defaultProps;
@@ -0,0 +1,294 @@
1
+ import GL from '@luma.gl/constants';
2
+ import { Geometry } from '@luma.gl/core';
3
+ import { COORDINATE_SYSTEM, CompositeLayer } from '@deck.gl/core';
4
+ import { PointCloudLayer } from '@deck.gl/layers';
5
+ import { ScenegraphLayer } from '@deck.gl/mesh-layers';
6
+ import { default as _MeshLayer } from '../mesh-layer/mesh-layer';
7
+ import { log } from '@deck.gl/core';
8
+ import { load } from '@loaders.gl/core';
9
+ import { Tileset3D, TILE_TYPE } from '@loaders.gl/tiles';
10
+ import { Tiles3DLoader } from '@loaders.gl/3d-tiles';
11
+ const SINGLE_DATA = [0];
12
+ const defaultProps = {
13
+ getPointColor: { type: 'accessor', value: [0, 0, 0, 255] },
14
+ pointSize: 1.0,
15
+ data: null,
16
+ loader: Tiles3DLoader,
17
+ onTilesetLoad: { type: 'function', value: tileset3d => { }, compare: false },
18
+ onTileLoad: { type: 'function', value: tileHeader => { }, compare: false },
19
+ onTileUnload: { type: 'function', value: tileHeader => { }, compare: false },
20
+ onTileError: { type: 'function', value: (tile, message, url) => { }, compare: false },
21
+ _getMeshColor: { type: 'function', value: tileHeader => [255, 255, 255], compare: false }
22
+ };
23
+ export default class Tile3DLayer extends CompositeLayer {
24
+ initializeState() {
25
+ if ('onTileLoadFail' in this.props) {
26
+ log.removed('onTileLoadFail', 'onTileError')();
27
+ }
28
+ // prop verification
29
+ this.state = {
30
+ layerMap: {},
31
+ tileset3d: null,
32
+ activeViewports: {},
33
+ lastUpdatedViewports: null
34
+ };
35
+ }
36
+ get isLoaded() {
37
+ const { tileset3d } = this.state;
38
+ return tileset3d && tileset3d.isLoaded();
39
+ }
40
+ shouldUpdateState({ changeFlags }) {
41
+ return changeFlags.somethingChanged;
42
+ }
43
+ updateState({ props, oldProps, changeFlags }) {
44
+ if (props.data && props.data !== oldProps.data) {
45
+ this._loadTileset(props.data);
46
+ }
47
+ if (changeFlags.viewportChanged) {
48
+ const { activeViewports } = this.state;
49
+ const viewportsNumber = Object.keys(activeViewports).length;
50
+ if (viewportsNumber) {
51
+ this._updateTileset(activeViewports);
52
+ this.state.lastUpdatedViewports = activeViewports;
53
+ this.state.activeViewports = {};
54
+ }
55
+ }
56
+ if (changeFlags.propsChanged) {
57
+ const { layerMap } = this.state;
58
+ for (const key in layerMap) {
59
+ layerMap[key].needsUpdate = true;
60
+ }
61
+ }
62
+ }
63
+ activateViewport(viewport) {
64
+ const { activeViewports, lastUpdatedViewports } = this.state;
65
+ this.internalState.viewport = viewport;
66
+ activeViewports[viewport.id] = viewport;
67
+ const lastViewport = lastUpdatedViewports?.[viewport.id];
68
+ if (!lastViewport || !viewport.equals(lastViewport)) {
69
+ this.setChangeFlags({ viewportChanged: true });
70
+ this.setNeedsUpdate();
71
+ }
72
+ }
73
+ getPickingInfo({ info, sourceLayer }) {
74
+ const { layerMap } = this.state;
75
+ const layerId = sourceLayer && sourceLayer.id;
76
+ if (layerId) {
77
+ // layerId: this.id-[scenegraph|pointcloud]-tileId
78
+ const substr = layerId.substring(this.id.length + 1);
79
+ const tileId = substr.substring(substr.indexOf('-') + 1);
80
+ info.object = layerMap[tileId] && layerMap[tileId].tile;
81
+ }
82
+ return info;
83
+ }
84
+ filterSubLayer({ layer, viewport }) {
85
+ const { tile } = layer.props;
86
+ const { id: viewportId } = viewport;
87
+ return tile.selected && tile.viewportIds.includes(viewportId);
88
+ }
89
+ _updateAutoHighlight(info) {
90
+ if (info.sourceLayer) {
91
+ info.sourceLayer.updateAutoHighlight(info);
92
+ }
93
+ }
94
+ async _loadTileset(tilesetUrl) {
95
+ const { loadOptions = {} } = this.props;
96
+ // TODO: deprecate `loader` in v9.0
97
+ let loader = this.props.loader || this.props.loaders;
98
+ if (Array.isArray(loader)) {
99
+ loader = loader[0];
100
+ }
101
+ const options = { loadOptions: { ...loadOptions } };
102
+ if (loader.preload) {
103
+ const preloadOptions = await loader.preload(tilesetUrl, loadOptions);
104
+ if (preloadOptions.headers) {
105
+ options.loadOptions.fetch = {
106
+ ...options.loadOptions.fetch,
107
+ headers: preloadOptions.headers
108
+ };
109
+ }
110
+ Object.assign(options, preloadOptions);
111
+ }
112
+ const tilesetJson = await load(tilesetUrl, loader, options.loadOptions);
113
+ const tileset3d = new Tileset3D(tilesetJson, {
114
+ onTileLoad: this._onTileLoad.bind(this),
115
+ onTileUnload: this._onTileUnload.bind(this),
116
+ onTileLoadFail: this.props.onTileError,
117
+ ...options
118
+ });
119
+ this.setState({
120
+ tileset3d,
121
+ layerMap: {}
122
+ });
123
+ this._updateTileset(this.state.activeViewports);
124
+ this.props.onTilesetLoad(tileset3d);
125
+ }
126
+ _onTileLoad(tileHeader) {
127
+ const { lastUpdatedViewports } = this.state;
128
+ this.props.onTileLoad(tileHeader);
129
+ this._updateTileset(lastUpdatedViewports);
130
+ this.setNeedsUpdate();
131
+ }
132
+ _onTileUnload(tileHeader) {
133
+ // Was cleaned up from tileset cache. We no longer need to track it.
134
+ delete this.state.layerMap[tileHeader.id];
135
+ this.props.onTileUnload(tileHeader);
136
+ }
137
+ _updateTileset(viewports) {
138
+ const { tileset3d } = this.state;
139
+ const { timeline } = this.context;
140
+ const viewportsNumber = Object.keys(viewports).length;
141
+ if (!timeline || !viewportsNumber || !tileset3d) {
142
+ return;
143
+ }
144
+ tileset3d.selectTiles(Object.values(viewports)).then(frameNumber => {
145
+ const tilesetChanged = this.state.frameNumber !== frameNumber;
146
+ if (tilesetChanged) {
147
+ this.setState({ frameNumber });
148
+ }
149
+ });
150
+ }
151
+ _getSubLayer(tileHeader, oldLayer) {
152
+ if (!tileHeader.content) {
153
+ return null;
154
+ }
155
+ switch (tileHeader.type) {
156
+ case TILE_TYPE.POINTCLOUD:
157
+ return this._makePointCloudLayer(tileHeader, oldLayer);
158
+ case TILE_TYPE.SCENEGRAPH:
159
+ return this._make3DModelLayer(tileHeader, oldLayer);
160
+ case TILE_TYPE.MESH:
161
+ return this._makeSimpleMeshLayer(tileHeader, oldLayer);
162
+ default:
163
+ throw new Error(`Tile3DLayer: Failed to render layer of type ${tileHeader.content.type}`);
164
+ }
165
+ }
166
+ _makePointCloudLayer(tileHeader, oldLayer) {
167
+ const { attributes, pointCount, constantRGBA, cartographicOrigin, modelMatrix } = tileHeader.content;
168
+ const { positions, normals, colors } = attributes;
169
+ if (!positions) {
170
+ return null;
171
+ }
172
+ const data = (oldLayer && oldLayer.props.data) || {
173
+ header: {
174
+ vertexCount: pointCount
175
+ },
176
+ attributes: {
177
+ POSITION: positions,
178
+ NORMAL: normals,
179
+ COLOR_0: colors
180
+ }
181
+ };
182
+ const { pointSize, getPointColor } = this.props;
183
+ const SubLayerClass = this.getSubLayerClass('pointcloud', PointCloudLayer);
184
+ return new SubLayerClass({
185
+ pointSize
186
+ }, this.getSubLayerProps({
187
+ id: 'pointcloud'
188
+ }), {
189
+ id: `${this.id}-pointcloud-${tileHeader.id}`,
190
+ tile: tileHeader,
191
+ data,
192
+ coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS,
193
+ coordinateOrigin: cartographicOrigin,
194
+ modelMatrix,
195
+ getColor: constantRGBA || getPointColor,
196
+ _offset: 0
197
+ });
198
+ }
199
+ _make3DModelLayer(tileHeader) {
200
+ const { gltf, instances, cartographicOrigin, modelMatrix } = tileHeader.content;
201
+ const SubLayerClass = this.getSubLayerClass('scenegraph', ScenegraphLayer);
202
+ return new SubLayerClass({
203
+ _lighting: 'pbr'
204
+ }, this.getSubLayerProps({
205
+ id: 'scenegraph'
206
+ }), {
207
+ id: `${this.id}-scenegraph-${tileHeader.id}`,
208
+ tile: tileHeader,
209
+ data: instances || SINGLE_DATA,
210
+ scenegraph: gltf,
211
+ coordinateSystem: COORDINATE_SYSTEM.METER_OFFSETS,
212
+ coordinateOrigin: cartographicOrigin,
213
+ modelMatrix,
214
+ getTransformMatrix: instance => instance.modelMatrix,
215
+ getPosition: [0, 0, 0],
216
+ _offset: 0
217
+ });
218
+ }
219
+ _makeSimpleMeshLayer(tileHeader, oldLayer) {
220
+ const content = tileHeader.content;
221
+ const { attributes, indices, modelMatrix, cartographicOrigin, coordinateSystem = COORDINATE_SYSTEM.METER_OFFSETS, material, featureIds } = content;
222
+ const { _getMeshColor } = this.props;
223
+ const geometry = (oldLayer && oldLayer.props.mesh) ||
224
+ new Geometry({
225
+ drawMode: GL.TRIANGLES,
226
+ attributes: getMeshGeometry(attributes),
227
+ indices
228
+ });
229
+ const SubLayerClass = this.getSubLayerClass('mesh', _MeshLayer);
230
+ return new SubLayerClass(this.getSubLayerProps({
231
+ id: 'mesh'
232
+ }), {
233
+ id: `${this.id}-mesh-${tileHeader.id}`,
234
+ tile: tileHeader,
235
+ mesh: geometry,
236
+ data: SINGLE_DATA,
237
+ getColor: _getMeshColor(tileHeader),
238
+ pbrMaterial: material,
239
+ modelMatrix,
240
+ coordinateOrigin: cartographicOrigin,
241
+ coordinateSystem,
242
+ featureIds,
243
+ _offset: 0
244
+ });
245
+ }
246
+ renderLayers() {
247
+ const { tileset3d, layerMap } = this.state;
248
+ if (!tileset3d) {
249
+ return null;
250
+ }
251
+ return tileset3d.tiles
252
+ .map(tile => {
253
+ const layerCache = (layerMap[tile.id] = layerMap[tile.id] || { tile });
254
+ let { layer } = layerCache;
255
+ if (tile.selected) {
256
+ // render selected tiles
257
+ if (!layer) {
258
+ // create layer
259
+ layer = this._getSubLayer(tile);
260
+ }
261
+ else if (layerCache.needsUpdate) {
262
+ // props have changed, rerender layer
263
+ layer = this._getSubLayer(tile, layer);
264
+ layerCache.needsUpdate = false;
265
+ }
266
+ }
267
+ layerCache.layer = layer;
268
+ return layer;
269
+ })
270
+ .filter(Boolean);
271
+ }
272
+ }
273
+ function getMeshGeometry(contentAttributes) {
274
+ const attributes = {};
275
+ attributes.positions = {
276
+ ...contentAttributes.positions,
277
+ value: new Float32Array(contentAttributes.positions.value)
278
+ };
279
+ if (contentAttributes.normals) {
280
+ attributes.normals = contentAttributes.normals;
281
+ }
282
+ if (contentAttributes.texCoords) {
283
+ attributes.texCoords = contentAttributes.texCoords;
284
+ }
285
+ if (contentAttributes.colors) {
286
+ attributes.colors = contentAttributes.colors;
287
+ }
288
+ if (contentAttributes.uvRegions) {
289
+ attributes.uvRegions = contentAttributes.uvRegions;
290
+ }
291
+ return attributes;
292
+ }
293
+ Tile3DLayer.layerName = 'Tile3DLayer';
294
+ Tile3DLayer.defaultProps = defaultProps;