@deck.gl/geo-layers 8.9.0-alpha.5 → 8.9.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.
- package/dist/dist.dev.js +25764 -66606
- package/dist/es5/geo-cell-layer/GeoCellLayer.js.map +1 -1
- package/dist/es5/geohash-layer/geohash-layer.js.map +1 -1
- package/dist/es5/great-circle-layer/great-circle-layer.js.map +1 -1
- package/dist/es5/h3-layers/h3-cluster-layer.js +2 -2
- package/dist/es5/h3-layers/h3-cluster-layer.js.map +1 -1
- package/dist/es5/h3-layers/h3-hexagon-layer.js.map +1 -1
- package/dist/es5/index.js +4 -8
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/mesh-layer/mesh-layer-fragment.glsl.js +1 -1
- package/dist/es5/mesh-layer/mesh-layer-vertex.glsl.js +1 -1
- package/dist/es5/mesh-layer/mesh-layer.js.map +1 -1
- package/dist/es5/mvt-layer/coordinate-transform.js.map +1 -1
- package/dist/es5/mvt-layer/mvt-layer.js +9 -9
- package/dist/es5/mvt-layer/mvt-layer.js.map +1 -1
- package/dist/es5/quadkey-layer/quadkey-layer.js.map +1 -1
- package/dist/es5/s2-layer/s2-layer.js.map +1 -1
- package/dist/es5/terrain-layer/terrain-layer.js +6 -9
- package/dist/es5/terrain-layer/terrain-layer.js.map +1 -1
- package/dist/es5/tile-3d-layer/tile-3d-layer.js +9 -8
- package/dist/es5/tile-3d-layer/tile-3d-layer.js.map +1 -1
- package/dist/es5/tile-layer/tile-layer.js +32 -14
- package/dist/es5/tile-layer/tile-layer.js.map +1 -1
- package/dist/es5/tileset-2d/index.js +66 -0
- package/dist/es5/tileset-2d/index.js.map +1 -0
- package/dist/es5/tileset-2d/memoize.js +47 -0
- package/dist/es5/tileset-2d/memoize.js.map +1 -0
- package/dist/es5/{tile-layer → tileset-2d}/tile-2d-header.js +3 -5
- package/dist/es5/tileset-2d/tile-2d-header.js.map +1 -0
- package/dist/es5/{tile-layer → tileset-2d}/tile-2d-traversal.js +0 -0
- package/dist/es5/tileset-2d/tile-2d-traversal.js.map +1 -0
- package/dist/es5/{tile-layer → tileset-2d}/tileset-2d.js +166 -121
- package/dist/es5/tileset-2d/tileset-2d.js.map +1 -0
- package/dist/es5/{tile-layer → tileset-2d}/types.js +0 -0
- package/dist/es5/{tile-layer → tileset-2d}/types.js.map +0 -0
- package/dist/es5/{tile-layer → tileset-2d}/utils.js +17 -18
- package/dist/es5/tileset-2d/utils.js.map +1 -0
- package/dist/es5/trips-layer/trips-layer.js.map +1 -1
- package/dist/esm/geo-cell-layer/GeoCellLayer.js.map +1 -1
- package/dist/esm/geohash-layer/geohash-layer.js.map +1 -1
- package/dist/esm/great-circle-layer/great-circle-layer.js.map +1 -1
- package/dist/esm/h3-layers/h3-cluster-layer.js +1 -1
- package/dist/esm/h3-layers/h3-cluster-layer.js.map +1 -1
- package/dist/esm/h3-layers/h3-hexagon-layer.js.map +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mesh-layer/mesh-layer-fragment.glsl.js +1 -1
- package/dist/esm/mesh-layer/mesh-layer-vertex.glsl.js +1 -1
- package/dist/esm/mesh-layer/mesh-layer.js.map +1 -1
- package/dist/esm/mvt-layer/coordinate-transform.js.map +1 -1
- package/dist/esm/mvt-layer/mvt-layer.js +3 -3
- package/dist/esm/mvt-layer/mvt-layer.js.map +1 -1
- package/dist/esm/quadkey-layer/quadkey-layer.js.map +1 -1
- package/dist/esm/s2-layer/s2-layer.js.map +1 -1
- package/dist/esm/terrain-layer/terrain-layer.js +2 -5
- package/dist/esm/terrain-layer/terrain-layer.js.map +1 -1
- package/dist/esm/tile-3d-layer/tile-3d-layer.js +9 -10
- package/dist/esm/tile-3d-layer/tile-3d-layer.js.map +1 -1
- package/dist/esm/tile-layer/tile-layer.js +16 -6
- package/dist/esm/tile-layer/tile-layer.js.map +1 -1
- package/dist/esm/tileset-2d/index.js +4 -0
- package/dist/esm/tileset-2d/index.js.map +1 -0
- package/dist/esm/tileset-2d/memoize.js +40 -0
- package/dist/esm/tileset-2d/memoize.js.map +1 -0
- package/dist/esm/{tile-layer → tileset-2d}/tile-2d-header.js +2 -3
- package/dist/esm/tileset-2d/tile-2d-header.js.map +1 -0
- package/dist/esm/{tile-layer → tileset-2d}/tile-2d-traversal.js +0 -0
- package/dist/esm/tileset-2d/tile-2d-traversal.js.map +1 -0
- package/dist/esm/{tile-layer → tileset-2d}/tileset-2d.js +48 -16
- package/dist/esm/tileset-2d/tileset-2d.js.map +1 -0
- package/dist/esm/{tile-layer → tileset-2d}/types.js +0 -0
- package/dist/esm/{tile-layer → tileset-2d}/types.js.map +0 -0
- package/dist/esm/{tile-layer → tileset-2d}/utils.js +16 -20
- package/dist/esm/tileset-2d/utils.js.map +1 -0
- package/dist/esm/trips-layer/trips-layer.js.map +1 -1
- package/dist.min.js +188 -6
- package/package.json +11 -11
- package/src/geo-cell-layer/GeoCellLayer.ts +2 -2
- package/src/geohash-layer/geohash-layer.ts +4 -4
- package/src/great-circle-layer/great-circle-layer.ts +2 -2
- package/src/h3-layers/h3-cluster-layer.ts +2 -2
- package/src/h3-layers/h3-hexagon-layer.ts +4 -1
- package/src/index.ts +9 -5
- package/src/mesh-layer/mesh-layer.ts +1 -1
- package/src/mvt-layer/coordinate-transform.ts +1 -1
- package/src/mvt-layer/mvt-layer.ts +18 -11
- package/src/quadkey-layer/quadkey-layer.ts +1 -1
- package/src/s2-layer/s2-layer.ts +1 -1
- package/src/terrain-layer/terrain-layer.ts +11 -9
- package/src/tile-3d-layer/tile-3d-layer.ts +13 -11
- package/src/tile-layer/tile-layer.ts +23 -11
- package/src/tileset-2d/index.ts +25 -0
- package/src/tileset-2d/memoize.ts +45 -0
- package/src/{tile-layer → tileset-2d}/tile-2d-header.ts +4 -4
- package/src/{tile-layer → tileset-2d}/tile-2d-traversal.ts +3 -1
- package/src/{tile-layer → tileset-2d}/tileset-2d.ts +91 -39
- package/src/{tile-layer → tileset-2d}/types.ts +0 -0
- package/src/{tile-layer → tileset-2d}/utils.ts +26 -12
- package/src/trips-layer/trips-layer.ts +1 -1
- package/typed/geo-cell-layer/GeoCellLayer.d.ts +2 -2
- package/typed/geo-cell-layer/GeoCellLayer.d.ts.map +1 -1
- package/typed/geo-cell-layer/GeoCellLayer.js +49 -0
- package/typed/geohash-layer/geohash-layer.d.ts +3 -3
- package/typed/geohash-layer/geohash-layer.d.ts.map +1 -1
- package/typed/great-circle-layer/great-circle-layer.d.ts +3 -2
- package/typed/great-circle-layer/great-circle-layer.d.ts.map +1 -1
- package/typed/great-circle-layer/great-circle-layer.js +29 -0
- package/typed/h3-layers/h3-cluster-layer.d.ts +1 -1
- package/typed/h3-layers/h3-cluster-layer.d.ts.map +1 -1
- package/typed/h3-layers/h3-cluster-layer.js +33 -0
- package/typed/h3-layers/h3-hexagon-layer.d.ts +1 -1
- package/typed/h3-layers/h3-hexagon-layer.d.ts.map +1 -1
- package/typed/h3-layers/h3-hexagon-layer.js +251 -0
- package/typed/index.d.ts +5 -5
- package/typed/index.d.ts.map +1 -1
- package/typed/index.js +33 -0
- package/typed/mesh-layer/mesh-layer-fragment.glsl.js +55 -0
- package/typed/mesh-layer/mesh-layer-vertex.glsl.js +80 -0
- package/typed/mesh-layer/mesh-layer.d.ts +1 -1
- package/typed/mesh-layer/mesh-layer.d.ts.map +1 -1
- package/typed/mesh-layer/mesh-layer.js +110 -0
- package/typed/mvt-layer/coordinate-transform.d.ts +1 -1
- package/typed/mvt-layer/coordinate-transform.d.ts.map +1 -1
- package/typed/mvt-layer/coordinate-transform.js +41 -0
- package/typed/mvt-layer/find-index-binary.js +96 -0
- package/typed/mvt-layer/mvt-layer.d.ts +3 -4
- package/typed/mvt-layer/mvt-layer.d.ts.map +1 -1
- package/typed/mvt-layer/mvt-layer.js +297 -0
- package/typed/quadkey-layer/quadkey-layer.d.ts +1 -1
- package/typed/quadkey-layer/quadkey-layer.d.ts.map +1 -1
- package/typed/quadkey-layer/quadkey-layer.js +18 -0
- package/typed/quadkey-layer/quadkey-utils.js +26 -0
- package/typed/s2-layer/s2-geometry.js +123 -0
- package/typed/s2-layer/s2-layer.d.ts +1 -1
- package/typed/s2-layer/s2-layer.d.ts.map +1 -1
- package/typed/s2-layer/s2-layer.js +37 -0
- package/typed/s2-layer/s2-utils.js +88 -0
- package/typed/terrain-layer/terrain-layer.d.ts +8 -5
- package/typed/terrain-layer/terrain-layer.d.ts.map +1 -1
- package/typed/terrain-layer/terrain-layer.js +226 -0
- package/typed/tile-3d-layer/tile-3d-layer.d.ts +3 -3
- package/typed/tile-3d-layer/tile-3d-layer.d.ts.map +1 -1
- package/typed/tile-3d-layer/tile-3d-layer.js +294 -0
- package/typed/tile-layer/tile-2d-header.js +113 -0
- package/typed/tile-layer/tile-2d-traversal.js +181 -0
- package/typed/tile-layer/tile-layer.d.ts +6 -7
- package/typed/tile-layer/tile-layer.d.ts.map +1 -1
- package/typed/tile-layer/tile-layer.js +192 -0
- package/typed/tile-layer/tileset-2d.d.ts.map +1 -1
- package/typed/tile-layer/tileset-2d.js +399 -0
- package/typed/tile-layer/types.js +1 -0
- package/typed/tile-layer/utils.d.ts +1 -1
- package/typed/tile-layer/utils.d.ts.map +1 -1
- package/typed/tile-layer/utils.js +197 -0
- package/typed/tileset-2d/index.d.ts +7 -0
- package/typed/tileset-2d/index.d.ts.map +1 -0
- package/typed/tileset-2d/memoize.d.ts +7 -0
- package/typed/tileset-2d/memoize.d.ts.map +1 -0
- package/typed/tileset-2d/tile-2d-header.d.ts +39 -0
- package/typed/tileset-2d/tile-2d-header.d.ts.map +1 -0
- package/typed/tileset-2d/tile-2d-traversal.d.ts +4 -0
- package/typed/tileset-2d/tile-2d-traversal.d.ts.map +1 -0
- package/typed/tileset-2d/tileset-2d.d.ts +121 -0
- package/typed/tileset-2d/tileset-2d.d.ts.map +1 -0
- package/typed/tileset-2d/types.d.ts +30 -0
- package/typed/tileset-2d/types.d.ts.map +1 -0
- package/typed/tileset-2d/utils.d.ts +52 -0
- package/typed/tileset-2d/utils.d.ts.map +1 -0
- package/typed/trips-layer/trips-layer.d.ts +1 -1
- package/typed/trips-layer/trips-layer.d.ts.map +1 -1
- package/typed/trips-layer/trips-layer.js +92 -0
- package/dist/es5/tile-layer/tile-2d-header.js.map +0 -1
- package/dist/es5/tile-layer/tile-2d-traversal.js.map +0 -1
- package/dist/es5/tile-layer/tileset-2d.js.map +0 -1
- package/dist/es5/tile-layer/utils.js.map +0 -1
- package/dist/esm/tile-layer/tile-2d-header.js.map +0 -1
- package/dist/esm/tile-layer/tile-2d-traversal.js.map +0 -1
- package/dist/esm/tile-layer/tileset-2d.js.map +0 -1
- package/dist/esm/tile-layer/utils.js.map +0 -1
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { CompositeLayer, _flatten as flatten } from '@deck.gl/core';
|
|
2
|
+
import { GeoJsonLayer } from '@deck.gl/layers';
|
|
3
|
+
import Tileset2D, { STRATEGY_DEFAULT } from './tileset-2d';
|
|
4
|
+
import { urlType, getURLFromTemplate } from './utils';
|
|
5
|
+
const defaultProps = {
|
|
6
|
+
TilesetClass: Tileset2D,
|
|
7
|
+
data: [],
|
|
8
|
+
dataComparator: urlType.equals,
|
|
9
|
+
renderSubLayers: { type: 'function', value: props => new GeoJsonLayer(props), compare: false },
|
|
10
|
+
getTileData: { type: 'function', optional: true, value: null, compare: false },
|
|
11
|
+
// TODO - change to onViewportLoad to align with Tile3DLayer
|
|
12
|
+
onViewportLoad: { type: 'function', optional: true, value: null, compare: false },
|
|
13
|
+
onTileLoad: { type: 'function', value: tile => { }, compare: false },
|
|
14
|
+
onTileUnload: { type: 'function', value: tile => { }, compare: false },
|
|
15
|
+
// eslint-disable-next-line
|
|
16
|
+
onTileError: { type: 'function', value: err => console.error(err), compare: false },
|
|
17
|
+
extent: { type: 'array', optional: true, value: null, compare: true },
|
|
18
|
+
tileSize: 512,
|
|
19
|
+
maxZoom: null,
|
|
20
|
+
minZoom: 0,
|
|
21
|
+
maxCacheSize: null,
|
|
22
|
+
maxCacheByteSize: null,
|
|
23
|
+
refinementStrategy: STRATEGY_DEFAULT,
|
|
24
|
+
zRange: null,
|
|
25
|
+
maxRequests: 6,
|
|
26
|
+
zoomOffset: 0
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The TileLayer is a composite layer that makes it possible to visualize very large datasets.
|
|
30
|
+
*
|
|
31
|
+
* Instead of fetching the entire dataset, it only loads and renders what's visible in the current viewport.
|
|
32
|
+
*/
|
|
33
|
+
export default class TileLayer extends CompositeLayer {
|
|
34
|
+
initializeState() {
|
|
35
|
+
this.state = {
|
|
36
|
+
tileset: null,
|
|
37
|
+
isLoaded: false
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
finalizeState() {
|
|
41
|
+
this.state?.tileset?.finalize();
|
|
42
|
+
}
|
|
43
|
+
get isLoaded() {
|
|
44
|
+
return this.state?.tileset?.selectedTiles.every(tile => tile.isLoaded && tile.layers && tile.layers.every(layer => layer.isLoaded));
|
|
45
|
+
}
|
|
46
|
+
shouldUpdateState({ changeFlags }) {
|
|
47
|
+
return changeFlags.somethingChanged;
|
|
48
|
+
}
|
|
49
|
+
updateState({ changeFlags }) {
|
|
50
|
+
let { tileset } = this.state;
|
|
51
|
+
const propsChanged = changeFlags.propsOrDataChanged || changeFlags.updateTriggersChanged;
|
|
52
|
+
const dataChanged = changeFlags.dataChanged ||
|
|
53
|
+
(changeFlags.updateTriggersChanged &&
|
|
54
|
+
(changeFlags.updateTriggersChanged.all || changeFlags.updateTriggersChanged.getTileData));
|
|
55
|
+
if (!tileset) {
|
|
56
|
+
tileset = new this.props.TilesetClass(this._getTilesetOptions());
|
|
57
|
+
this.setState({ tileset });
|
|
58
|
+
}
|
|
59
|
+
else if (propsChanged) {
|
|
60
|
+
tileset.setOptions(this._getTilesetOptions());
|
|
61
|
+
if (dataChanged) {
|
|
62
|
+
// reload all tiles
|
|
63
|
+
// use cached layers until new content is loaded
|
|
64
|
+
tileset.reloadAll();
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// some render options changed, regenerate sub layers now
|
|
68
|
+
this.state.tileset.tiles.forEach(tile => {
|
|
69
|
+
tile.layers = null;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
this._updateTileset();
|
|
74
|
+
}
|
|
75
|
+
_getTilesetOptions() {
|
|
76
|
+
const { tileSize, maxCacheSize, maxCacheByteSize, refinementStrategy, extent, maxZoom, minZoom, maxRequests, zoomOffset } = this.props;
|
|
77
|
+
return {
|
|
78
|
+
maxCacheSize,
|
|
79
|
+
maxCacheByteSize,
|
|
80
|
+
maxZoom,
|
|
81
|
+
minZoom,
|
|
82
|
+
tileSize,
|
|
83
|
+
refinementStrategy,
|
|
84
|
+
extent,
|
|
85
|
+
maxRequests,
|
|
86
|
+
zoomOffset,
|
|
87
|
+
getTileData: this.getTileData.bind(this),
|
|
88
|
+
onTileLoad: this._onTileLoad.bind(this),
|
|
89
|
+
onTileError: this._onTileError.bind(this),
|
|
90
|
+
onTileUnload: this._onTileUnload.bind(this)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
_updateTileset() {
|
|
94
|
+
const { tileset } = this.state;
|
|
95
|
+
const { zRange, modelMatrix } = this.props;
|
|
96
|
+
const frameNumber = tileset.update(this.context.viewport, { zRange, modelMatrix });
|
|
97
|
+
const { isLoaded } = tileset;
|
|
98
|
+
const loadingStateChanged = this.state.isLoaded !== isLoaded;
|
|
99
|
+
const tilesetChanged = this.state.frameNumber !== frameNumber;
|
|
100
|
+
if (isLoaded && (loadingStateChanged || tilesetChanged)) {
|
|
101
|
+
this._onViewportLoad();
|
|
102
|
+
}
|
|
103
|
+
if (tilesetChanged) {
|
|
104
|
+
// Save the tileset frame number - trigger a rerender
|
|
105
|
+
this.setState({ frameNumber });
|
|
106
|
+
}
|
|
107
|
+
// Save the loaded state - should not trigger a rerender
|
|
108
|
+
this.state.isLoaded = isLoaded;
|
|
109
|
+
}
|
|
110
|
+
_onViewportLoad() {
|
|
111
|
+
const { tileset } = this.state;
|
|
112
|
+
const { onViewportLoad } = this.props;
|
|
113
|
+
if (onViewportLoad) {
|
|
114
|
+
onViewportLoad(tileset.selectedTiles);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
_onTileLoad(tile) {
|
|
118
|
+
this.props.onTileLoad(tile);
|
|
119
|
+
tile.layers = null;
|
|
120
|
+
this.setNeedsUpdate();
|
|
121
|
+
}
|
|
122
|
+
_onTileError(error, tile) {
|
|
123
|
+
this.props.onTileError(error);
|
|
124
|
+
tile.layers = null;
|
|
125
|
+
this.setNeedsUpdate();
|
|
126
|
+
}
|
|
127
|
+
_onTileUnload(tile) {
|
|
128
|
+
this.props.onTileUnload(tile);
|
|
129
|
+
}
|
|
130
|
+
// Methods for subclass to override
|
|
131
|
+
getTileData(tile) {
|
|
132
|
+
const { data, getTileData, fetch } = this.props;
|
|
133
|
+
const { signal } = tile;
|
|
134
|
+
tile.url =
|
|
135
|
+
typeof data === 'string' || Array.isArray(data) ? getURLFromTemplate(data, tile) : null;
|
|
136
|
+
if (getTileData) {
|
|
137
|
+
return getTileData(tile);
|
|
138
|
+
}
|
|
139
|
+
if (fetch && tile.url) {
|
|
140
|
+
return fetch(tile.url, { propName: 'data', layer: this, signal });
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
renderSubLayers(props) {
|
|
145
|
+
return this.props.renderSubLayers(props);
|
|
146
|
+
}
|
|
147
|
+
getSubLayerPropsByTile(tile) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
getPickingInfo({ info, sourceLayer }) {
|
|
151
|
+
info.tile = sourceLayer.props.tile;
|
|
152
|
+
return info;
|
|
153
|
+
}
|
|
154
|
+
_updateAutoHighlight(info) {
|
|
155
|
+
if (info.sourceLayer) {
|
|
156
|
+
info.sourceLayer.updateAutoHighlight(info);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
renderLayers() {
|
|
160
|
+
return this.state.tileset.tiles.map((tile) => {
|
|
161
|
+
const subLayerProps = this.getSubLayerPropsByTile(tile);
|
|
162
|
+
// cache the rendered layer in the tile
|
|
163
|
+
if (!tile.isLoaded && !tile.content) {
|
|
164
|
+
// nothing to show
|
|
165
|
+
}
|
|
166
|
+
else if (!tile.layers) {
|
|
167
|
+
const layers = this.renderSubLayers({
|
|
168
|
+
...this.props,
|
|
169
|
+
id: `${this.id}-${tile.id}`,
|
|
170
|
+
data: tile.content,
|
|
171
|
+
_offset: 0,
|
|
172
|
+
tile
|
|
173
|
+
});
|
|
174
|
+
tile.layers = flatten(layers, Boolean).map(layer => layer.clone({
|
|
175
|
+
tile,
|
|
176
|
+
...subLayerProps
|
|
177
|
+
}));
|
|
178
|
+
}
|
|
179
|
+
else if (subLayerProps &&
|
|
180
|
+
tile.layers[0] &&
|
|
181
|
+
Object.keys(subLayerProps).some(propName => tile.layers[0].props[propName] !== subLayerProps[propName])) {
|
|
182
|
+
tile.layers = tile.layers.map(layer => layer.clone(subLayerProps));
|
|
183
|
+
}
|
|
184
|
+
return tile.layers;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
filterSubLayer({ layer }) {
|
|
188
|
+
return layer.props.tile.isVisible;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
TileLayer.defaultProps = defaultProps;
|
|
192
|
+
TileLayer.layerName = 'TileLayer';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tileset-2d.d.ts","sourceRoot":"","sources":["../../src/tile-layer/tileset-2d.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAG5C,OAAO,EAAC,OAAO,EAAS,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,EAAS,SAAS,EAAE,MAAM,EAAC,MAAM,SAAS,CAAC;AAClD,OAAO,EAAC,cAAc,EAAC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G,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAMtD,uCAAuC;IACvC,cAAc,CAAC,KAAK,EAAE,SAAS;;;;;IAQ/B,OAAO,CAAC,gBAAgB;IAoCxB,OAAO,CAAC,cAAc,CAA0B;IAEhD,OAAO,CAAC,cAAc;IAwBtB,OAAO,CAAC,YAAY;IAqBpB;;OAEG;IAEH,OAAO,CAAC,YAAY;IAmCpB,OAAO,CAAC,QAAQ;IA8BhB,mBAAmB,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,GAAG,IAAI;CAa7D"}
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import Tile2DHeader from './tile-2d-header';
|
|
2
|
+
import { getTileIndices, tileToBoundingBox } from './utils';
|
|
3
|
+
import { RequestScheduler } from '@loaders.gl/loader-utils';
|
|
4
|
+
import { Matrix4 } from '@math.gl/core';
|
|
5
|
+
// bit masks
|
|
6
|
+
const TILE_STATE_VISITED = 1;
|
|
7
|
+
const TILE_STATE_VISIBLE = 2;
|
|
8
|
+
/*
|
|
9
|
+
show cached parent tile if children are loading
|
|
10
|
+
+-----------+ +-----+ +-----+-----+
|
|
11
|
+
| | | | | | |
|
|
12
|
+
| | | | | | |
|
|
13
|
+
| | --> +-----+-----+ -> +-----+-----+
|
|
14
|
+
| | | | | | |
|
|
15
|
+
| | | | | | |
|
|
16
|
+
+-----------+ +-----+ +-----+-----+
|
|
17
|
+
|
|
18
|
+
show cached children tiles when parent is loading
|
|
19
|
+
+-------+---- +------------
|
|
20
|
+
| | |
|
|
21
|
+
| | |
|
|
22
|
+
| | |
|
|
23
|
+
+-------+---- --> |
|
|
24
|
+
| | |
|
|
25
|
+
*/
|
|
26
|
+
export const STRATEGY_NEVER = 'never';
|
|
27
|
+
export const STRATEGY_REPLACE = 'no-overlap';
|
|
28
|
+
export const STRATEGY_DEFAULT = 'best-available';
|
|
29
|
+
const DEFAULT_CACHE_SCALE = 5;
|
|
30
|
+
const STRATEGIES = {
|
|
31
|
+
[STRATEGY_DEFAULT]: updateTileStateDefault,
|
|
32
|
+
[STRATEGY_REPLACE]: updateTileStateReplace,
|
|
33
|
+
[STRATEGY_NEVER]: () => { }
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Manages loading and purging of tile data. This class caches recently visited tiles
|
|
37
|
+
* and only creates new tiles if they are present.
|
|
38
|
+
*/
|
|
39
|
+
export default class Tileset2D {
|
|
40
|
+
/**
|
|
41
|
+
* Takes in a function that returns tile data, a cache size, and a max and a min zoom level.
|
|
42
|
+
* Cache size defaults to 5 * number of tiles in the current viewport
|
|
43
|
+
*/
|
|
44
|
+
constructor(opts) {
|
|
45
|
+
this.opts = opts;
|
|
46
|
+
this.onTileLoad = tile => {
|
|
47
|
+
this.opts.onTileLoad(tile);
|
|
48
|
+
if (this.opts.maxCacheByteSize) {
|
|
49
|
+
this._cacheByteSize += tile.byteLength;
|
|
50
|
+
this._resizeCache();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
this._requestScheduler = new RequestScheduler({
|
|
54
|
+
maxRequests: opts.maxRequests,
|
|
55
|
+
throttleRequests: opts.maxRequests > 0
|
|
56
|
+
});
|
|
57
|
+
// Maps tile id in string {z}-{x}-{y} to a Tile object
|
|
58
|
+
this._cache = new Map();
|
|
59
|
+
this._tiles = [];
|
|
60
|
+
this._dirty = false;
|
|
61
|
+
this._cacheByteSize = 0;
|
|
62
|
+
// Cache the last processed viewport
|
|
63
|
+
this._viewport = null;
|
|
64
|
+
this._selectedTiles = null;
|
|
65
|
+
this._frameNumber = 0;
|
|
66
|
+
this._modelMatrix = new Matrix4();
|
|
67
|
+
this._modelMatrixInverse = new Matrix4();
|
|
68
|
+
this.setOptions(opts);
|
|
69
|
+
}
|
|
70
|
+
/* Public API */
|
|
71
|
+
get tiles() {
|
|
72
|
+
return this._tiles;
|
|
73
|
+
}
|
|
74
|
+
get selectedTiles() {
|
|
75
|
+
return this._selectedTiles;
|
|
76
|
+
}
|
|
77
|
+
get isLoaded() {
|
|
78
|
+
return this._selectedTiles !== null && this._selectedTiles.every(tile => tile.isLoaded);
|
|
79
|
+
}
|
|
80
|
+
get needsReload() {
|
|
81
|
+
return this._selectedTiles !== null && this._selectedTiles.some(tile => tile.needsReload);
|
|
82
|
+
}
|
|
83
|
+
setOptions(opts) {
|
|
84
|
+
Object.assign(this.opts, opts);
|
|
85
|
+
if (Number.isFinite(opts.maxZoom)) {
|
|
86
|
+
this._maxZoom = Math.floor(opts.maxZoom);
|
|
87
|
+
}
|
|
88
|
+
if (Number.isFinite(opts.minZoom)) {
|
|
89
|
+
this._minZoom = Math.ceil(opts.minZoom);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Clean up any outstanding tile requests.
|
|
93
|
+
finalize() {
|
|
94
|
+
for (const tile of this._cache.values()) {
|
|
95
|
+
if (tile.isLoading) {
|
|
96
|
+
tile.abort();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
this._cache.clear();
|
|
100
|
+
this._tiles = [];
|
|
101
|
+
this._selectedTiles = null;
|
|
102
|
+
}
|
|
103
|
+
reloadAll() {
|
|
104
|
+
for (const id of this._cache.keys()) {
|
|
105
|
+
const tile = this._cache.get(id);
|
|
106
|
+
if (!this._selectedTiles || !this._selectedTiles.includes(tile)) {
|
|
107
|
+
this._cache.delete(id);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
tile.setNeedsReload();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Update the cache with the given viewport and model matrix and triggers callback onUpdate.
|
|
116
|
+
*/
|
|
117
|
+
update(viewport, { zRange, modelMatrix } = {}) {
|
|
118
|
+
const modelMatrixAsMatrix4 = new Matrix4(modelMatrix);
|
|
119
|
+
const isModelMatrixNew = !modelMatrixAsMatrix4.equals(this._modelMatrix);
|
|
120
|
+
if (!this._viewport || !viewport.equals(this._viewport) || isModelMatrixNew) {
|
|
121
|
+
if (isModelMatrixNew) {
|
|
122
|
+
this._modelMatrixInverse = modelMatrixAsMatrix4.clone().invert();
|
|
123
|
+
this._modelMatrix = modelMatrixAsMatrix4;
|
|
124
|
+
}
|
|
125
|
+
this._viewport = viewport;
|
|
126
|
+
const tileIndices = this.getTileIndices({
|
|
127
|
+
viewport,
|
|
128
|
+
maxZoom: this._maxZoom,
|
|
129
|
+
minZoom: this._minZoom,
|
|
130
|
+
zRange,
|
|
131
|
+
modelMatrix: this._modelMatrix,
|
|
132
|
+
modelMatrixInverse: this._modelMatrixInverse
|
|
133
|
+
});
|
|
134
|
+
this._selectedTiles = tileIndices.map(index => this._getTile(index, true));
|
|
135
|
+
if (this._dirty) {
|
|
136
|
+
// Some new tiles are added
|
|
137
|
+
this._rebuildTree();
|
|
138
|
+
}
|
|
139
|
+
// Check for needed reloads explicitly even if the view/matrix has not changed.
|
|
140
|
+
}
|
|
141
|
+
else if (this.needsReload) {
|
|
142
|
+
this._selectedTiles = this._selectedTiles.map(tile => this._getTile(tile.index, true));
|
|
143
|
+
}
|
|
144
|
+
// Update tile states
|
|
145
|
+
const changed = this.updateTileStates();
|
|
146
|
+
this._pruneRequests();
|
|
147
|
+
if (this._dirty) {
|
|
148
|
+
// cache size is either the user defined maxSize or 5 * number of current tiles in the viewport.
|
|
149
|
+
this._resizeCache();
|
|
150
|
+
}
|
|
151
|
+
if (changed) {
|
|
152
|
+
this._frameNumber++;
|
|
153
|
+
}
|
|
154
|
+
return this._frameNumber;
|
|
155
|
+
}
|
|
156
|
+
/* Public interface for subclassing */
|
|
157
|
+
/** Returns array of tile indices in the current viewport */
|
|
158
|
+
getTileIndices({ viewport, maxZoom, minZoom, zRange, modelMatrix, modelMatrixInverse }) {
|
|
159
|
+
const { tileSize, extent, zoomOffset } = this.opts;
|
|
160
|
+
return getTileIndices({
|
|
161
|
+
viewport,
|
|
162
|
+
maxZoom,
|
|
163
|
+
minZoom,
|
|
164
|
+
zRange,
|
|
165
|
+
tileSize,
|
|
166
|
+
extent: extent,
|
|
167
|
+
modelMatrix,
|
|
168
|
+
modelMatrixInverse,
|
|
169
|
+
zoomOffset
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/** Returns unique string key for a tile index */
|
|
173
|
+
getTileId(index) {
|
|
174
|
+
return `${index.x}-${index.y}-${index.z}`;
|
|
175
|
+
}
|
|
176
|
+
/** Returns a zoom level for a tile index */
|
|
177
|
+
getTileZoom(index) {
|
|
178
|
+
return index.z;
|
|
179
|
+
}
|
|
180
|
+
/** Returns additional metadata to add to tile, bbox by default */
|
|
181
|
+
getTileMetadata(index) {
|
|
182
|
+
const { tileSize } = this.opts;
|
|
183
|
+
// @ts-expect-error
|
|
184
|
+
return { bbox: tileToBoundingBox(this._viewport, index.x, index.y, index.z, tileSize) };
|
|
185
|
+
}
|
|
186
|
+
/** Returns index of the parent tile */
|
|
187
|
+
getParentIndex(index) {
|
|
188
|
+
const x = Math.floor(index.x / 2);
|
|
189
|
+
const y = Math.floor(index.y / 2);
|
|
190
|
+
const z = index.z - 1;
|
|
191
|
+
return { x, y, z };
|
|
192
|
+
}
|
|
193
|
+
// Returns true if any tile's visibility changed
|
|
194
|
+
updateTileStates() {
|
|
195
|
+
const refinementStrategy = this.opts.refinementStrategy || STRATEGY_DEFAULT;
|
|
196
|
+
const visibilities = new Array(this._cache.size);
|
|
197
|
+
let i = 0;
|
|
198
|
+
// Reset state
|
|
199
|
+
for (const tile of this._cache.values()) {
|
|
200
|
+
// save previous state
|
|
201
|
+
visibilities[i++] = tile.isVisible;
|
|
202
|
+
tile.isSelected = false;
|
|
203
|
+
tile.isVisible = false;
|
|
204
|
+
}
|
|
205
|
+
// @ts-expect-error called only when _selectedTiles is already defined
|
|
206
|
+
for (const tile of this._selectedTiles) {
|
|
207
|
+
tile.isSelected = true;
|
|
208
|
+
tile.isVisible = true;
|
|
209
|
+
}
|
|
210
|
+
// Strategy-specific state logic
|
|
211
|
+
(typeof refinementStrategy === 'function'
|
|
212
|
+
? refinementStrategy
|
|
213
|
+
: STRATEGIES[refinementStrategy])(Array.from(this._cache.values()));
|
|
214
|
+
i = 0;
|
|
215
|
+
// Check if any visibility has changed
|
|
216
|
+
for (const tile of this._cache.values()) {
|
|
217
|
+
if (visibilities[i++] !== tile.isVisible) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
/* Private methods */
|
|
224
|
+
_pruneRequests() {
|
|
225
|
+
const { maxRequests } = this.opts;
|
|
226
|
+
const abortCandidates = [];
|
|
227
|
+
let ongoingRequestCount = 0;
|
|
228
|
+
for (const tile of this._cache.values()) {
|
|
229
|
+
// Keep track of all the ongoing requests
|
|
230
|
+
if (tile.isLoading) {
|
|
231
|
+
ongoingRequestCount++;
|
|
232
|
+
if (!tile.isSelected && !tile.isVisible) {
|
|
233
|
+
abortCandidates.push(tile);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
while (maxRequests > 0 && ongoingRequestCount > maxRequests && abortCandidates.length > 0) {
|
|
238
|
+
// There are too many ongoing requests, so abort some that are unselected
|
|
239
|
+
const tile = abortCandidates.shift();
|
|
240
|
+
tile.abort();
|
|
241
|
+
ongoingRequestCount--;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
// This needs to be called every time some tiles have been added/removed from cache
|
|
245
|
+
_rebuildTree() {
|
|
246
|
+
const { _cache } = this;
|
|
247
|
+
// Reset states
|
|
248
|
+
for (const tile of _cache.values()) {
|
|
249
|
+
tile.parent = null;
|
|
250
|
+
if (tile.children) {
|
|
251
|
+
tile.children.length = 0;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
// Rebuild tree
|
|
255
|
+
for (const tile of _cache.values()) {
|
|
256
|
+
const parent = this._getNearestAncestor(tile);
|
|
257
|
+
tile.parent = parent;
|
|
258
|
+
if (parent?.children) {
|
|
259
|
+
parent.children.push(tile);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Clear tiles that are not visible when the cache is full
|
|
265
|
+
*/
|
|
266
|
+
/* eslint-disable complexity */
|
|
267
|
+
_resizeCache() {
|
|
268
|
+
const { _cache, opts } = this;
|
|
269
|
+
const maxCacheSize = opts.maxCacheSize ||
|
|
270
|
+
// @ts-expect-error called only when selectedTiles is initialized
|
|
271
|
+
(opts.maxCacheByteSize ? Infinity : DEFAULT_CACHE_SCALE * this.selectedTiles.length);
|
|
272
|
+
const maxCacheByteSize = opts.maxCacheByteSize || Infinity;
|
|
273
|
+
const overflown = _cache.size > maxCacheSize || this._cacheByteSize > maxCacheByteSize;
|
|
274
|
+
if (overflown) {
|
|
275
|
+
for (const [id, tile] of _cache) {
|
|
276
|
+
if (!tile.isVisible) {
|
|
277
|
+
// delete tile
|
|
278
|
+
this._cacheByteSize -= opts.maxCacheByteSize ? tile.byteLength : 0;
|
|
279
|
+
_cache.delete(id);
|
|
280
|
+
this.opts.onTileUnload(tile);
|
|
281
|
+
}
|
|
282
|
+
if (_cache.size <= maxCacheSize && this._cacheByteSize <= maxCacheByteSize) {
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
this._rebuildTree();
|
|
287
|
+
this._dirty = true;
|
|
288
|
+
}
|
|
289
|
+
if (this._dirty) {
|
|
290
|
+
// sort by zoom level so that smaller tiles are displayed on top
|
|
291
|
+
this._tiles = Array.from(this._cache.values()).sort((t1, t2) => t1.zoom - t2.zoom);
|
|
292
|
+
this._dirty = false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
_getTile(index, create) {
|
|
296
|
+
const id = this.getTileId(index);
|
|
297
|
+
let tile = this._cache.get(id);
|
|
298
|
+
let needsReload = false;
|
|
299
|
+
if (!tile && create) {
|
|
300
|
+
tile = new Tile2DHeader(index);
|
|
301
|
+
Object.assign(tile, this.getTileMetadata(tile.index));
|
|
302
|
+
Object.assign(tile, { id, zoom: this.getTileZoom(tile.index) });
|
|
303
|
+
needsReload = true;
|
|
304
|
+
this._cache.set(id, tile);
|
|
305
|
+
this._dirty = true;
|
|
306
|
+
}
|
|
307
|
+
else if (tile && tile.needsReload) {
|
|
308
|
+
needsReload = true;
|
|
309
|
+
}
|
|
310
|
+
if (tile && needsReload) {
|
|
311
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
312
|
+
tile.loadData({
|
|
313
|
+
getData: this.opts.getTileData,
|
|
314
|
+
requestScheduler: this._requestScheduler,
|
|
315
|
+
onLoad: this.onTileLoad,
|
|
316
|
+
onError: this.opts.onTileError
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
return tile;
|
|
320
|
+
}
|
|
321
|
+
_getNearestAncestor(tile) {
|
|
322
|
+
const { _minZoom = 0 } = this;
|
|
323
|
+
let index = tile.index;
|
|
324
|
+
while (this.getTileZoom(index) > _minZoom) {
|
|
325
|
+
index = this.getParentIndex(index);
|
|
326
|
+
const parent = this._getTile(index);
|
|
327
|
+
if (parent) {
|
|
328
|
+
return parent;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
/* -- Refinement strategies --*/
|
|
335
|
+
/* eslint-disable max-depth */
|
|
336
|
+
// For all the selected && pending tiles:
|
|
337
|
+
// - pick the closest ancestor as placeholder
|
|
338
|
+
// - if no ancestor is visible, pick the closest children as placeholder
|
|
339
|
+
function updateTileStateDefault(allTiles) {
|
|
340
|
+
for (const tile of allTiles) {
|
|
341
|
+
tile.state = 0;
|
|
342
|
+
}
|
|
343
|
+
for (const tile of allTiles) {
|
|
344
|
+
if (tile.isSelected && !getPlaceholderInAncestors(tile)) {
|
|
345
|
+
getPlaceholderInChildren(tile);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
for (const tile of allTiles) {
|
|
349
|
+
tile.isVisible = Boolean(tile.state & TILE_STATE_VISIBLE);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// Until a selected tile and all its selected siblings are loaded, use the closest ancestor as placeholder
|
|
353
|
+
function updateTileStateReplace(allTiles) {
|
|
354
|
+
for (const tile of allTiles) {
|
|
355
|
+
tile.state = 0;
|
|
356
|
+
}
|
|
357
|
+
for (const tile of allTiles) {
|
|
358
|
+
if (tile.isSelected) {
|
|
359
|
+
getPlaceholderInAncestors(tile);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
// Always process parents first
|
|
363
|
+
const sortedTiles = Array.from(allTiles).sort((t1, t2) => t1.zoom - t2.zoom);
|
|
364
|
+
for (const tile of sortedTiles) {
|
|
365
|
+
tile.isVisible = Boolean(tile.state & TILE_STATE_VISIBLE);
|
|
366
|
+
if (tile.children && (tile.isVisible || tile.state & TILE_STATE_VISITED)) {
|
|
367
|
+
// If the tile is rendered, or if the tile has been explicitly hidden, hide all of its children
|
|
368
|
+
for (const child of tile.children) {
|
|
369
|
+
child.state = TILE_STATE_VISITED;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
else if (tile.isSelected) {
|
|
373
|
+
getPlaceholderInChildren(tile);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
// Walk up the tree until we find one ancestor that is loaded. Returns true if successful.
|
|
378
|
+
function getPlaceholderInAncestors(startTile) {
|
|
379
|
+
let tile = startTile;
|
|
380
|
+
while (tile) {
|
|
381
|
+
if (tile.isLoaded || tile.content) {
|
|
382
|
+
tile.state |= TILE_STATE_VISIBLE;
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
tile = tile.parent;
|
|
386
|
+
}
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
// Recursively set children as placeholder
|
|
390
|
+
function getPlaceholderInChildren(tile) {
|
|
391
|
+
for (const child of tile.children) {
|
|
392
|
+
if (child.isLoaded || child.content) {
|
|
393
|
+
child.state |= TILE_STATE_VISIBLE;
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
getPlaceholderInChildren(child);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -24,7 +24,7 @@ export declare function getCullBounds({ viewport, z, cullRect }: {
|
|
|
24
24
|
width: number;
|
|
25
25
|
height: number;
|
|
26
26
|
};
|
|
27
|
-
}): [number, number, number, number];
|
|
27
|
+
}): [number, number, number, number][];
|
|
28
28
|
export declare function osmTile2lngLat(x: number, y: number, z: number): [number, number];
|
|
29
29
|
export declare function tileToBoundingBox(viewport: Viewport, x: number, y: number, z: number, tileSize?: number): TileBoundingBox;
|
|
30
30
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/tile-layer/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAC,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,SAAS,CAAC;AAKnF,eAAO,MAAM,OAAO;;;;;CAyBnB,CAAC;AA8BF,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,EAC3B,IAAI,EAAE;IACJ,KAAK,EAAE,SAAS,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;CACZ,GACA,MAAM,GAAG,IAAI,CAsBf;AAsCD,wCAAwC;AACxC,wBAAgB,aAAa,CAAC,EAC5B,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/tile-layer/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAC,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS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