@loaders.gl/tiles 3.2.0-alpha.1 → 3.2.0-alpha.4
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.min.js +121 -19
- package/dist/es5/tileset/helpers/zoom.js +32 -0
- package/dist/es5/tileset/helpers/zoom.js.map +1 -1
- package/dist/es5/tileset/tileset-3d.js +131 -43
- package/dist/es5/tileset/tileset-3d.js.map +1 -1
- package/dist/es5/tileset/traversers/i3s-frame-counter.js +45 -0
- package/dist/es5/tileset/traversers/i3s-frame-counter.js.map +1 -0
- package/dist/es5/tileset/traversers/i3s-tile-manager.js +17 -0
- package/dist/es5/tileset/traversers/i3s-tile-manager.js.map +1 -1
- package/dist/es5/tileset/traversers/i3s-tileset-traverser.js +6 -1
- package/dist/es5/tileset/traversers/i3s-tileset-traverser.js.map +1 -1
- package/dist/es5/tileset/traversers/tileset-traverser.js +13 -1
- package/dist/es5/tileset/traversers/tileset-traverser.js.map +1 -1
- package/dist/esm/tileset/helpers/zoom.js +17 -0
- package/dist/esm/tileset/helpers/zoom.js.map +1 -1
- package/dist/esm/tileset/tileset-3d.js +72 -16
- package/dist/esm/tileset/tileset-3d.js.map +1 -1
- package/dist/esm/tileset/traversers/i3s-frame-counter.js +23 -0
- package/dist/esm/tileset/traversers/i3s-frame-counter.js.map +1 -0
- package/dist/esm/tileset/traversers/i3s-tile-manager.js +15 -0
- package/dist/esm/tileset/traversers/i3s-tile-manager.js.map +1 -1
- package/dist/esm/tileset/traversers/i3s-tileset-traverser.js +5 -1
- package/dist/esm/tileset/traversers/i3s-tileset-traverser.js.map +1 -1
- package/dist/esm/tileset/traversers/tileset-traverser.js +14 -1
- package/dist/esm/tileset/traversers/tileset-traverser.js.map +1 -1
- package/dist/tileset/helpers/zoom.d.ts +35 -0
- package/dist/tileset/helpers/zoom.d.ts.map +1 -1
- package/dist/tileset/helpers/zoom.js +41 -1
- package/dist/tileset/tileset-3d.d.ts +17 -3
- package/dist/tileset/tileset-3d.d.ts.map +1 -1
- package/dist/tileset/tileset-3d.js +72 -21
- package/dist/tileset/traversers/i3s-frame-counter.d.ts +24 -0
- package/dist/tileset/traversers/i3s-frame-counter.d.ts.map +1 -0
- package/dist/tileset/traversers/i3s-frame-counter.js +37 -0
- package/dist/tileset/traversers/i3s-tile-manager.d.ts +10 -2
- package/dist/tileset/traversers/i3s-tile-manager.d.ts.map +1 -1
- package/dist/tileset/traversers/i3s-tile-manager.js +24 -0
- package/dist/tileset/traversers/i3s-tileset-traverser.d.ts +9 -2
- package/dist/tileset/traversers/i3s-tileset-traverser.d.ts.map +1 -1
- package/dist/tileset/traversers/i3s-tileset-traverser.js +10 -1
- package/dist/tileset/traversers/tileset-traverser.d.ts +5 -1
- package/dist/tileset/traversers/tileset-traverser.d.ts.map +1 -1
- package/dist/tileset/traversers/tileset-traverser.js +10 -1
- package/package.json +5 -5
- package/src/tileset/helpers/zoom.ts +64 -0
- package/src/tileset/tileset-3d.ts +84 -21
- package/src/tileset/traversers/i3s-frame-counter.ts +35 -0
- package/src/tileset/traversers/i3s-tile-manager.ts +26 -2
- package/src/tileset/traversers/i3s-tileset-traverser.ts +16 -3
- package/src/tileset/traversers/tileset-traverser.ts +13 -2
package/dist/dist.min.js
CHANGED
|
@@ -3672,7 +3672,7 @@
|
|
|
3672
3672
|
this.worker = isBrowser2 ? this._createBrowserWorker() : this._createNodeWorker();
|
|
3673
3673
|
}
|
|
3674
3674
|
static isSupported() {
|
|
3675
|
-
return typeof Worker !== "undefined" && isBrowser2;
|
|
3675
|
+
return typeof Worker !== "undefined" && isBrowser2 || typeof Worker2 !== void 0;
|
|
3676
3676
|
}
|
|
3677
3677
|
destroy() {
|
|
3678
3678
|
this.onMessage = NOOP;
|
|
@@ -3993,10 +3993,12 @@
|
|
|
3993
3993
|
const workerFarm = WorkerFarm.getWorkerFarm(options);
|
|
3994
3994
|
const workerPool = workerFarm.getWorkerPool({ name, url });
|
|
3995
3995
|
options = JSON.parse(JSON.stringify(options));
|
|
3996
|
+
context = JSON.parse(JSON.stringify(context || {}));
|
|
3996
3997
|
const job = await workerPool.startJob("process-on-worker", onMessage.bind(null, parseOnMainThread));
|
|
3997
3998
|
job.postMessage("process", {
|
|
3998
3999
|
input: data,
|
|
3999
|
-
options
|
|
4000
|
+
options,
|
|
4001
|
+
context
|
|
4000
4002
|
});
|
|
4001
4003
|
const result = await job.result;
|
|
4002
4004
|
return await result.result;
|
|
@@ -5145,6 +5147,15 @@
|
|
|
5145
5147
|
}
|
|
5146
5148
|
return 1;
|
|
5147
5149
|
}
|
|
5150
|
+
function getZoomFromFullExtent(fullExtent, cartorgraphicCenter, cartesianCenter) {
|
|
5151
|
+
const extentVertex = Ellipsoid.WGS84.cartographicToCartesian([fullExtent.xmax, fullExtent.ymax, fullExtent.zmax], new Vector3());
|
|
5152
|
+
const extentSize = Math.sqrt(Math.pow(extentVertex[0] - cartesianCenter[0], 2) + Math.pow(extentVertex[1] - cartesianCenter[1], 2) + Math.pow(extentVertex[2] - cartesianCenter[2], 2));
|
|
5153
|
+
return Math.log2(WGS84_RADIUS_Z2 / (extentSize + cartorgraphicCenter[2]));
|
|
5154
|
+
}
|
|
5155
|
+
function getZoomFromExtent(extent, cartorgraphicCenter, cartesianCenter) {
|
|
5156
|
+
const [xmin, ymin, xmax, ymax] = extent;
|
|
5157
|
+
return getZoomFromFullExtent({ xmin, xmax, ymin, ymax, zmin: 0, zmax: 0 }, cartorgraphicCenter, cartesianCenter);
|
|
5158
|
+
}
|
|
5148
5159
|
function getObbSize(halfAxes) {
|
|
5149
5160
|
halfAxes.getColumn(0, scratchVector8);
|
|
5150
5161
|
const axeY = halfAxes.getColumn(1);
|
|
@@ -5158,6 +5169,7 @@
|
|
|
5158
5169
|
"src/tileset/helpers/zoom.ts"() {
|
|
5159
5170
|
init_esm();
|
|
5160
5171
|
init_esm4();
|
|
5172
|
+
init_esm2();
|
|
5161
5173
|
WGS84_RADIUS_X2 = 6378137;
|
|
5162
5174
|
WGS84_RADIUS_Y2 = 6378137;
|
|
5163
5175
|
WGS84_RADIUS_Z2 = 6356752314245179e-9;
|
|
@@ -5304,7 +5316,7 @@
|
|
|
5304
5316
|
text += ` ${await response.text()}`;
|
|
5305
5317
|
}
|
|
5306
5318
|
message += text;
|
|
5307
|
-
message = message.length > 60 ? `${message.slice(60)}...` : message;
|
|
5319
|
+
message = message.length > 60 ? `${message.slice(0, 60)}...` : message;
|
|
5308
5320
|
} catch (error) {
|
|
5309
5321
|
}
|
|
5310
5322
|
return message;
|
|
@@ -7307,6 +7319,12 @@
|
|
|
7307
7319
|
}
|
|
7308
7320
|
async function parseWithLoader(loader, data, options, context) {
|
|
7309
7321
|
validateWorkerVersion(loader);
|
|
7322
|
+
if (isResponse(data)) {
|
|
7323
|
+
const response = data;
|
|
7324
|
+
const { ok, redirected, status, statusText, type, url } = response;
|
|
7325
|
+
const headers = Object.fromEntries(response.headers.entries());
|
|
7326
|
+
context.response = { headers, ok, redirected, status, statusText, type, url };
|
|
7327
|
+
}
|
|
7310
7328
|
data = await getArrayBufferOrStringFromData(data, loader, options);
|
|
7311
7329
|
if (loader.parseTextSync && typeof data === "string") {
|
|
7312
7330
|
options.dataType = "text";
|
|
@@ -7329,6 +7347,7 @@
|
|
|
7329
7347
|
init_src();
|
|
7330
7348
|
init_src2();
|
|
7331
7349
|
init_normalize_loader();
|
|
7350
|
+
init_is_type();
|
|
7332
7351
|
init_option_utils();
|
|
7333
7352
|
init_get_data();
|
|
7334
7353
|
init_loader_context();
|
|
@@ -7714,6 +7733,8 @@
|
|
|
7714
7733
|
};
|
|
7715
7734
|
TilesetTraverser = class {
|
|
7716
7735
|
constructor(options) {
|
|
7736
|
+
this.lastUpdate = new Date().getTime();
|
|
7737
|
+
this.updateDebounceTime = 1e3;
|
|
7717
7738
|
this.options = { ...DEFAULT_PROPS3, ...options };
|
|
7718
7739
|
this._traversalStack = new ManagedArray();
|
|
7719
7740
|
this._emptyTraversalStack = new ManagedArray();
|
|
@@ -7723,6 +7744,9 @@
|
|
|
7723
7744
|
this.requestedTiles = {};
|
|
7724
7745
|
this.emptyTiles = {};
|
|
7725
7746
|
}
|
|
7747
|
+
get traversalFinished() {
|
|
7748
|
+
return true;
|
|
7749
|
+
}
|
|
7726
7750
|
traverse(root, frameState, options) {
|
|
7727
7751
|
this.root = root;
|
|
7728
7752
|
this.options = { ...this.options, ...options };
|
|
@@ -7770,7 +7794,11 @@
|
|
|
7770
7794
|
this.touchTile(tile, frameState);
|
|
7771
7795
|
tile._shouldRefine = shouldRefine && parentRefines;
|
|
7772
7796
|
}
|
|
7773
|
-
|
|
7797
|
+
const newTime = new Date().getTime();
|
|
7798
|
+
if (this.traversalFinished || newTime - this.lastUpdate > this.updateDebounceTime) {
|
|
7799
|
+
this.lastUpdate = newTime;
|
|
7800
|
+
this.options.onTraversalEnd(frameState);
|
|
7801
|
+
}
|
|
7774
7802
|
}
|
|
7775
7803
|
updateChildTiles(tile, frameState) {
|
|
7776
7804
|
const children = tile.children;
|
|
@@ -8327,10 +8355,35 @@
|
|
|
8327
8355
|
}
|
|
8328
8356
|
});
|
|
8329
8357
|
|
|
8358
|
+
// src/tileset/traversers/i3s-frame-counter.ts
|
|
8359
|
+
var I3SPendingTilesRegister;
|
|
8360
|
+
var init_i3s_frame_counter = __esm({
|
|
8361
|
+
"src/tileset/traversers/i3s-frame-counter.ts"() {
|
|
8362
|
+
I3SPendingTilesRegister = class {
|
|
8363
|
+
constructor() {
|
|
8364
|
+
this.frameNumberMap = new Map();
|
|
8365
|
+
}
|
|
8366
|
+
register(frameNumber) {
|
|
8367
|
+
const oldCount = this.frameNumberMap.get(frameNumber) || 0;
|
|
8368
|
+
this.frameNumberMap.set(frameNumber, (oldCount || 0) + 1);
|
|
8369
|
+
}
|
|
8370
|
+
deregister(frameNumber) {
|
|
8371
|
+
const oldCount = this.frameNumberMap.get(frameNumber) || 1;
|
|
8372
|
+
this.frameNumberMap.set(frameNumber, (oldCount || 0) - 1);
|
|
8373
|
+
}
|
|
8374
|
+
isZero(frameNumber) {
|
|
8375
|
+
const count = this.frameNumberMap.get(frameNumber) || 0;
|
|
8376
|
+
return count === 0;
|
|
8377
|
+
}
|
|
8378
|
+
};
|
|
8379
|
+
}
|
|
8380
|
+
});
|
|
8381
|
+
|
|
8330
8382
|
// src/tileset/traversers/i3s-tile-manager.ts
|
|
8331
8383
|
var STATUS, I3STileManager;
|
|
8332
8384
|
var init_i3s_tile_manager = __esm({
|
|
8333
8385
|
"src/tileset/traversers/i3s-tile-manager.ts"() {
|
|
8386
|
+
init_i3s_frame_counter();
|
|
8334
8387
|
STATUS = {
|
|
8335
8388
|
REQUESTED: "REQUESTED",
|
|
8336
8389
|
COMPLETED: "COMPLETED",
|
|
@@ -8338,28 +8391,38 @@
|
|
|
8338
8391
|
};
|
|
8339
8392
|
I3STileManager = class {
|
|
8340
8393
|
constructor() {
|
|
8394
|
+
this.pendingTilesRegister = new I3SPendingTilesRegister();
|
|
8341
8395
|
this._statusMap = {};
|
|
8342
8396
|
}
|
|
8343
8397
|
add(request, key, callback, frameState) {
|
|
8344
8398
|
if (!this._statusMap[key]) {
|
|
8399
|
+
const { frameNumber } = frameState;
|
|
8345
8400
|
this._statusMap[key] = { request, callback, key, frameState, status: STATUS.REQUESTED };
|
|
8401
|
+
this.pendingTilesRegister.register(frameNumber);
|
|
8346
8402
|
request().then((data) => {
|
|
8347
8403
|
this._statusMap[key].status = STATUS.COMPLETED;
|
|
8404
|
+
this.pendingTilesRegister.deregister(frameNumber);
|
|
8348
8405
|
this._statusMap[key].callback(data, frameState);
|
|
8349
8406
|
}).catch((error) => {
|
|
8350
8407
|
this._statusMap[key].status = STATUS.ERROR;
|
|
8408
|
+
this.pendingTilesRegister.deregister(frameNumber);
|
|
8351
8409
|
callback(error);
|
|
8352
8410
|
});
|
|
8353
8411
|
}
|
|
8354
8412
|
}
|
|
8355
8413
|
update(key, frameState) {
|
|
8356
8414
|
if (this._statusMap[key]) {
|
|
8415
|
+
this.pendingTilesRegister.deregister(this._statusMap[key].frameState.frameNumber);
|
|
8416
|
+
this.pendingTilesRegister.register(frameState.frameNumber);
|
|
8357
8417
|
this._statusMap[key].frameState = frameState;
|
|
8358
8418
|
}
|
|
8359
8419
|
}
|
|
8360
8420
|
find(key) {
|
|
8361
8421
|
return this._statusMap[key];
|
|
8362
8422
|
}
|
|
8423
|
+
hasPendingTiles(frameNumber) {
|
|
8424
|
+
return !this.pendingTilesRegister.isZero(frameNumber);
|
|
8425
|
+
}
|
|
8363
8426
|
};
|
|
8364
8427
|
}
|
|
8365
8428
|
});
|
|
@@ -8374,6 +8437,9 @@
|
|
|
8374
8437
|
init_tile_3d();
|
|
8375
8438
|
init_i3s_tile_manager();
|
|
8376
8439
|
I3STilesetTraverser = class extends TilesetTraverser {
|
|
8440
|
+
get traversalFinished() {
|
|
8441
|
+
return !this._tileManager.hasPendingTiles(this._frameNumber || 0);
|
|
8442
|
+
}
|
|
8377
8443
|
constructor(options) {
|
|
8378
8444
|
super(options);
|
|
8379
8445
|
this._tileManager = new I3STileManager();
|
|
@@ -8424,7 +8490,7 @@
|
|
|
8424
8490
|
tile.children.push(childTile);
|
|
8425
8491
|
const frameState = this._tileManager.find(childTile.id).frameState;
|
|
8426
8492
|
this.updateTile(childTile, frameState);
|
|
8427
|
-
if (this._frameNumber === frameState.frameNumber) {
|
|
8493
|
+
if (this._frameNumber === frameState.frameNumber && (this.traversalFinished || new Date().getTime() - this.lastUpdate > this.updateDebounceTime)) {
|
|
8428
8494
|
this.executeTraversal(childTile, frameState);
|
|
8429
8495
|
}
|
|
8430
8496
|
}
|
|
@@ -8498,7 +8564,7 @@
|
|
|
8498
8564
|
TILES_LOADING = "Tiles Loading";
|
|
8499
8565
|
TILES_UNLOADED = "Tiles Unloaded";
|
|
8500
8566
|
TILES_LOAD_FAILED = "Failed Tile Loads";
|
|
8501
|
-
POINTS_COUNT = "Points";
|
|
8567
|
+
POINTS_COUNT = "Points/Vertices";
|
|
8502
8568
|
TILES_GPU_MEMORY = "Tile Memory Use";
|
|
8503
8569
|
Tileset3D = class {
|
|
8504
8570
|
constructor(json, options) {
|
|
@@ -8550,13 +8616,13 @@
|
|
|
8550
8616
|
this.asset = {};
|
|
8551
8617
|
this.credits = {};
|
|
8552
8618
|
this.description = this.options.description || "";
|
|
8553
|
-
this._initializeTileSet(json);
|
|
8619
|
+
this.tilesetInitializationPromise = this._initializeTileSet(json);
|
|
8554
8620
|
}
|
|
8555
8621
|
destroy() {
|
|
8556
8622
|
this._destroy();
|
|
8557
8623
|
}
|
|
8558
8624
|
isLoaded() {
|
|
8559
|
-
return this._pendingCount === 0 && this._frameNumber !== 0;
|
|
8625
|
+
return this._pendingCount === 0 && this._frameNumber !== 0 && this._requestedTiles.length === 0;
|
|
8560
8626
|
}
|
|
8561
8627
|
get tiles() {
|
|
8562
8628
|
return Object.values(this._tiles);
|
|
@@ -8587,14 +8653,17 @@
|
|
|
8587
8653
|
return Boolean(this._extensionsUsed && this._extensionsUsed.indexOf(extensionName) > -1);
|
|
8588
8654
|
}
|
|
8589
8655
|
update(viewports = null) {
|
|
8590
|
-
|
|
8591
|
-
viewports
|
|
8592
|
-
|
|
8593
|
-
|
|
8594
|
-
|
|
8595
|
-
|
|
8656
|
+
this.tilesetInitializationPromise.then(() => {
|
|
8657
|
+
if (!viewports && this.lastUpdatedVieports) {
|
|
8658
|
+
viewports = this.lastUpdatedVieports;
|
|
8659
|
+
} else {
|
|
8660
|
+
this.lastUpdatedVieports = viewports;
|
|
8661
|
+
}
|
|
8662
|
+
this.doUpdate(viewports);
|
|
8663
|
+
});
|
|
8596
8664
|
}
|
|
8597
8665
|
async selectTiles(viewports = null) {
|
|
8666
|
+
await this.tilesetInitializationPromise;
|
|
8598
8667
|
if (viewports) {
|
|
8599
8668
|
this.lastUpdatedVieports = viewports;
|
|
8600
8669
|
}
|
|
@@ -8719,6 +8788,8 @@
|
|
|
8719
8788
|
tilesRenderable++;
|
|
8720
8789
|
if (tile.content.pointCount) {
|
|
8721
8790
|
pointsRenderable += tile.content.pointCount;
|
|
8791
|
+
} else {
|
|
8792
|
+
pointsRenderable += tile.content.vertexCount;
|
|
8722
8793
|
}
|
|
8723
8794
|
}
|
|
8724
8795
|
}
|
|
@@ -8726,17 +8797,43 @@
|
|
|
8726
8797
|
this.stats.get(TILES_RENDERABLE).count = tilesRenderable;
|
|
8727
8798
|
this.stats.get(POINTS_COUNT).count = pointsRenderable;
|
|
8728
8799
|
}
|
|
8729
|
-
_initializeTileSet(tilesetJson) {
|
|
8800
|
+
async _initializeTileSet(tilesetJson) {
|
|
8801
|
+
if (this.type === TILESET_TYPE.I3S) {
|
|
8802
|
+
this.calculateViewPropsI3S();
|
|
8803
|
+
tilesetJson.root = await tilesetJson.root;
|
|
8804
|
+
}
|
|
8730
8805
|
this.root = this._initializeTileHeaders(tilesetJson, null);
|
|
8731
8806
|
if (this.type === TILESET_TYPE.TILES3D) {
|
|
8732
|
-
this.
|
|
8807
|
+
this._initializeTiles3DTileset(tilesetJson);
|
|
8808
|
+
this.calculateViewPropsTiles3D();
|
|
8733
8809
|
}
|
|
8734
8810
|
if (this.type === TILESET_TYPE.I3S) {
|
|
8735
8811
|
this._initializeI3STileset();
|
|
8736
8812
|
}
|
|
8737
|
-
this._calculateViewProps();
|
|
8738
8813
|
}
|
|
8739
|
-
|
|
8814
|
+
calculateViewPropsI3S() {
|
|
8815
|
+
const fullExtent = this.tileset.fullExtent;
|
|
8816
|
+
if (fullExtent) {
|
|
8817
|
+
const { xmin, xmax, ymin, ymax, zmin, zmax } = fullExtent;
|
|
8818
|
+
this.cartographicCenter = new Vector3(xmin + (xmax - xmin) / 2, ymin + (ymax - ymin) / 2, zmin + (zmax - zmin) / 2);
|
|
8819
|
+
this.cartesianCenter = Ellipsoid.WGS84.cartographicToCartesian(this.cartographicCenter, new Vector3());
|
|
8820
|
+
this.zoom = getZoomFromFullExtent(fullExtent, this.cartographicCenter, this.cartesianCenter);
|
|
8821
|
+
return;
|
|
8822
|
+
}
|
|
8823
|
+
const extent = this.tileset.store?.extent;
|
|
8824
|
+
if (extent) {
|
|
8825
|
+
const [xmin, ymin, xmax, ymax] = extent;
|
|
8826
|
+
this.cartographicCenter = new Vector3(xmin + (xmax - xmin) / 2, ymin + (ymax - ymin) / 2, 0);
|
|
8827
|
+
this.cartesianCenter = Ellipsoid.WGS84.cartographicToCartesian(this.cartographicCenter, new Vector3());
|
|
8828
|
+
this.zoom = getZoomFromExtent(extent, this.cartographicCenter, this.cartesianCenter);
|
|
8829
|
+
return;
|
|
8830
|
+
}
|
|
8831
|
+
console.warn("Extent is not defined in the tileset header");
|
|
8832
|
+
this.cartographicCenter = new Vector3();
|
|
8833
|
+
this.zoom = 1;
|
|
8834
|
+
return;
|
|
8835
|
+
}
|
|
8836
|
+
calculateViewPropsTiles3D() {
|
|
8740
8837
|
const root = this.root;
|
|
8741
8838
|
assert2(root);
|
|
8742
8839
|
const { center } = root.boundingVolume;
|
|
@@ -8829,6 +8926,11 @@
|
|
|
8829
8926
|
if (!loaded) {
|
|
8830
8927
|
return;
|
|
8831
8928
|
}
|
|
8929
|
+
if (this.type === TILESET_TYPE.I3S) {
|
|
8930
|
+
const nodesInNodePages = this.tileset?.nodePagesTile?.nodesInNodePages || 0;
|
|
8931
|
+
this.stats.get(TILES_TOTAL).reset();
|
|
8932
|
+
this.stats.get(TILES_TOTAL).addCount(nodesInNodePages);
|
|
8933
|
+
}
|
|
8832
8934
|
if (tile && tile.content) {
|
|
8833
8935
|
calculateTransformProps(tile, tile.content);
|
|
8834
8936
|
}
|
|
@@ -8894,7 +8996,7 @@
|
|
|
8894
8996
|
this._unloadTile(tile);
|
|
8895
8997
|
tile.destroy();
|
|
8896
8998
|
}
|
|
8897
|
-
|
|
8999
|
+
_initializeTiles3DTileset(tilesetJson) {
|
|
8898
9000
|
this.asset = tilesetJson.asset;
|
|
8899
9001
|
if (!this.asset) {
|
|
8900
9002
|
throw new Error("Tileset must have an asset property.");
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports.getZoomFromBoundingVolume = getZoomFromBoundingVolume;
|
|
9
|
+
exports.getZoomFromFullExtent = getZoomFromFullExtent;
|
|
10
|
+
exports.getZoomFromExtent = getZoomFromExtent;
|
|
11
|
+
|
|
12
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
7
13
|
|
|
8
14
|
var _core = require("@math.gl/core");
|
|
9
15
|
|
|
10
16
|
var _culling = require("@math.gl/culling");
|
|
11
17
|
|
|
18
|
+
var _geospatial = require("@math.gl/geospatial");
|
|
19
|
+
|
|
12
20
|
var WGS84_RADIUS_X = 6378137.0;
|
|
13
21
|
var WGS84_RADIUS_Y = 6378137.0;
|
|
14
22
|
var WGS84_RADIUS_Z = 6356752.3142451793;
|
|
@@ -33,6 +41,30 @@ function getZoomFromBoundingVolume(boundingVolume, cartorgraphicCenter) {
|
|
|
33
41
|
return 1;
|
|
34
42
|
}
|
|
35
43
|
|
|
44
|
+
function getZoomFromFullExtent(fullExtent, cartorgraphicCenter, cartesianCenter) {
|
|
45
|
+
var extentVertex = _geospatial.Ellipsoid.WGS84.cartographicToCartesian([fullExtent.xmax, fullExtent.ymax, fullExtent.zmax], new _core.Vector3());
|
|
46
|
+
|
|
47
|
+
var extentSize = Math.sqrt(Math.pow(extentVertex[0] - cartesianCenter[0], 2) + Math.pow(extentVertex[1] - cartesianCenter[1], 2) + Math.pow(extentVertex[2] - cartesianCenter[2], 2));
|
|
48
|
+
return Math.log2(WGS84_RADIUS_Z / (extentSize + cartorgraphicCenter[2]));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getZoomFromExtent(extent, cartorgraphicCenter, cartesianCenter) {
|
|
52
|
+
var _extent = (0, _slicedToArray2.default)(extent, 4),
|
|
53
|
+
xmin = _extent[0],
|
|
54
|
+
ymin = _extent[1],
|
|
55
|
+
xmax = _extent[2],
|
|
56
|
+
ymax = _extent[3];
|
|
57
|
+
|
|
58
|
+
return getZoomFromFullExtent({
|
|
59
|
+
xmin: xmin,
|
|
60
|
+
xmax: xmax,
|
|
61
|
+
ymin: ymin,
|
|
62
|
+
ymax: ymax,
|
|
63
|
+
zmin: 0,
|
|
64
|
+
zmax: 0
|
|
65
|
+
}, cartorgraphicCenter, cartesianCenter);
|
|
66
|
+
}
|
|
67
|
+
|
|
36
68
|
function getObbSize(halfAxes) {
|
|
37
69
|
halfAxes.getColumn(0, scratchVector);
|
|
38
70
|
var axeY = halfAxes.getColumn(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/tileset/helpers/zoom.ts"],"names":["WGS84_RADIUS_X","WGS84_RADIUS_Y","WGS84_RADIUS_Z","scratchVector","Vector3","getZoomFromBoundingVolume","boundingVolume","cartorgraphicCenter","OrientedBoundingBox","halfAxes","obbSize","getObbSize","Math","log2","BoundingSphere","radius","width","height","zoomX","zoomY","getColumn","axeY","axeZ","farthestVertex","add","size","len"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/tileset/helpers/zoom.ts"],"names":["WGS84_RADIUS_X","WGS84_RADIUS_Y","WGS84_RADIUS_Z","scratchVector","Vector3","getZoomFromBoundingVolume","boundingVolume","cartorgraphicCenter","OrientedBoundingBox","halfAxes","obbSize","getObbSize","Math","log2","BoundingSphere","radius","width","height","zoomX","zoomY","getZoomFromFullExtent","fullExtent","cartesianCenter","extentVertex","Ellipsoid","WGS84","cartographicToCartesian","xmax","ymax","zmax","extentSize","sqrt","pow","getZoomFromExtent","extent","xmin","ymin","zmin","getColumn","axeY","axeZ","farthestVertex","add","size","len"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAGA,IAAMA,cAAc,GAAG,SAAvB;AAC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nB,CAAb;AACA,MAAMG,cAAc,GAAGtC,aAAa,CAACuC,GAAd,CAAkBH,IAAlB,EAAwBG,GAAxB,CAA4BF,IAA5B,CAAvB;AACA,MAAMG,IAAI,GAAGF,cAAc,CAACG,GAAf,EAAb;AACA,SAAOD,IAAP;AACD","sourcesContent":["import {Vector3} from '@math.gl/core';\nimport {BoundingSphere, OrientedBoundingBox} from '@math.gl/culling';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {BoundingRectangle} from '../../types';\n\nconst WGS84_RADIUS_X = 6378137.0;\nconst WGS84_RADIUS_Y = 6378137.0;\nconst WGS84_RADIUS_Z = 6356752.3142451793;\n\nconst scratchVector = new Vector3();\n\n/**\n * Calculate appropriate zoom value for a particular boundingVolume\n * @param boundingVolume - the instance of bounding volume\n * @param cartorgraphicCenter - cartographic center of the bounding volume\n * @returns {number} - zoom value\n */\nexport function getZoomFromBoundingVolume(\n boundingVolume: BoundingSphere | OrientedBoundingBox | BoundingRectangle,\n cartorgraphicCenter: Vector3\n) {\n if (boundingVolume instanceof OrientedBoundingBox) {\n // OrientedBoundingBox\n const {halfAxes} = boundingVolume;\n const obbSize = getObbSize(halfAxes);\n // Use WGS84_RADIUS_Z to allign with BoundingSphere algorithm\n // Add the tile elevation value for correct zooming to elevated tiles\n return Math.log2(WGS84_RADIUS_Z / (obbSize + cartorgraphicCenter[2]));\n } else if (boundingVolume instanceof BoundingSphere) {\n // BoundingSphere\n const {radius} = boundingVolume;\n // Add the tile elevation value for correct zooming to elevated tiles\n return Math.log2(WGS84_RADIUS_Z / (radius + cartorgraphicCenter[2]));\n } else if (boundingVolume.width && boundingVolume.height) {\n // BoundingRectangle\n const {width, height} = boundingVolume;\n const zoomX = Math.log2(WGS84_RADIUS_X / width);\n const zoomY = Math.log2(WGS84_RADIUS_Y / height);\n\n return (zoomX + zoomY) / 2;\n }\n\n return 1;\n}\n\n/**\n * Calculate initial zoom for the tileset from 3D `fullExtent` defined in\n * the tileset metadata\n * @param fullExtent - 3D extent of the tileset\n * @param fullExtent.xmin - minimal longitude in decimal degrees\n * @param fullExtent.xmax - maximal longitude in decimal degrees\n * @param fullExtent.ymin - minimal latitude in decimal degrees\n * @param fullExtent.ymax - maximal latitude in decimal degrees\n * @param fullExtent.zmin - minimal elevation in meters\n * @param fullExtent.zmax - maximal elevation in meters\n * @param cartorgraphicCenter - tileset center in cartographic coordinate system\n * @param cartesianCenter - tileset center in cartesian coordinate system\n * @returns - initial zoom for the tileset\n */\nexport function getZoomFromFullExtent(\n fullExtent: {\n xmin: number;\n xmax: number;\n ymin: number;\n ymax: number;\n zmin: number;\n zmax: number;\n },\n cartorgraphicCenter: Vector3,\n cartesianCenter: Vector3\n) {\n const extentVertex = Ellipsoid.WGS84.cartographicToCartesian(\n [fullExtent.xmax, fullExtent.ymax, fullExtent.zmax],\n new Vector3()\n );\n const extentSize = Math.sqrt(\n Math.pow(extentVertex[0] - cartesianCenter[0], 2) +\n Math.pow(extentVertex[1] - cartesianCenter[1], 2) +\n Math.pow(extentVertex[2] - cartesianCenter[2], 2)\n );\n return Math.log2(WGS84_RADIUS_Z / (extentSize + cartorgraphicCenter[2]));\n}\n\n/**\n * Calculate initial zoom for the tileset from 2D `extent` defined in\n * the tileset metadata\n * @param extent - 2D extent of the tileset. It is array of 4 elements [xmin, ymin, xmax, ymax]\n * @param extent[0] - minimal longitude in decimal degrees\n * @param extent[1] - minimal latitude in decimal degrees\n * @param extent[2] - maximal longitude in decimal degrees\n * @param extent[3] - maximal latitude in decimal degrees\n * @param cartorgraphicCenter - tileset center in cartographic coordinate system\n * @param cartesianCenter - tileset center in cartesian coordinate system\n * @returns - initial zoom for the tileset\n */\nexport function getZoomFromExtent(\n extent: [number, number, number, number],\n cartorgraphicCenter: Vector3,\n cartesianCenter: Vector3\n) {\n const [xmin, ymin, xmax, ymax] = extent;\n return getZoomFromFullExtent(\n {xmin, xmax, ymin, ymax, zmin: 0, zmax: 0},\n cartorgraphicCenter,\n cartesianCenter\n );\n}\n\nfunction getObbSize(halfAxes) {\n halfAxes.getColumn(0, scratchVector);\n const axeY = halfAxes.getColumn(1);\n const axeZ = halfAxes.getColumn(2);\n const farthestVertex = scratchVector.add(axeY).add(axeZ);\n const size = farthestVertex.len();\n return size;\n}\n"],"file":"zoom.js"}
|