@deck.gl-community/geo-layers 9.2.8 → 9.3.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/global-grid-layer/global-grid-cluster-layer.d.ts.map +1 -1
- package/dist/global-grid-layer/global-grid-cluster-layer.js +1 -0
- package/dist/global-grid-layer/global-grid-cluster-layer.js.map +1 -1
- package/dist/index.cjs +1799 -7
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/shared-tile-2d-layer/deck-tile-traversal.d.ts +5 -0
- package/dist/shared-tile-2d-layer/deck-tile-traversal.d.ts.map +1 -0
- package/dist/shared-tile-2d-layer/deck-tile-traversal.js +173 -0
- package/dist/shared-tile-2d-layer/deck-tile-traversal.js.map +1 -0
- package/dist/shared-tile-2d-layer/deck-tileset-adapter.d.ts +26 -0
- package/dist/shared-tile-2d-layer/deck-tileset-adapter.d.ts.map +1 -0
- package/dist/shared-tile-2d-layer/deck-tileset-adapter.js +174 -0
- package/dist/shared-tile-2d-layer/deck-tileset-adapter.js.map +1 -0
- package/dist/shared-tile-2d-layer/index.d.ts +4 -0
- package/dist/shared-tile-2d-layer/index.d.ts.map +1 -0
- package/dist/shared-tile-2d-layer/index.js +6 -0
- package/dist/shared-tile-2d-layer/index.js.map +1 -0
- package/dist/shared-tile-2d-layer/shared-tile-2d-layer.d.ts +151 -0
- package/dist/shared-tile-2d-layer/shared-tile-2d-layer.d.ts.map +1 -0
- package/dist/shared-tile-2d-layer/shared-tile-2d-layer.js +422 -0
- package/dist/shared-tile-2d-layer/shared-tile-2d-layer.js.map +1 -0
- package/dist/shared-tile-2d-layer/shared-tile-2d-view.d.ts +57 -0
- package/dist/shared-tile-2d-layer/shared-tile-2d-view.d.ts.map +1 -0
- package/dist/shared-tile-2d-layer/shared-tile-2d-view.js +253 -0
- package/dist/shared-tile-2d-layer/shared-tile-2d-view.js.map +1 -0
- package/dist/shared-tile-2d-layer/url-template.d.ts +9 -0
- package/dist/shared-tile-2d-layer/url-template.d.ts.map +1 -0
- package/dist/shared-tile-2d-layer/url-template.js +25 -0
- package/dist/shared-tile-2d-layer/url-template.js.map +1 -0
- package/dist/tile-grid-layer/tile-grid-layer.d.ts +47 -0
- package/dist/tile-grid-layer/tile-grid-layer.d.ts.map +1 -0
- package/dist/tile-grid-layer/tile-grid-layer.js +94 -0
- package/dist/tile-grid-layer/tile-grid-layer.js.map +1 -0
- package/dist/tile-source-layer/tile-source-layer.d.ts +2 -2
- package/dist/tile-source-layer/tile-source-layer.d.ts.map +1 -1
- package/dist/tileset/adapter.d.ts +38 -0
- package/dist/tileset/adapter.d.ts.map +1 -0
- package/dist/tileset/adapter.js +5 -0
- package/dist/tileset/adapter.js.map +1 -0
- package/dist/tileset/index.cjs +721 -0
- package/dist/tileset/index.cjs.map +7 -0
- package/dist/tileset/index.d.ts +8 -0
- package/dist/tileset/index.d.ts.map +1 -0
- package/dist/tileset/index.js +7 -0
- package/dist/tileset/index.js.map +1 -0
- package/dist/tileset/tile-2d-header.d.ts +71 -0
- package/dist/tileset/tile-2d-header.d.ts.map +1 -0
- package/dist/tileset/tile-2d-header.js +168 -0
- package/dist/tileset/tile-2d-header.js.map +1 -0
- package/dist/tileset/tileset-2d.d.ts +210 -0
- package/dist/tileset/tileset-2d.d.ts.map +1 -0
- package/dist/tileset/tileset-2d.js +531 -0
- package/dist/tileset/tileset-2d.js.map +1 -0
- package/dist/tileset/types.d.ts +44 -0
- package/dist/tileset/types.d.ts.map +1 -0
- package/dist/tileset/types.js +5 -0
- package/dist/tileset/types.js.map +1 -0
- package/dist/utils/memoize.d.ts +2 -0
- package/dist/utils/memoize.d.ts.map +1 -0
- package/dist/utils/memoize.js +36 -0
- package/dist/utils/memoize.js.map +1 -0
- package/package.json +17 -11
- package/src/global-grid-layer/global-grid-cluster-layer.ts +1 -1
- package/src/index.ts +14 -0
- package/src/shared-tile-2d-layer/deck-tile-traversal.ts +247 -0
- package/src/shared-tile-2d-layer/deck-tileset-adapter.ts +262 -0
- package/src/shared-tile-2d-layer/index.ts +7 -0
- package/src/shared-tile-2d-layer/shared-tile-2d-layer.ts +681 -0
- package/src/shared-tile-2d-layer/shared-tile-2d-view.ts +339 -0
- package/src/shared-tile-2d-layer/url-template.ts +40 -0
- package/src/tile-grid-layer/tile-grid-layer.ts +158 -0
- package/src/tile-source-layer/tile-source-layer.ts +2 -2
- package/src/tileset/adapter.ts +47 -0
- package/src/tileset/index.ts +22 -0
- package/src/tileset/tile-2d-header.ts +210 -0
- package/src/tileset/tileset-2d.ts +705 -0
- package/src/tileset/types.ts +38 -0
- package/src/utils/memoize.ts +38 -0
|
@@ -0,0 +1,721 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// dist/tileset/index.js
|
|
20
|
+
var tileset_exports = {};
|
|
21
|
+
__export(tileset_exports, {
|
|
22
|
+
STRATEGY_DEFAULT: () => STRATEGY_DEFAULT,
|
|
23
|
+
STRATEGY_NEVER: () => STRATEGY_NEVER,
|
|
24
|
+
STRATEGY_REPLACE: () => STRATEGY_REPLACE,
|
|
25
|
+
SharedTile2DHeader: () => SharedTile2DHeader,
|
|
26
|
+
SharedTileset2D: () => SharedTileset2D
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(tileset_exports);
|
|
29
|
+
|
|
30
|
+
// dist/tileset/tileset-2d.js
|
|
31
|
+
var import_loader_utils = require("@loaders.gl/loader-utils");
|
|
32
|
+
var import_stats = require("@probe.gl/stats");
|
|
33
|
+
|
|
34
|
+
// dist/tileset/tile-2d-header.js
|
|
35
|
+
var SharedTile2DHeader = class {
|
|
36
|
+
/** x/y/z tile coordinate. */
|
|
37
|
+
index;
|
|
38
|
+
/** Closest cached ancestor tile in the current tree. */
|
|
39
|
+
parent;
|
|
40
|
+
/** Cached child tiles beneath this tile. */
|
|
41
|
+
children;
|
|
42
|
+
/** Loaded tile payload. */
|
|
43
|
+
content;
|
|
44
|
+
/** Stable tile cache id. */
|
|
45
|
+
id;
|
|
46
|
+
/** Resolved zoom level for the tile. */
|
|
47
|
+
zoom;
|
|
48
|
+
/** Optional application data associated with the tile. */
|
|
49
|
+
userData;
|
|
50
|
+
/** Bounds represented as `[[minX, minY], [maxX, maxY]]` for loaders.gl compatibility. */
|
|
51
|
+
boundingBox;
|
|
52
|
+
/** Abort controller for the current request, if one exists. */
|
|
53
|
+
_abortController;
|
|
54
|
+
/** Promise tracking the in-flight tile load, if any. */
|
|
55
|
+
_loader;
|
|
56
|
+
/** Monotonic request id used to ignore stale responses. */
|
|
57
|
+
_loaderId;
|
|
58
|
+
/** Indicates whether the last request completed successfully. */
|
|
59
|
+
_isLoaded;
|
|
60
|
+
/** Indicates whether the current request was cancelled. */
|
|
61
|
+
_isCancelled;
|
|
62
|
+
/** Indicates whether the tile should be refreshed. */
|
|
63
|
+
_needsReload;
|
|
64
|
+
/** Structured bounds assigned when the tile is created. */
|
|
65
|
+
_bbox;
|
|
66
|
+
/** Creates a tile header for a specific tile index. */
|
|
67
|
+
constructor(index) {
|
|
68
|
+
this.index = index;
|
|
69
|
+
this.parent = null;
|
|
70
|
+
this.children = [];
|
|
71
|
+
this.content = null;
|
|
72
|
+
this._loader = void 0;
|
|
73
|
+
this._abortController = null;
|
|
74
|
+
this._loaderId = 0;
|
|
75
|
+
this._isLoaded = false;
|
|
76
|
+
this._isCancelled = false;
|
|
77
|
+
this._needsReload = false;
|
|
78
|
+
}
|
|
79
|
+
/** Structured bounds for the tile in the active coordinate system. */
|
|
80
|
+
get bbox() {
|
|
81
|
+
return this._bbox;
|
|
82
|
+
}
|
|
83
|
+
/** Initializes the tile bounds once during tile creation. */
|
|
84
|
+
set bbox(value) {
|
|
85
|
+
if (this._bbox)
|
|
86
|
+
return;
|
|
87
|
+
this._bbox = value;
|
|
88
|
+
if ("west" in value) {
|
|
89
|
+
this.boundingBox = [
|
|
90
|
+
[value.west, value.south],
|
|
91
|
+
[value.east, value.north]
|
|
92
|
+
];
|
|
93
|
+
} else {
|
|
94
|
+
this.boundingBox = [
|
|
95
|
+
[value.left, value.top],
|
|
96
|
+
[value.right, value.bottom]
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Resolves to loaded content while a request is in flight, otherwise returns the cached content. */
|
|
101
|
+
get data() {
|
|
102
|
+
const loader = this._loader;
|
|
103
|
+
if (!this._isCancelled && loader !== void 0) {
|
|
104
|
+
return loader.then(() => this.data);
|
|
105
|
+
}
|
|
106
|
+
return this.content;
|
|
107
|
+
}
|
|
108
|
+
/** Indicates whether tile content is available and up to date. */
|
|
109
|
+
get isLoaded() {
|
|
110
|
+
return this._isLoaded && !this._needsReload;
|
|
111
|
+
}
|
|
112
|
+
/** Indicates whether a tile request is currently in flight. */
|
|
113
|
+
get isLoading() {
|
|
114
|
+
return Boolean(this._loader) && !this._isCancelled;
|
|
115
|
+
}
|
|
116
|
+
/** Indicates whether the tile should be requested again. */
|
|
117
|
+
get needsReload() {
|
|
118
|
+
return this._needsReload || this._isCancelled;
|
|
119
|
+
}
|
|
120
|
+
/** Estimated byte size of the cached payload. */
|
|
121
|
+
get byteLength() {
|
|
122
|
+
const result = this.content ? this.content.byteLength : 0;
|
|
123
|
+
return Number.isFinite(result) ? result : 0;
|
|
124
|
+
}
|
|
125
|
+
/** Internal request pipeline used by {@link loadData}. */
|
|
126
|
+
async _loadData({ getData, requestScheduler, onLoad, onError }) {
|
|
127
|
+
const completeLoad = (tileData2, error2, loaderId2) => {
|
|
128
|
+
if (loaderId2 !== this._loaderId) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this._loader = void 0;
|
|
132
|
+
this.content = tileData2;
|
|
133
|
+
if (this._isCancelled && !tileData2) {
|
|
134
|
+
this._isLoaded = false;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
this._isLoaded = true;
|
|
138
|
+
this._isCancelled = false;
|
|
139
|
+
if (error2) {
|
|
140
|
+
onError(error2, this);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
onLoad(this);
|
|
144
|
+
};
|
|
145
|
+
const { index, id, bbox, userData, zoom } = this;
|
|
146
|
+
const loaderId = this._loaderId;
|
|
147
|
+
this._abortController = new AbortController();
|
|
148
|
+
const { signal } = this._abortController;
|
|
149
|
+
const requestToken = await requestScheduler.scheduleRequest(this, () => 1);
|
|
150
|
+
if (!requestToken) {
|
|
151
|
+
this._isCancelled = true;
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (this._isCancelled) {
|
|
155
|
+
requestToken.done();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
let tileData = null;
|
|
159
|
+
let error;
|
|
160
|
+
try {
|
|
161
|
+
tileData = await getData({ index, id, bbox, userData, zoom, signal });
|
|
162
|
+
} catch (err) {
|
|
163
|
+
error = err || true;
|
|
164
|
+
} finally {
|
|
165
|
+
requestToken.done();
|
|
166
|
+
}
|
|
167
|
+
completeLoad(tileData, error, loaderId);
|
|
168
|
+
}
|
|
169
|
+
/** Loads tile data through the shared scheduler. */
|
|
170
|
+
loadData(opts) {
|
|
171
|
+
this._isLoaded = false;
|
|
172
|
+
this._isCancelled = false;
|
|
173
|
+
this._needsReload = false;
|
|
174
|
+
this._loaderId++;
|
|
175
|
+
this._loader = this._loadData(opts);
|
|
176
|
+
return this._loader;
|
|
177
|
+
}
|
|
178
|
+
/** Marks the tile stale so it is refreshed on the next traversal. */
|
|
179
|
+
setNeedsReload() {
|
|
180
|
+
if (this.isLoading) {
|
|
181
|
+
this.abort();
|
|
182
|
+
this._loader = void 0;
|
|
183
|
+
}
|
|
184
|
+
this._needsReload = true;
|
|
185
|
+
}
|
|
186
|
+
/** Cancels an in-flight tile request. */
|
|
187
|
+
abort() {
|
|
188
|
+
var _a;
|
|
189
|
+
if (this.isLoaded) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
this._isCancelled = true;
|
|
193
|
+
(_a = this._abortController) == null ? void 0 : _a.abort();
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// dist/tileset/tileset-2d.js
|
|
198
|
+
var STRATEGY_NEVER = "never";
|
|
199
|
+
var STRATEGY_REPLACE = "no-overlap";
|
|
200
|
+
var STRATEGY_DEFAULT = "best-available";
|
|
201
|
+
var DEFAULT_TILESET2D_PROPS = {
|
|
202
|
+
adapter: null,
|
|
203
|
+
extent: null,
|
|
204
|
+
tileSize: 512,
|
|
205
|
+
maxZoom: null,
|
|
206
|
+
minZoom: null,
|
|
207
|
+
maxCacheSize: 100,
|
|
208
|
+
maxCacheByteSize: null,
|
|
209
|
+
refinementStrategy: "best-available",
|
|
210
|
+
zRange: null,
|
|
211
|
+
maxRequests: 6,
|
|
212
|
+
debounceTime: 0,
|
|
213
|
+
zoomOffset: 0,
|
|
214
|
+
onTileLoad: () => {
|
|
215
|
+
},
|
|
216
|
+
onTileUnload: () => {
|
|
217
|
+
},
|
|
218
|
+
onTileError: () => {
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
var SharedTileset2D = class {
|
|
222
|
+
/** Live counters describing shared tileset state. */
|
|
223
|
+
stats;
|
|
224
|
+
/** Effective runtime options after defaults and metadata overrides have been applied. */
|
|
225
|
+
opts;
|
|
226
|
+
/** Cached metadata returned by the backing TileSource, if any. */
|
|
227
|
+
sourceMetadata = null;
|
|
228
|
+
/** Scheduler shared across all tile requests for this tileset. */
|
|
229
|
+
_requestScheduler;
|
|
230
|
+
/** Shared tile cache keyed by tile id. */
|
|
231
|
+
_cache;
|
|
232
|
+
/** Tracks whether parent/child links need rebuilding. */
|
|
233
|
+
_dirty;
|
|
234
|
+
/** Cached tiles sorted by zoom for traversal and rendering. */
|
|
235
|
+
_tiles;
|
|
236
|
+
/** Running total of cached payload byte size. */
|
|
237
|
+
_cacheByteSize;
|
|
238
|
+
/** Cumulative number of tiles evicted from the shared cache. */
|
|
239
|
+
_unloadedTileCount;
|
|
240
|
+
/** Subscribers watching tileset lifecycle events. */
|
|
241
|
+
_listeners = /* @__PURE__ */ new Set();
|
|
242
|
+
/** Selected and visible tiles tracked per consumer. */
|
|
243
|
+
_consumers = /* @__PURE__ */ new Map();
|
|
244
|
+
/** Option names explicitly set by the caller. */
|
|
245
|
+
_explicitOptionKeys = /* @__PURE__ */ new Set();
|
|
246
|
+
/** Caller-provided options before metadata-derived overrides are applied. */
|
|
247
|
+
_baseOpts = {};
|
|
248
|
+
/** Derived overrides sourced from TileSource metadata. */
|
|
249
|
+
_sourceMetadataOverrides = {};
|
|
250
|
+
/** Resolved maximum zoom level used by traversal. */
|
|
251
|
+
_maxZoom;
|
|
252
|
+
/** Resolved minimum zoom level used by traversal. */
|
|
253
|
+
_minZoom;
|
|
254
|
+
/** Most recent traversal context used to derive tile metadata. */
|
|
255
|
+
_lastTileContext = null;
|
|
256
|
+
/** Creates a tileset from either `getTileData` or a loaders.gl `TileSource`. */
|
|
257
|
+
constructor(opts) {
|
|
258
|
+
this.stats = new import_stats.Stats({
|
|
259
|
+
id: "SharedTileset2D",
|
|
260
|
+
stats: [
|
|
261
|
+
{ name: "Tiles In Cache" },
|
|
262
|
+
{ name: "Cache Size" },
|
|
263
|
+
{ name: "Visible Tiles" },
|
|
264
|
+
{ name: "Selected Tiles" },
|
|
265
|
+
{ name: "Loading Tiles" },
|
|
266
|
+
{ name: "Unloaded Tiles" },
|
|
267
|
+
{ name: "Consumers" }
|
|
268
|
+
]
|
|
269
|
+
});
|
|
270
|
+
this.opts = {
|
|
271
|
+
...DEFAULT_TILESET2D_PROPS,
|
|
272
|
+
...opts,
|
|
273
|
+
getTileData: opts.getTileData || (() => null),
|
|
274
|
+
tileSource: opts.tileSource
|
|
275
|
+
};
|
|
276
|
+
this._requestScheduler = new import_loader_utils.RequestScheduler({
|
|
277
|
+
throttleRequests: this.opts.maxRequests > 0 || this.opts.debounceTime > 0,
|
|
278
|
+
maxRequests: this.opts.maxRequests,
|
|
279
|
+
debounceTime: this.opts.debounceTime
|
|
280
|
+
});
|
|
281
|
+
this._cache = /* @__PURE__ */ new Map();
|
|
282
|
+
this._tiles = [];
|
|
283
|
+
this._dirty = false;
|
|
284
|
+
this._cacheByteSize = 0;
|
|
285
|
+
this._unloadedTileCount = 0;
|
|
286
|
+
if (!this.opts.tileSource && !opts.getTileData) {
|
|
287
|
+
throw new Error("SharedTileset2D requires either `getTileData` or `tileSource`.");
|
|
288
|
+
}
|
|
289
|
+
this.setOptions(opts);
|
|
290
|
+
this._updateStats();
|
|
291
|
+
if (this.opts.tileSource) {
|
|
292
|
+
this._initializeTileSource(this.opts.tileSource).catch(() => {
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/** Convenience factory for wrapping a loaders.gl `TileSource`. */
|
|
297
|
+
static fromTileSource(tileSource, opts = {}) {
|
|
298
|
+
return new SharedTileset2D({ ...opts, tileSource });
|
|
299
|
+
}
|
|
300
|
+
/** All tiles currently present in the shared cache. */
|
|
301
|
+
get tiles() {
|
|
302
|
+
return this._tiles;
|
|
303
|
+
}
|
|
304
|
+
/** Estimated byte size of all tile content currently retained in cache. */
|
|
305
|
+
get cacheByteSize() {
|
|
306
|
+
return this._cacheByteSize;
|
|
307
|
+
}
|
|
308
|
+
/** Union of tiles selected by all attached consumers. */
|
|
309
|
+
get selectedTiles() {
|
|
310
|
+
return Array.from(this._getSelectedTilesUnion());
|
|
311
|
+
}
|
|
312
|
+
/** Union of tiles contributing to the visible result across all consumers and views, including unloaded selected tiles. */
|
|
313
|
+
get visibleTiles() {
|
|
314
|
+
const union = this._getVisibleTilesUnion();
|
|
315
|
+
for (const tile of this._getSelectedTilesUnion()) {
|
|
316
|
+
union.add(tile);
|
|
317
|
+
}
|
|
318
|
+
return Array.from(union);
|
|
319
|
+
}
|
|
320
|
+
/** Tiles currently loading anywhere in the shared cache. */
|
|
321
|
+
get loadingTiles() {
|
|
322
|
+
return Array.from(this._cache.values()).filter((tile) => tile.isLoading);
|
|
323
|
+
}
|
|
324
|
+
/** Tiles retained in cache that do not currently have loaded content. */
|
|
325
|
+
get unloadedTiles() {
|
|
326
|
+
return Array.from(this._cache.values()).filter((tile) => !tile.isLoaded);
|
|
327
|
+
}
|
|
328
|
+
/** Maximum resolved zoom level after applying metadata and explicit options. */
|
|
329
|
+
get maxZoom() {
|
|
330
|
+
return this._maxZoom;
|
|
331
|
+
}
|
|
332
|
+
/** Minimum resolved zoom level after applying metadata and explicit options. */
|
|
333
|
+
get minZoom() {
|
|
334
|
+
return this._minZoom;
|
|
335
|
+
}
|
|
336
|
+
/** Active refinement strategy for placeholder handling. */
|
|
337
|
+
get refinementStrategy() {
|
|
338
|
+
return this.opts.refinementStrategy || STRATEGY_DEFAULT;
|
|
339
|
+
}
|
|
340
|
+
/** Adapter currently used for traversal and tile metadata. */
|
|
341
|
+
get adapter() {
|
|
342
|
+
return this.opts.adapter;
|
|
343
|
+
}
|
|
344
|
+
/** Subscribes to tileset lifecycle events. */
|
|
345
|
+
subscribe(listener) {
|
|
346
|
+
this._listeners.add(listener);
|
|
347
|
+
return () => this._listeners.delete(listener);
|
|
348
|
+
}
|
|
349
|
+
/** Registers a consumer so cache pruning can account for its selected tiles. */
|
|
350
|
+
attachConsumer(id) {
|
|
351
|
+
this._consumers.set(id, { selectedTiles: /* @__PURE__ */ new Set(), visibleTiles: /* @__PURE__ */ new Set() });
|
|
352
|
+
this._updateStats();
|
|
353
|
+
}
|
|
354
|
+
/** Unregisters a consumer and prunes unused requests and tiles. */
|
|
355
|
+
detachConsumer(id) {
|
|
356
|
+
this._consumers.delete(id);
|
|
357
|
+
this._pruneRequests();
|
|
358
|
+
this._resizeCache();
|
|
359
|
+
this._updateStats();
|
|
360
|
+
}
|
|
361
|
+
/** Updates tileset options and reapplies TileSource metadata overrides. */
|
|
362
|
+
setOptions(opts) {
|
|
363
|
+
this._rememberExplicitOptions(opts);
|
|
364
|
+
this._baseOpts = { ...this._baseOpts, ...opts };
|
|
365
|
+
this._applyResolvedOptions();
|
|
366
|
+
}
|
|
367
|
+
/** Aborts in-flight requests and clears the shared cache. */
|
|
368
|
+
finalize() {
|
|
369
|
+
for (const tile of this._cache.values()) {
|
|
370
|
+
if (tile.isLoading) {
|
|
371
|
+
tile.abort();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
this._cache.clear();
|
|
375
|
+
this._tiles = [];
|
|
376
|
+
this._consumers.clear();
|
|
377
|
+
this._cacheByteSize = 0;
|
|
378
|
+
this._unloadedTileCount = 0;
|
|
379
|
+
this._updateStats();
|
|
380
|
+
}
|
|
381
|
+
/** Marks all retained tiles stale and drops unused cached tiles. */
|
|
382
|
+
reloadAll() {
|
|
383
|
+
const selectedTiles = this._getSelectedTilesUnion();
|
|
384
|
+
for (const id of this._cache.keys()) {
|
|
385
|
+
const tile = this._cache.get(id);
|
|
386
|
+
if (tile && !selectedTiles.has(tile)) {
|
|
387
|
+
this._cache.delete(id);
|
|
388
|
+
} else if (tile) {
|
|
389
|
+
tile.setNeedsReload();
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
this._cacheByteSize = this._getCacheByteSize();
|
|
393
|
+
this.prepareTiles();
|
|
394
|
+
this._updateStats();
|
|
395
|
+
}
|
|
396
|
+
/** Updates the selected and visible tile sets for one consumer. */
|
|
397
|
+
updateConsumer(id, selectedTiles, visibleTiles) {
|
|
398
|
+
this._consumers.set(id, {
|
|
399
|
+
selectedTiles: new Set(selectedTiles),
|
|
400
|
+
visibleTiles: new Set(visibleTiles)
|
|
401
|
+
});
|
|
402
|
+
this._pruneRequests();
|
|
403
|
+
this._resizeCache();
|
|
404
|
+
this._updateStats();
|
|
405
|
+
}
|
|
406
|
+
/** Rebuilds parent/child links if the cache changed since the last traversal. */
|
|
407
|
+
prepareTiles() {
|
|
408
|
+
if (this._dirty) {
|
|
409
|
+
this._rebuildTree();
|
|
410
|
+
this._syncTiles();
|
|
411
|
+
this._dirty = false;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
/** Returns tile indices needed to cover a viewport. */
|
|
415
|
+
getTileIndices({ viewState, maxZoom, minZoom, zRange, modelMatrix, modelMatrixInverse }) {
|
|
416
|
+
const { adapter, tileSize, extent, zoomOffset } = this.opts;
|
|
417
|
+
if (!adapter) {
|
|
418
|
+
throw new Error("SharedTileset2D requires an adapter before tile traversal can be used.");
|
|
419
|
+
}
|
|
420
|
+
this._lastTileContext = { viewState, tileSize };
|
|
421
|
+
return adapter.getTileIndices({
|
|
422
|
+
viewState,
|
|
423
|
+
maxZoom,
|
|
424
|
+
minZoom,
|
|
425
|
+
zRange,
|
|
426
|
+
tileSize,
|
|
427
|
+
extent: normalizeBounds(extent),
|
|
428
|
+
modelMatrix,
|
|
429
|
+
modelMatrixInverse,
|
|
430
|
+
zoomOffset
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
/** Returns the stable cache id for a tile index. */
|
|
434
|
+
getTileId(index) {
|
|
435
|
+
return `${index.x}-${index.y}-${index.z}`;
|
|
436
|
+
}
|
|
437
|
+
/** Returns the zoom level represented by a tile index. */
|
|
438
|
+
getTileZoom(index) {
|
|
439
|
+
return index.z;
|
|
440
|
+
}
|
|
441
|
+
/** Returns derived metadata used to initialize a tile header. */
|
|
442
|
+
getTileMetadata(index) {
|
|
443
|
+
if (!this._lastTileContext) {
|
|
444
|
+
throw new Error("SharedTileset2D metadata requested before traversal context was set.");
|
|
445
|
+
}
|
|
446
|
+
if (!this.opts.adapter) {
|
|
447
|
+
throw new Error("SharedTileset2D requires an adapter before tile metadata can be derived.");
|
|
448
|
+
}
|
|
449
|
+
return { bbox: this.opts.adapter.getTileBoundingBox(this._lastTileContext, index) };
|
|
450
|
+
}
|
|
451
|
+
/** Returns the parent tile index in the quadtree. */
|
|
452
|
+
getParentIndex(index) {
|
|
453
|
+
return { x: Math.floor(index.x / 2), y: Math.floor(index.y / 2), z: index.z - 1 };
|
|
454
|
+
}
|
|
455
|
+
getTile(index, create) {
|
|
456
|
+
const id = this.getTileId(index);
|
|
457
|
+
let tile = this._cache.get(id);
|
|
458
|
+
let needsReload = false;
|
|
459
|
+
if (!tile && create) {
|
|
460
|
+
tile = new SharedTile2DHeader(index);
|
|
461
|
+
Object.assign(tile, this.getTileMetadata(tile.index));
|
|
462
|
+
Object.assign(tile, { id, zoom: this.getTileZoom(tile.index) });
|
|
463
|
+
needsReload = true;
|
|
464
|
+
this._cache.set(id, tile);
|
|
465
|
+
this._dirty = true;
|
|
466
|
+
this._updateStats();
|
|
467
|
+
} else if (tile && tile.needsReload) {
|
|
468
|
+
needsReload = true;
|
|
469
|
+
}
|
|
470
|
+
if (tile) {
|
|
471
|
+
this._touchTile(id, tile);
|
|
472
|
+
}
|
|
473
|
+
if (tile && needsReload) {
|
|
474
|
+
tile.loadData({
|
|
475
|
+
getData: this.opts.getTileData,
|
|
476
|
+
requestScheduler: this._requestScheduler,
|
|
477
|
+
onLoad: this._handleTileLoad.bind(this),
|
|
478
|
+
onError: this._handleTileError.bind(this)
|
|
479
|
+
}).catch(() => {
|
|
480
|
+
});
|
|
481
|
+
this._updateStats();
|
|
482
|
+
}
|
|
483
|
+
return tile;
|
|
484
|
+
}
|
|
485
|
+
/** Loads metadata from a TileSource and reapplies derived option overrides. */
|
|
486
|
+
async _initializeTileSource(tileSource) {
|
|
487
|
+
try {
|
|
488
|
+
this.sourceMetadata = await tileSource.getMetadata();
|
|
489
|
+
this._sourceMetadataOverrides = this._getMetadataOverrides(this.sourceMetadata);
|
|
490
|
+
this._applyResolvedOptions();
|
|
491
|
+
this._notifyUpdate();
|
|
492
|
+
} catch (error) {
|
|
493
|
+
const normalizedError = error instanceof Error ? error : new Error(`TileSource metadata error: ${String(error)}`);
|
|
494
|
+
this._notifyError(normalizedError);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
/** Tracks which options were explicitly set by the caller. */
|
|
498
|
+
_rememberExplicitOptions(opts) {
|
|
499
|
+
for (const key of Object.keys(opts)) {
|
|
500
|
+
this._explicitOptionKeys.add(key);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
/** Resolves defaults, metadata overrides, and caller options into runtime settings. */
|
|
504
|
+
_applyResolvedOptions() {
|
|
505
|
+
const resolvedOpts = {
|
|
506
|
+
...DEFAULT_TILESET2D_PROPS,
|
|
507
|
+
...this._sourceMetadataOverrides,
|
|
508
|
+
...this._baseOpts
|
|
509
|
+
};
|
|
510
|
+
if (resolvedOpts.tileSource) {
|
|
511
|
+
const tileSource = resolvedOpts.tileSource;
|
|
512
|
+
resolvedOpts.getTileData = (loadProps) => tileSource.getTileData(loadProps);
|
|
513
|
+
}
|
|
514
|
+
this.opts = resolvedOpts;
|
|
515
|
+
this._maxZoom = typeof this.opts.maxZoom === "number" && Number.isFinite(this.opts.maxZoom) ? Math.floor(this.opts.maxZoom) : void 0;
|
|
516
|
+
this._minZoom = typeof this.opts.minZoom === "number" && Number.isFinite(this.opts.minZoom) ? Math.ceil(this.opts.minZoom) : void 0;
|
|
517
|
+
}
|
|
518
|
+
/** Maps TileSource metadata into supported tileset options. */
|
|
519
|
+
_getMetadataOverrides(metadata) {
|
|
520
|
+
if (!metadata) {
|
|
521
|
+
return {};
|
|
522
|
+
}
|
|
523
|
+
const overrides = {};
|
|
524
|
+
if (!this._explicitOptionKeys.has("minZoom") && Number.isFinite(metadata.minZoom)) {
|
|
525
|
+
overrides.minZoom = metadata.minZoom;
|
|
526
|
+
}
|
|
527
|
+
if (!this._explicitOptionKeys.has("maxZoom") && Number.isFinite(metadata.maxZoom)) {
|
|
528
|
+
overrides.maxZoom = metadata.maxZoom;
|
|
529
|
+
}
|
|
530
|
+
if (!this._explicitOptionKeys.has("extent") && metadata.boundingBox) {
|
|
531
|
+
overrides.extent = [
|
|
532
|
+
metadata.boundingBox[0][0],
|
|
533
|
+
metadata.boundingBox[0][1],
|
|
534
|
+
metadata.boundingBox[1][0],
|
|
535
|
+
metadata.boundingBox[1][1]
|
|
536
|
+
];
|
|
537
|
+
}
|
|
538
|
+
return overrides;
|
|
539
|
+
}
|
|
540
|
+
/** Handles successful tile loads. */
|
|
541
|
+
_handleTileLoad(tile) {
|
|
542
|
+
var _a, _b, _c;
|
|
543
|
+
(_b = (_a = this.opts).onTileLoad) == null ? void 0 : _b.call(_a, tile);
|
|
544
|
+
this._cacheByteSize = this._getCacheByteSize();
|
|
545
|
+
this._resizeCache();
|
|
546
|
+
for (const listener of this._listeners) {
|
|
547
|
+
(_c = listener.onTileLoad) == null ? void 0 : _c.call(listener, tile);
|
|
548
|
+
}
|
|
549
|
+
this._updateStats();
|
|
550
|
+
}
|
|
551
|
+
/** Handles tile load failures. */
|
|
552
|
+
_handleTileError(error, tile) {
|
|
553
|
+
var _a, _b, _c;
|
|
554
|
+
(_b = (_a = this.opts).onTileError) == null ? void 0 : _b.call(_a, error, tile);
|
|
555
|
+
for (const listener of this._listeners) {
|
|
556
|
+
(_c = listener.onTileError) == null ? void 0 : _c.call(listener, error, tile);
|
|
557
|
+
}
|
|
558
|
+
this._updateStats();
|
|
559
|
+
}
|
|
560
|
+
/** Handles tile eviction from cache. */
|
|
561
|
+
_handleTileUnload(tile) {
|
|
562
|
+
var _a, _b, _c;
|
|
563
|
+
this._unloadedTileCount++;
|
|
564
|
+
(_b = (_a = this.opts).onTileUnload) == null ? void 0 : _b.call(_a, tile);
|
|
565
|
+
for (const listener of this._listeners) {
|
|
566
|
+
(_c = listener.onTileUnload) == null ? void 0 : _c.call(listener, tile);
|
|
567
|
+
}
|
|
568
|
+
this._updateStats();
|
|
569
|
+
}
|
|
570
|
+
/** Notifies listeners that metadata or effective options changed. */
|
|
571
|
+
_notifyUpdate() {
|
|
572
|
+
var _a;
|
|
573
|
+
for (const listener of this._listeners) {
|
|
574
|
+
(_a = listener.onUpdate) == null ? void 0 : _a.call(listener);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
/** Notifies listeners about asynchronous metadata errors. */
|
|
578
|
+
_notifyError(error) {
|
|
579
|
+
var _a;
|
|
580
|
+
for (const listener of this._listeners) {
|
|
581
|
+
(_a = listener.onError) == null ? void 0 : _a.call(listener, error);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
/** Recomputes absolute counter stats and notifies listeners. */
|
|
585
|
+
_updateStats() {
|
|
586
|
+
var _a;
|
|
587
|
+
this._setStatCount("Tiles In Cache", this._cache.size);
|
|
588
|
+
this._setStatCount("Cache Size", this.cacheByteSize);
|
|
589
|
+
this._setStatCount("Visible Tiles", this.visibleTiles.length);
|
|
590
|
+
this._setStatCount("Selected Tiles", this.selectedTiles.length);
|
|
591
|
+
this._setStatCount("Loading Tiles", this.loadingTiles.length);
|
|
592
|
+
this._setStatCount("Unloaded Tiles", this._unloadedTileCount);
|
|
593
|
+
this._setStatCount("Consumers", this._consumers.size);
|
|
594
|
+
for (const listener of this._listeners) {
|
|
595
|
+
(_a = listener.onStatsChange) == null ? void 0 : _a.call(listener, this.stats);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
/** Writes an absolute count into a probe.gl stat. */
|
|
599
|
+
_setStatCount(name, value) {
|
|
600
|
+
this.stats.get(name).reset().addCount(value);
|
|
601
|
+
}
|
|
602
|
+
/** Returns the union of selected tiles across all consumers. */
|
|
603
|
+
_getSelectedTilesUnion() {
|
|
604
|
+
const union = /* @__PURE__ */ new Set();
|
|
605
|
+
for (const consumer of this._consumers.values()) {
|
|
606
|
+
for (const tile of consumer.selectedTiles) {
|
|
607
|
+
union.add(tile);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
return union;
|
|
611
|
+
}
|
|
612
|
+
/** Returns the union of visible tiles across all consumers. */
|
|
613
|
+
_getVisibleTilesUnion() {
|
|
614
|
+
const union = /* @__PURE__ */ new Set();
|
|
615
|
+
for (const consumer of this._consumers.values()) {
|
|
616
|
+
for (const tile of consumer.visibleTiles) {
|
|
617
|
+
union.add(tile);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
return union;
|
|
621
|
+
}
|
|
622
|
+
/** Moves a touched tile to the back of the cache map for LRU eviction ordering. */
|
|
623
|
+
_touchTile(id, tile) {
|
|
624
|
+
this._cache.delete(id);
|
|
625
|
+
this._cache.set(id, tile);
|
|
626
|
+
}
|
|
627
|
+
/** Computes the total byte size of all cached tile content. */
|
|
628
|
+
_getCacheByteSize() {
|
|
629
|
+
let byteLength = 0;
|
|
630
|
+
for (const tile of this._cache.values()) {
|
|
631
|
+
byteLength += tile.byteLength;
|
|
632
|
+
}
|
|
633
|
+
return byteLength;
|
|
634
|
+
}
|
|
635
|
+
/** Cancels low-priority requests when consumers no longer need them. */
|
|
636
|
+
_pruneRequests() {
|
|
637
|
+
const { maxRequests = 0 } = this.opts;
|
|
638
|
+
const selectedTiles = this._getSelectedTilesUnion();
|
|
639
|
+
const visibleTiles = this._getVisibleTilesUnion();
|
|
640
|
+
const abortCandidates = [];
|
|
641
|
+
let ongoingRequestCount = 0;
|
|
642
|
+
for (const tile of this._cache.values()) {
|
|
643
|
+
if (tile.isLoading) {
|
|
644
|
+
ongoingRequestCount++;
|
|
645
|
+
if (!selectedTiles.has(tile) && !visibleTiles.has(tile)) {
|
|
646
|
+
abortCandidates.push(tile);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
while (maxRequests > 0 && ongoingRequestCount > maxRequests && abortCandidates.length > 0) {
|
|
651
|
+
const tile = abortCandidates.shift();
|
|
652
|
+
if (tile) {
|
|
653
|
+
tile.abort();
|
|
654
|
+
}
|
|
655
|
+
ongoingRequestCount--;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
/** Rebuilds parent and child links for all cached tiles. */
|
|
659
|
+
_rebuildTree() {
|
|
660
|
+
for (const tile of this._cache.values()) {
|
|
661
|
+
tile.parent = null;
|
|
662
|
+
if (tile.children) {
|
|
663
|
+
tile.children.length = 0;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
for (const tile of this._cache.values()) {
|
|
667
|
+
const parent = this._getNearestAncestor(tile);
|
|
668
|
+
tile.parent = parent;
|
|
669
|
+
if (parent == null ? void 0 : parent.children) {
|
|
670
|
+
parent.children.push(tile);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
/** Updates the sorted tile list used by traversal and rendering. */
|
|
675
|
+
_syncTiles() {
|
|
676
|
+
this._tiles = Array.from(this._cache.values()).sort((t1, t2) => t1.zoom - t2.zoom);
|
|
677
|
+
}
|
|
678
|
+
/** Evicts unused cached tiles when configured cache limits are exceeded. */
|
|
679
|
+
_resizeCache() {
|
|
680
|
+
const maxCacheSize = this.opts.maxCacheSize ?? 100;
|
|
681
|
+
const maxCacheByteSize = this.opts.maxCacheByteSize ?? Infinity;
|
|
682
|
+
const visibleTiles = this._getVisibleTilesUnion();
|
|
683
|
+
const selectedTiles = this._getSelectedTilesUnion();
|
|
684
|
+
const overflown = this._cache.size > maxCacheSize || this._cacheByteSize > maxCacheByteSize;
|
|
685
|
+
if (overflown) {
|
|
686
|
+
for (const [id, tile] of this._cache) {
|
|
687
|
+
if (!visibleTiles.has(tile) && !selectedTiles.has(tile)) {
|
|
688
|
+
this._cache.delete(id);
|
|
689
|
+
this._cacheByteSize = this._getCacheByteSize();
|
|
690
|
+
this._handleTileUnload(tile);
|
|
691
|
+
}
|
|
692
|
+
if (this._cache.size <= maxCacheSize && this._cacheByteSize <= maxCacheByteSize) {
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
this._dirty = true;
|
|
697
|
+
}
|
|
698
|
+
if (this._dirty) {
|
|
699
|
+
this._rebuildTree();
|
|
700
|
+
this._syncTiles();
|
|
701
|
+
this._dirty = false;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
/** Finds the nearest cached ancestor tile for placeholder rendering. */
|
|
705
|
+
_getNearestAncestor(tile) {
|
|
706
|
+
const { _minZoom = 0 } = this;
|
|
707
|
+
let index = tile.index;
|
|
708
|
+
while (this.getTileZoom(index) > _minZoom) {
|
|
709
|
+
index = this.getParentIndex(index);
|
|
710
|
+
const parent = this.getTile(index);
|
|
711
|
+
if (parent) {
|
|
712
|
+
return parent;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
return null;
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
function normalizeBounds(extent) {
|
|
719
|
+
return extent && extent.length === 4 ? extent : void 0;
|
|
720
|
+
}
|
|
721
|
+
//# sourceMappingURL=index.cjs.map
|