@loaders.gl/tiles 3.1.8 → 3.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/dist.min.js +207 -309
  2. package/dist/es5/tileset/helpers/frame-state.js +79 -0
  3. package/dist/es5/tileset/helpers/frame-state.js.map +1 -1
  4. package/dist/es5/tileset/helpers/i3s-lod.js +17 -26
  5. package/dist/es5/tileset/helpers/i3s-lod.js.map +1 -1
  6. package/dist/es5/tileset/tile-3d.js +5 -0
  7. package/dist/es5/tileset/tile-3d.js.map +1 -1
  8. package/dist/es5/tileset/tileset-3d.js +152 -71
  9. package/dist/es5/tileset/tileset-3d.js.map +1 -1
  10. package/dist/esm/tileset/helpers/frame-state.js +52 -0
  11. package/dist/esm/tileset/helpers/frame-state.js.map +1 -1
  12. package/dist/esm/tileset/helpers/i3s-lod.js +17 -27
  13. package/dist/esm/tileset/helpers/i3s-lod.js.map +1 -1
  14. package/dist/esm/tileset/tile-3d.js +4 -0
  15. package/dist/esm/tileset/tile-3d.js.map +1 -1
  16. package/dist/esm/tileset/tileset-3d.js +41 -9
  17. package/dist/esm/tileset/tileset-3d.js.map +1 -1
  18. package/dist/tileset/helpers/frame-state.d.ts +14 -0
  19. package/dist/tileset/helpers/frame-state.d.ts.map +1 -1
  20. package/dist/tileset/helpers/frame-state.js +49 -1
  21. package/dist/tileset/helpers/i3s-lod.d.ts.map +1 -1
  22. package/dist/tileset/helpers/i3s-lod.js +17 -16
  23. package/dist/tileset/tile-3d.d.ts +5 -0
  24. package/dist/tileset/tile-3d.d.ts.map +1 -1
  25. package/dist/tileset/tile-3d.js +7 -0
  26. package/dist/tileset/tileset-3d.d.ts +19 -1
  27. package/dist/tileset/tileset-3d.d.ts.map +1 -1
  28. package/dist/tileset/tileset-3d.js +46 -8
  29. package/package.json +5 -5
  30. package/src/tileset/helpers/frame-state.ts +56 -0
  31. package/src/tileset/helpers/i3s-lod.ts +18 -19
  32. package/src/tileset/tile-3d.ts +8 -0
  33. package/src/tileset/tileset-3d.ts +57 -8
package/dist/dist.min.js CHANGED
@@ -3215,7 +3215,7 @@
3215
3215
  }
3216
3216
  });
3217
3217
 
3218
- // node_modules/@probe.gl/stats/dist/esm/utils/hi-res-timestamp.js
3218
+ // ../../node_modules/@probe.gl/stats/dist/esm/utils/hi-res-timestamp.js
3219
3219
  function getHiResTimestamp() {
3220
3220
  let timestamp;
3221
3221
  if (typeof window !== "undefined" && window.performance) {
@@ -3229,14 +3229,14 @@
3229
3229
  return timestamp;
3230
3230
  }
3231
3231
  var init_hi_res_timestamp = __esm({
3232
- "node_modules/@probe.gl/stats/dist/esm/utils/hi-res-timestamp.js"() {
3232
+ "../../node_modules/@probe.gl/stats/dist/esm/utils/hi-res-timestamp.js"() {
3233
3233
  }
3234
3234
  });
3235
3235
 
3236
- // node_modules/@probe.gl/stats/dist/esm/lib/stat.js
3236
+ // ../../node_modules/@probe.gl/stats/dist/esm/lib/stat.js
3237
3237
  var Stat;
3238
3238
  var init_stat = __esm({
3239
- "node_modules/@probe.gl/stats/dist/esm/lib/stat.js"() {
3239
+ "../../node_modules/@probe.gl/stats/dist/esm/lib/stat.js"() {
3240
3240
  init_defineProperty();
3241
3241
  init_hi_res_timestamp();
3242
3242
  Stat = class {
@@ -3352,10 +3352,10 @@
3352
3352
  }
3353
3353
  });
3354
3354
 
3355
- // node_modules/@probe.gl/stats/dist/esm/lib/stats.js
3355
+ // ../../node_modules/@probe.gl/stats/dist/esm/lib/stats.js
3356
3356
  var Stats;
3357
3357
  var init_stats = __esm({
3358
- "node_modules/@probe.gl/stats/dist/esm/lib/stats.js"() {
3358
+ "../../node_modules/@probe.gl/stats/dist/esm/lib/stats.js"() {
3359
3359
  init_defineProperty();
3360
3360
  init_stat();
3361
3361
  Stats = class {
@@ -3425,9 +3425,9 @@
3425
3425
  }
3426
3426
  });
3427
3427
 
3428
- // node_modules/@probe.gl/stats/dist/esm/index.js
3428
+ // ../../node_modules/@probe.gl/stats/dist/esm/index.js
3429
3429
  var init_esm3 = __esm({
3430
- "node_modules/@probe.gl/stats/dist/esm/index.js"() {
3430
+ "../../node_modules/@probe.gl/stats/dist/esm/index.js"() {
3431
3431
  init_stats();
3432
3432
  init_stat();
3433
3433
  init_hi_res_timestamp();
@@ -3469,7 +3469,7 @@
3469
3469
  var DEFAULT_VERSION, VERSION;
3470
3470
  var init_version = __esm({
3471
3471
  "../worker-utils/src/lib/env-utils/version.ts"() {
3472
- DEFAULT_VERSION = "latest";
3472
+ DEFAULT_VERSION = "beta";
3473
3473
  VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : DEFAULT_VERSION;
3474
3474
  if (typeof __VERSION__ === "undefined") {
3475
3475
  console.error("loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.");
@@ -3516,13 +3516,13 @@
3516
3516
  init_assert3();
3517
3517
  WorkerJob = class {
3518
3518
  constructor(jobName, workerThread) {
3519
- this.name = jobName;
3520
- this.workerThread = workerThread;
3521
3519
  this.isRunning = true;
3522
3520
  this._resolve = () => {
3523
3521
  };
3524
3522
  this._reject = () => {
3525
3523
  };
3524
+ this.name = jobName;
3525
+ this.workerThread = workerThread;
3526
3526
  this.result = new Promise((resolve, reject) => {
3527
3527
  this._resolve = resolve;
3528
3528
  this._reject = reject;
@@ -3549,6 +3549,21 @@
3549
3549
  }
3550
3550
  });
3551
3551
 
3552
+ // ../worker-utils/src/lib/node/worker_threads-browser.js
3553
+ var Worker2;
3554
+ var init_worker_threads_browser = __esm({
3555
+ "../worker-utils/src/lib/node/worker_threads-browser.js"() {
3556
+ Worker2 = class {
3557
+ on(message, cb) {
3558
+ }
3559
+ postMessage(...args) {
3560
+ }
3561
+ terminate() {
3562
+ }
3563
+ };
3564
+ }
3565
+ });
3566
+
3552
3567
  // ../worker-utils/src/lib/worker-utils/get-loadable-worker-url.ts
3553
3568
  function getLoadableWorkerURL(props) {
3554
3569
  assert3(props.source && !props.url || !props.source && props.url);
@@ -3636,6 +3651,8 @@
3636
3651
  var NOOP, WorkerThread;
3637
3652
  var init_worker_thread = __esm({
3638
3653
  "../worker-utils/src/lib/worker-farm/worker-thread.ts"() {
3654
+ init_worker_threads_browser();
3655
+ init_globals2();
3639
3656
  init_assert3();
3640
3657
  init_get_loadable_worker_url();
3641
3658
  init_get_transfer_list();
@@ -3652,10 +3669,10 @@
3652
3669
  this.url = url;
3653
3670
  this.onMessage = NOOP;
3654
3671
  this.onError = (error) => console.log(error);
3655
- this.worker = this._createBrowserWorker();
3672
+ this.worker = isBrowser2 ? this._createBrowserWorker() : this._createNodeWorker();
3656
3673
  }
3657
3674
  static isSupported() {
3658
- return typeof Worker !== "undefined";
3675
+ return typeof Worker !== "undefined" && isBrowser2;
3659
3676
  }
3660
3677
  destroy() {
3661
3678
  this.onMessage = NOOP;
@@ -3698,6 +3715,27 @@
3698
3715
  worker.onmessageerror = (event) => console.error(event);
3699
3716
  return worker;
3700
3717
  }
3718
+ _createNodeWorker() {
3719
+ let worker;
3720
+ if (this.url) {
3721
+ const absolute = this.url.includes(":/") || this.url.startsWith("/");
3722
+ const url = absolute ? this.url : `./${this.url}`;
3723
+ worker = new Worker2(url, { eval: false });
3724
+ } else if (this.source) {
3725
+ worker = new Worker2(this.source, { eval: true });
3726
+ } else {
3727
+ throw new Error("no worker");
3728
+ }
3729
+ worker.on("message", (data) => {
3730
+ this.onMessage(data);
3731
+ });
3732
+ worker.on("error", (error) => {
3733
+ this.onError(error);
3734
+ });
3735
+ worker.on("exit", (code) => {
3736
+ });
3737
+ return worker;
3738
+ }
3701
3739
  };
3702
3740
  }
3703
3741
  });
@@ -3726,6 +3764,9 @@
3726
3764
  this.url = props.url;
3727
3765
  this.setProps(props);
3728
3766
  }
3767
+ static isSupported() {
3768
+ return WorkerThread.isSupported();
3769
+ }
3729
3770
  destroy() {
3730
3771
  this.idleQueue.forEach((worker) => worker.destroy());
3731
3772
  this.isDestroyed = true;
@@ -3822,9 +3863,9 @@
3822
3863
  DEFAULT_PROPS = {
3823
3864
  maxConcurrency: 3,
3824
3865
  maxMobileConcurrency: 1,
3866
+ reuseWorkers: true,
3825
3867
  onDebug: () => {
3826
- },
3827
- reuseWorkers: true
3868
+ }
3828
3869
  };
3829
3870
  WorkerFarm = class {
3830
3871
  constructor(props) {
@@ -3845,6 +3886,7 @@
3845
3886
  for (const workerPool of this.workerPools.values()) {
3846
3887
  workerPool.destroy();
3847
3888
  }
3889
+ this.workerPools = new Map();
3848
3890
  }
3849
3891
  setProps(props) {
3850
3892
  this.props = { ...this.props, ...props };
@@ -3904,7 +3946,7 @@
3904
3946
  var init_get_worker_url = __esm({
3905
3947
  "../worker-utils/src/lib/worker-api/get-worker-url.ts"() {
3906
3948
  init_assert3();
3907
- NPM_TAG = "latest";
3949
+ NPM_TAG = "beta";
3908
3950
  }
3909
3951
  });
3910
3952
 
@@ -3928,6 +3970,7 @@
3928
3970
  var init_src = __esm({
3929
3971
  "../worker-utils/src/index.ts"() {
3930
3972
  init_assert3();
3973
+ init_globals2();
3931
3974
  init_worker_farm();
3932
3975
  init_get_worker_url();
3933
3976
  init_validate_worker_version();
@@ -3939,6 +3982,9 @@
3939
3982
  if (!WorkerFarm.isSupported()) {
3940
3983
  return false;
3941
3984
  }
3985
+ if (!isBrowser2 && !options?._nodeWorkers) {
3986
+ return false;
3987
+ }
3942
3988
  return loader.worker && options?.worker;
3943
3989
  }
3944
3990
  async function parseWithWorker(loader, data, options, context, parseOnMainThread) {
@@ -3980,6 +4026,7 @@
3980
4026
  var init_parse_with_worker = __esm({
3981
4027
  "../loader-utils/src/lib/worker-loader-utils/parse-with-worker.ts"() {
3982
4028
  init_src();
4029
+ init_src();
3983
4030
  }
3984
4031
  });
3985
4032
 
@@ -4068,230 +4115,11 @@
4068
4115
  }
4069
4116
  });
4070
4117
 
4071
- // ../loader-utils/node_modules/@probe.gl/stats/dist/esm/utils/hi-res-timestamp.js
4072
- function getHiResTimestamp2() {
4073
- let timestamp;
4074
- if (typeof window !== "undefined" && window.performance) {
4075
- timestamp = window.performance.now();
4076
- } else if (typeof process !== "undefined" && process.hrtime) {
4077
- const timeParts = process.hrtime();
4078
- timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
4079
- } else {
4080
- timestamp = Date.now();
4081
- }
4082
- return timestamp;
4083
- }
4084
- var init_hi_res_timestamp2 = __esm({
4085
- "../loader-utils/node_modules/@probe.gl/stats/dist/esm/utils/hi-res-timestamp.js"() {
4086
- }
4087
- });
4088
-
4089
- // ../loader-utils/node_modules/@probe.gl/stats/dist/esm/lib/stat.js
4090
- var Stat2;
4091
- var init_stat2 = __esm({
4092
- "../loader-utils/node_modules/@probe.gl/stats/dist/esm/lib/stat.js"() {
4093
- init_defineProperty();
4094
- init_hi_res_timestamp2();
4095
- Stat2 = class {
4096
- constructor(name, type) {
4097
- _defineProperty(this, "name", void 0);
4098
- _defineProperty(this, "type", void 0);
4099
- _defineProperty(this, "sampleSize", 1);
4100
- _defineProperty(this, "time", void 0);
4101
- _defineProperty(this, "count", void 0);
4102
- _defineProperty(this, "samples", void 0);
4103
- _defineProperty(this, "lastTiming", void 0);
4104
- _defineProperty(this, "lastSampleTime", void 0);
4105
- _defineProperty(this, "lastSampleCount", void 0);
4106
- _defineProperty(this, "_count", 0);
4107
- _defineProperty(this, "_time", 0);
4108
- _defineProperty(this, "_samples", 0);
4109
- _defineProperty(this, "_startTime", 0);
4110
- _defineProperty(this, "_timerPending", false);
4111
- this.name = name;
4112
- this.type = type;
4113
- this.reset();
4114
- }
4115
- setSampleSize(samples) {
4116
- this.sampleSize = samples;
4117
- return this;
4118
- }
4119
- incrementCount() {
4120
- this.addCount(1);
4121
- return this;
4122
- }
4123
- decrementCount() {
4124
- this.subtractCount(1);
4125
- return this;
4126
- }
4127
- addCount(value) {
4128
- this._count += value;
4129
- this._samples++;
4130
- this._checkSampling();
4131
- return this;
4132
- }
4133
- subtractCount(value) {
4134
- this._count -= value;
4135
- this._samples++;
4136
- this._checkSampling();
4137
- return this;
4138
- }
4139
- addTime(time) {
4140
- this._time += time;
4141
- this.lastTiming = time;
4142
- this._samples++;
4143
- this._checkSampling();
4144
- return this;
4145
- }
4146
- timeStart() {
4147
- this._startTime = getHiResTimestamp2();
4148
- this._timerPending = true;
4149
- return this;
4150
- }
4151
- timeEnd() {
4152
- if (!this._timerPending) {
4153
- return this;
4154
- }
4155
- this.addTime(getHiResTimestamp2() - this._startTime);
4156
- this._timerPending = false;
4157
- this._checkSampling();
4158
- return this;
4159
- }
4160
- getSampleAverageCount() {
4161
- return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
4162
- }
4163
- getSampleAverageTime() {
4164
- return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
4165
- }
4166
- getSampleHz() {
4167
- return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1e3) : 0;
4168
- }
4169
- getAverageCount() {
4170
- return this.samples > 0 ? this.count / this.samples : 0;
4171
- }
4172
- getAverageTime() {
4173
- return this.samples > 0 ? this.time / this.samples : 0;
4174
- }
4175
- getHz() {
4176
- return this.time > 0 ? this.samples / (this.time / 1e3) : 0;
4177
- }
4178
- reset() {
4179
- this.time = 0;
4180
- this.count = 0;
4181
- this.samples = 0;
4182
- this.lastTiming = 0;
4183
- this.lastSampleTime = 0;
4184
- this.lastSampleCount = 0;
4185
- this._count = 0;
4186
- this._time = 0;
4187
- this._samples = 0;
4188
- this._startTime = 0;
4189
- this._timerPending = false;
4190
- return this;
4191
- }
4192
- _checkSampling() {
4193
- if (this._samples === this.sampleSize) {
4194
- this.lastSampleTime = this._time;
4195
- this.lastSampleCount = this._count;
4196
- this.count += this._count;
4197
- this.time += this._time;
4198
- this.samples += this._samples;
4199
- this._time = 0;
4200
- this._count = 0;
4201
- this._samples = 0;
4202
- }
4203
- }
4204
- };
4205
- }
4206
- });
4207
-
4208
- // ../loader-utils/node_modules/@probe.gl/stats/dist/esm/lib/stats.js
4209
- var Stats2;
4210
- var init_stats2 = __esm({
4211
- "../loader-utils/node_modules/@probe.gl/stats/dist/esm/lib/stats.js"() {
4212
- init_defineProperty();
4213
- init_stat2();
4214
- Stats2 = class {
4215
- constructor(options) {
4216
- _defineProperty(this, "id", void 0);
4217
- _defineProperty(this, "stats", {});
4218
- this.id = options.id;
4219
- this.stats = {};
4220
- this._initializeStats(options.stats);
4221
- Object.seal(this);
4222
- }
4223
- get(name) {
4224
- let type = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "count";
4225
- return this._getOrCreate({
4226
- name,
4227
- type
4228
- });
4229
- }
4230
- get size() {
4231
- return Object.keys(this.stats).length;
4232
- }
4233
- reset() {
4234
- for (const key in this.stats) {
4235
- this.stats[key].reset();
4236
- }
4237
- return this;
4238
- }
4239
- forEach(fn) {
4240
- for (const key in this.stats) {
4241
- fn(this.stats[key]);
4242
- }
4243
- }
4244
- getTable() {
4245
- const table = {};
4246
- this.forEach((stat) => {
4247
- table[stat.name] = {
4248
- time: stat.time || 0,
4249
- count: stat.count || 0,
4250
- average: stat.getAverageTime() || 0,
4251
- hz: stat.getHz() || 0
4252
- };
4253
- });
4254
- return table;
4255
- }
4256
- _initializeStats() {
4257
- let stats = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
4258
- stats.forEach((stat) => this._getOrCreate(stat));
4259
- }
4260
- _getOrCreate(stat) {
4261
- if (!stat || !stat.name) {
4262
- return null;
4263
- }
4264
- const {
4265
- name,
4266
- type
4267
- } = stat;
4268
- if (!this.stats[name]) {
4269
- if (stat instanceof Stat2) {
4270
- this.stats[name] = stat;
4271
- } else {
4272
- this.stats[name] = new Stat2(name, type);
4273
- }
4274
- }
4275
- return this.stats[name];
4276
- }
4277
- };
4278
- }
4279
- });
4280
-
4281
- // ../loader-utils/node_modules/@probe.gl/stats/dist/esm/index.js
4282
- var init_esm4 = __esm({
4283
- "../loader-utils/node_modules/@probe.gl/stats/dist/esm/index.js"() {
4284
- init_stats2();
4285
- init_stat2();
4286
- init_hi_res_timestamp2();
4287
- }
4288
- });
4289
-
4290
4118
  // ../loader-utils/src/lib/request-utils/request-scheduler.ts
4291
4119
  var STAT_QUEUED_REQUESTS, STAT_ACTIVE_REQUESTS, STAT_CANCELLED_REQUESTS, STAT_QUEUED_REQUESTS_EVER, STAT_ACTIVE_REQUESTS_EVER, DEFAULT_PROPS2, RequestScheduler;
4292
4120
  var init_request_scheduler = __esm({
4293
4121
  "../loader-utils/src/lib/request-utils/request-scheduler.ts"() {
4294
- init_esm4();
4122
+ init_esm3();
4295
4123
  STAT_QUEUED_REQUESTS = "Queued Requests";
4296
4124
  STAT_ACTIVE_REQUESTS = "Active Requests";
4297
4125
  STAT_CANCELLED_REQUESTS = "Cancelled Requests";
@@ -4309,7 +4137,7 @@
4309
4137
  this.requestMap = new Map();
4310
4138
  this.deferredUpdate = null;
4311
4139
  this.props = { ...DEFAULT_PROPS2, ...props };
4312
- this.stats = new Stats2({ id: this.props.id });
4140
+ this.stats = new Stats({ id: this.props.id });
4313
4141
  this.stats.get(STAT_QUEUED_REQUESTS);
4314
4142
  this.stats.get(STAT_ACTIVE_REQUESTS);
4315
4143
  this.stats.get(STAT_CANCELLED_REQUESTS);
@@ -5190,7 +5018,7 @@
5190
5018
  });
5191
5019
 
5192
5020
  // ../../node_modules/@math.gl/culling/dist/esm/index.js
5193
- var init_esm5 = __esm({
5021
+ var init_esm4 = __esm({
5194
5022
  "../../node_modules/@math.gl/culling/dist/esm/index.js"() {
5195
5023
  init_constants2();
5196
5024
  init_axis_aligned_bounding_box();
@@ -5216,23 +5044,59 @@
5216
5044
  const viewportCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(viewportCenterCartographic, new Vector3());
5217
5045
  const enuToFixedTransform = Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);
5218
5046
  const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
5219
- const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new Vector3());
5047
+ const cameraPositionCartesian2 = Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new Vector3());
5220
5048
  const cameraDirectionCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraDirection).scale(metersPerUnit))).normalize();
5221
5049
  const cameraUpCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))).normalize();
5222
5050
  commonSpacePlanesToWGS84(viewport, viewportCenterCartesian);
5051
+ const ViewportClass = viewport.constructor;
5052
+ const { longitude, latitude, width, bearing, zoom } = viewport;
5053
+ const topDownViewport = new ViewportClass({
5054
+ longitude,
5055
+ latitude,
5056
+ height,
5057
+ width,
5058
+ bearing,
5059
+ zoom,
5060
+ pitch: 0
5061
+ });
5223
5062
  return {
5224
5063
  camera: {
5225
- position: cameraPositionCartesian,
5064
+ position: cameraPositionCartesian2,
5226
5065
  direction: cameraDirectionCartesian,
5227
5066
  up: cameraUpCartesian
5228
5067
  },
5229
5068
  viewport,
5069
+ topDownViewport,
5230
5070
  height,
5231
5071
  cullingVolume,
5232
5072
  frameNumber,
5233
5073
  sseDenominator: 1.15
5234
5074
  };
5235
5075
  }
5076
+ function limitSelectedTiles(tiles, frameState, maximumTilesSelected) {
5077
+ if (maximumTilesSelected === 0 || tiles.length <= maximumTilesSelected) {
5078
+ return [tiles, []];
5079
+ }
5080
+ const tuples = [];
5081
+ const { longitude: viewportLongitude, latitude: viewportLatitude } = frameState.viewport;
5082
+ for (const [index, tile] of tiles.entries()) {
5083
+ const [longitude, latitude] = tile.header.mbs;
5084
+ const deltaLon = Math.abs(viewportLongitude - longitude);
5085
+ const deltaLat = Math.abs(viewportLatitude - latitude);
5086
+ const distance = Math.sqrt(deltaLat * deltaLat + deltaLon * deltaLon);
5087
+ tuples.push([index, distance]);
5088
+ }
5089
+ const tuplesSorted = tuples.sort((a, b) => a[1] - b[1]);
5090
+ const selectedTiles = [];
5091
+ for (let i = 0; i < maximumTilesSelected; i++) {
5092
+ selectedTiles.push(tiles[tuplesSorted[i][0]]);
5093
+ }
5094
+ const unselectedTiles = [];
5095
+ for (let i = maximumTilesSelected; i < tuplesSorted.length; i++) {
5096
+ unselectedTiles.push(tiles[tuplesSorted[i][0]]);
5097
+ }
5098
+ return [selectedTiles, unselectedTiles];
5099
+ }
5236
5100
  function commonSpacePlanesToWGS84(viewport, viewportCenterCartesian) {
5237
5101
  const frustumPlanes = viewport.getFrustumPlanes();
5238
5102
  let i = 0;
@@ -5249,7 +5113,7 @@
5249
5113
  var init_frame_state = __esm({
5250
5114
  "src/tileset/helpers/frame-state.ts"() {
5251
5115
  init_esm();
5252
- init_esm5();
5116
+ init_esm4();
5253
5117
  init_esm2();
5254
5118
  scratchVector7 = new Vector3();
5255
5119
  scratchPosition3 = new Vector3();
@@ -5293,7 +5157,7 @@
5293
5157
  var init_zoom = __esm({
5294
5158
  "src/tileset/helpers/zoom.ts"() {
5295
5159
  init_esm();
5296
- init_esm5();
5160
+ init_esm4();
5297
5161
  WGS84_RADIUS_X2 = 6378137;
5298
5162
  WGS84_RADIUS_Y2 = 6378137;
5299
5163
  WGS84_RADIUS_Z2 = 6356752314245179e-9;
@@ -5715,7 +5579,7 @@
5715
5579
  });
5716
5580
 
5717
5581
  // ../../node_modules/probe.gl/dist/esm/utils/hi-res-timestamp.js
5718
- function getHiResTimestamp3() {
5582
+ function getHiResTimestamp2() {
5719
5583
  let timestamp;
5720
5584
  if (isBrowser4 && window_3.performance) {
5721
5585
  timestamp = window_3.performance.now();
@@ -5727,7 +5591,7 @@
5727
5591
  }
5728
5592
  return timestamp;
5729
5593
  }
5730
- var init_hi_res_timestamp3 = __esm({
5594
+ var init_hi_res_timestamp2 = __esm({
5731
5595
  "../../node_modules/probe.gl/dist/esm/utils/hi-res-timestamp.js"() {
5732
5596
  init_globals4();
5733
5597
  }
@@ -5854,7 +5718,7 @@
5854
5718
  init_color();
5855
5719
  init_autobind();
5856
5720
  init_assert4();
5857
- init_hi_res_timestamp3();
5721
+ init_hi_res_timestamp2();
5858
5722
  originalConsole = {
5859
5723
  debug: isBrowser4 ? console.debug || console.log : console.log,
5860
5724
  log: console.log,
@@ -5878,8 +5742,8 @@
5878
5742
  }) {
5879
5743
  this.id = id;
5880
5744
  this.VERSION = VERSION2;
5881
- this._startTs = getHiResTimestamp3();
5882
- this._deltaTs = getHiResTimestamp3();
5745
+ this._startTs = getHiResTimestamp2();
5746
+ this._deltaTs = getHiResTimestamp2();
5883
5747
  this.LOG_THROTTLE_TIMEOUT = 0;
5884
5748
  this._storage = new LocalStorage("__probe-".concat(this.id, "__"), DEFAULT_SETTINGS);
5885
5749
  this.userData = {};
@@ -5900,10 +5764,10 @@
5900
5764
  return this._storage.config.level;
5901
5765
  }
5902
5766
  getTotal() {
5903
- return Number((getHiResTimestamp3() - this._startTs).toPrecision(10));
5767
+ return Number((getHiResTimestamp2() - this._startTs).toPrecision(10));
5904
5768
  }
5905
5769
  getDelta() {
5906
- return Number((getHiResTimestamp3() - this._deltaTs).toPrecision(10));
5770
+ return Number((getHiResTimestamp2() - this._deltaTs).toPrecision(10));
5907
5771
  }
5908
5772
  set priority(newPriority) {
5909
5773
  this.level = newPriority;
@@ -6058,11 +5922,11 @@
6058
5922
  assert4(method);
6059
5923
  opts.total = this.getTotal();
6060
5924
  opts.delta = this.getDelta();
6061
- this._deltaTs = getHiResTimestamp3();
5925
+ this._deltaTs = getHiResTimestamp2();
6062
5926
  const tag = opts.tag || opts.message;
6063
5927
  if (opts.once) {
6064
5928
  if (!cache[tag]) {
6065
- cache[tag] = getHiResTimestamp3();
5929
+ cache[tag] = getHiResTimestamp2();
6066
5930
  } else {
6067
5931
  return noop2;
6068
5932
  }
@@ -6077,42 +5941,42 @@
6077
5941
  }
6078
5942
  });
6079
5943
 
6080
- // ../../node_modules/@probe.gl/stats/dist/esm/utils/hi-res-timestamp.js
6081
- var init_hi_res_timestamp4 = __esm({
6082
- "../../node_modules/@probe.gl/stats/dist/esm/utils/hi-res-timestamp.js"() {
5944
+ // ../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/utils/hi-res-timestamp.js
5945
+ var init_hi_res_timestamp3 = __esm({
5946
+ "../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/utils/hi-res-timestamp.js"() {
6083
5947
  }
6084
5948
  });
6085
5949
 
6086
- // ../../node_modules/@probe.gl/stats/dist/esm/lib/stat.js
6087
- var init_stat3 = __esm({
6088
- "../../node_modules/@probe.gl/stats/dist/esm/lib/stat.js"() {
6089
- init_hi_res_timestamp4();
5950
+ // ../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/lib/stat.js
5951
+ var init_stat2 = __esm({
5952
+ "../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/lib/stat.js"() {
5953
+ init_hi_res_timestamp3();
6090
5954
  }
6091
5955
  });
6092
5956
 
6093
- // ../../node_modules/@probe.gl/stats/dist/esm/lib/stats.js
6094
- var init_stats3 = __esm({
6095
- "../../node_modules/@probe.gl/stats/dist/esm/lib/stats.js"() {
6096
- init_stat3();
5957
+ // ../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/lib/stats.js
5958
+ var init_stats2 = __esm({
5959
+ "../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/lib/stats.js"() {
5960
+ init_stat2();
6097
5961
  }
6098
5962
  });
6099
5963
 
6100
- // ../../node_modules/@probe.gl/stats/dist/esm/index.js
6101
- var init_esm6 = __esm({
6102
- "../../node_modules/@probe.gl/stats/dist/esm/index.js"() {
6103
- init_stats3();
6104
- init_stat3();
6105
- init_hi_res_timestamp4();
5964
+ // ../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/index.js
5965
+ var init_esm5 = __esm({
5966
+ "../../node_modules/probe.gl/node_modules/@probe.gl/stats/dist/esm/index.js"() {
5967
+ init_stats2();
5968
+ init_stat2();
5969
+ init_hi_res_timestamp3();
6106
5970
  }
6107
5971
  });
6108
5972
 
6109
5973
  // ../../node_modules/probe.gl/dist/esm/index.js
6110
5974
  var esm_default;
6111
- var init_esm7 = __esm({
5975
+ var init_esm6 = __esm({
6112
5976
  "../../node_modules/probe.gl/dist/esm/index.js"() {
6113
5977
  init_log();
6114
5978
  init_log();
6115
- init_esm6();
5979
+ init_esm5();
6116
5980
  esm_default = new Log({
6117
5981
  id: "probe.gl"
6118
5982
  });
@@ -6123,7 +5987,7 @@
6123
5987
  var probeLog, NullLog, ConsoleLog;
6124
5988
  var init_loggers = __esm({
6125
5989
  "../core/src/lib/loader-utils/loggers.ts"() {
6126
- init_esm7();
5990
+ init_esm6();
6127
5991
  probeLog = new Log({ id: "loaders.gl" });
6128
5992
  NullLog = class {
6129
5993
  log() {
@@ -6167,6 +6031,7 @@
6167
6031
  var DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS;
6168
6032
  var init_option_defaults = __esm({
6169
6033
  "../core/src/lib/loader-utils/option-defaults.ts"() {
6034
+ init_src2();
6170
6035
  init_loggers();
6171
6036
  DEFAULT_LOADER_OPTIONS = {
6172
6037
  fetch: null,
@@ -6177,7 +6042,8 @@
6177
6042
  worker: true,
6178
6043
  maxConcurrency: 3,
6179
6044
  maxMobileConcurrency: 1,
6180
- reuseWorkers: true,
6045
+ reuseWorkers: isBrowser,
6046
+ _nodeWorkers: false,
6181
6047
  _workerType: "",
6182
6048
  limit: 0,
6183
6049
  _limitMB: 0,
@@ -6435,7 +6301,7 @@
6435
6301
  });
6436
6302
 
6437
6303
  // ../../node_modules/@probe.gl/env/dist/esm/index.js
6438
- var init_esm8 = __esm({
6304
+ var init_esm7 = __esm({
6439
6305
  "../../node_modules/@probe.gl/env/dist/esm/index.js"() {
6440
6306
  init_globals6();
6441
6307
  init_globals5();
@@ -6555,7 +6421,7 @@
6555
6421
  var COLOR2;
6556
6422
  var init_color2 = __esm({
6557
6423
  "../../node_modules/@probe.gl/log/dist/esm/utils/color.js"() {
6558
- init_esm8();
6424
+ init_esm7();
6559
6425
  (function(COLOR3) {
6560
6426
  COLOR3[COLOR3["BLACK"] = 30] = "BLACK";
6561
6427
  COLOR3[COLOR3["RED"] = 31] = "RED";
@@ -6607,7 +6473,7 @@
6607
6473
  });
6608
6474
 
6609
6475
  // ../../node_modules/@probe.gl/log/dist/esm/utils/hi-res-timestamp.js
6610
- function getHiResTimestamp5() {
6476
+ function getHiResTimestamp4() {
6611
6477
  let timestamp;
6612
6478
  if (isBrowser5 && "performance" in window_4) {
6613
6479
  var _window$performance, _window$performance$n;
@@ -6621,9 +6487,9 @@
6621
6487
  }
6622
6488
  return timestamp;
6623
6489
  }
6624
- var init_hi_res_timestamp5 = __esm({
6490
+ var init_hi_res_timestamp4 = __esm({
6625
6491
  "../../node_modules/@probe.gl/log/dist/esm/utils/hi-res-timestamp.js"() {
6626
- init_esm8();
6492
+ init_esm7();
6627
6493
  }
6628
6494
  });
6629
6495
 
@@ -6746,13 +6612,13 @@
6746
6612
  var init_log2 = __esm({
6747
6613
  "../../node_modules/@probe.gl/log/dist/esm/log.js"() {
6748
6614
  init_defineProperty();
6749
- init_esm8();
6615
+ init_esm7();
6750
6616
  init_local_storage2();
6751
6617
  init_formatters2();
6752
6618
  init_color2();
6753
6619
  init_autobind2();
6754
6620
  init_assert5();
6755
- init_hi_res_timestamp5();
6621
+ init_hi_res_timestamp4();
6756
6622
  originalConsole2 = {
6757
6623
  debug: isBrowser5 ? console.debug || console.log : console.log,
6758
6624
  log: console.log,
@@ -6777,8 +6643,8 @@
6777
6643
  };
6778
6644
  _defineProperty(this, "id", void 0);
6779
6645
  _defineProperty(this, "VERSION", VERSION3);
6780
- _defineProperty(this, "_startTs", getHiResTimestamp5());
6781
- _defineProperty(this, "_deltaTs", getHiResTimestamp5());
6646
+ _defineProperty(this, "_startTs", getHiResTimestamp4());
6647
+ _defineProperty(this, "_deltaTs", getHiResTimestamp4());
6782
6648
  _defineProperty(this, "_storage", void 0);
6783
6649
  _defineProperty(this, "userData", {});
6784
6650
  _defineProperty(this, "LOG_THROTTLE_TIMEOUT", 0);
@@ -6802,10 +6668,10 @@
6802
6668
  return this._storage.config.level;
6803
6669
  }
6804
6670
  getTotal() {
6805
- return Number((getHiResTimestamp5() - this._startTs).toPrecision(10));
6671
+ return Number((getHiResTimestamp4() - this._startTs).toPrecision(10));
6806
6672
  }
6807
6673
  getDelta() {
6808
- return Number((getHiResTimestamp5() - this._deltaTs).toPrecision(10));
6674
+ return Number((getHiResTimestamp4() - this._deltaTs).toPrecision(10));
6809
6675
  }
6810
6676
  set priority(newPriority) {
6811
6677
  this.level = newPriority;
@@ -6967,11 +6833,11 @@
6967
6833
  assert5(method);
6968
6834
  opts.total = this.getTotal();
6969
6835
  opts.delta = this.getDelta();
6970
- this._deltaTs = getHiResTimestamp5();
6836
+ this._deltaTs = getHiResTimestamp4();
6971
6837
  const tag = opts.tag || opts.message;
6972
6838
  if (opts.once) {
6973
6839
  if (!cache2[tag]) {
6974
- cache2[tag] = getHiResTimestamp5();
6840
+ cache2[tag] = getHiResTimestamp4();
6975
6841
  } else {
6976
6842
  return noop3;
6977
6843
  }
@@ -6988,7 +6854,7 @@
6988
6854
 
6989
6855
  // ../../node_modules/@probe.gl/log/dist/esm/index.js
6990
6856
  var esm_default2;
6991
- var init_esm9 = __esm({
6857
+ var init_esm8 = __esm({
6992
6858
  "../../node_modules/@probe.gl/log/dist/esm/index.js"() {
6993
6859
  init_log2();
6994
6860
  init_log2();
@@ -7002,7 +6868,7 @@
7002
6868
  var log;
7003
6869
  var init_log3 = __esm({
7004
6870
  "../core/src/lib/utils/log.ts"() {
7005
- init_esm9();
6871
+ init_esm8();
7006
6872
  log = new Log2({ id: "loaders.gl" });
7007
6873
  }
7008
6874
  });
@@ -7623,7 +7489,7 @@
7623
7489
  var init_bounding_volume = __esm({
7624
7490
  "src/tileset/helpers/bounding-volume.ts"() {
7625
7491
  init_esm();
7626
- init_esm5();
7492
+ init_esm4();
7627
7493
  init_esm2();
7628
7494
  init_src2();
7629
7495
  scratchScale = new Vector3();
@@ -7690,39 +7556,43 @@
7690
7556
  return "OUT";
7691
7557
  }
7692
7558
  function getProjectedRadius(tile, frameState) {
7693
- const originalViewport = frameState.viewport;
7694
- const ViewportClass = originalViewport.constructor;
7695
- const { longitude, latitude, height, width, bearing, zoom } = originalViewport;
7696
- const viewport = new ViewportClass({ longitude, latitude, height, width, bearing, zoom, pitch: 0 });
7559
+ const { topDownViewport: viewport } = frameState;
7697
7560
  const mbsLat = tile.header.mbs[1];
7698
7561
  const mbsLon = tile.header.mbs[0];
7699
7562
  const mbsZ = tile.header.mbs[2];
7700
7563
  const mbsR = tile.header.mbs[3];
7701
7564
  const mbsCenterCartesian = [...tile.boundingVolume.center];
7702
7565
  const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
7703
- const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new Vector3());
7704
- const toEye = new Vector3(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();
7705
- const enuToCartesianMatrix = new Matrix4();
7566
+ Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, cameraPositionCartesian);
7567
+ toEye.copy(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();
7706
7568
  Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);
7707
- const cartesianToEnuMatrix = new Matrix4(enuToCartesianMatrix).invert();
7708
- const cameraPositionEnu = new Vector3(cameraPositionCartesian).transform(cartesianToEnuMatrix);
7569
+ cartesianToEnuMatrix.copy(enuToCartesianMatrix).invert();
7570
+ cameraPositionEnu.copy(cameraPositionCartesian).transform(cartesianToEnuMatrix);
7709
7571
  const projection = Math.sqrt(cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]);
7710
7572
  const extraZ = projection * projection / cameraPositionEnu[2];
7711
- const extraVertexEnu = new Vector3([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);
7573
+ extraVertexEnu.copy([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);
7712
7574
  const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);
7713
- const extraVectorCartesian = new Vector3(extraVertexCartesian).subtract(mbsCenterCartesian).normalize();
7575
+ const extraVectorCartesian = extraVertexCartesian.subtract(mbsCenterCartesian).normalize();
7714
7576
  const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);
7715
- const sphereMbsBorderVertexCartesian = new Vector3(mbsCenterCartesian).add(radiusVector);
7577
+ const sphereMbsBorderVertexCartesian = radiusVector.add(mbsCenterCartesian);
7716
7578
  const sphereMbsBorderVertexCartographic = Ellipsoid.WGS84.cartesianToCartographic(sphereMbsBorderVertexCartesian);
7717
7579
  const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);
7718
7580
  const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);
7719
- const projectedRadius = new Vector3(projectedOrigin).subtract(projectedMbsBorderVertex).magnitude();
7581
+ const projectedRadius = projectedOriginVector.copy(projectedOrigin).subtract(projectedMbsBorderVertex).magnitude();
7720
7582
  return projectedRadius;
7721
7583
  }
7584
+ var cameraPositionCartesian, toEye, cameraPositionEnu, extraVertexEnu, projectedOriginVector, enuToCartesianMatrix, cartesianToEnuMatrix;
7722
7585
  var init_i3s_lod = __esm({
7723
7586
  "src/tileset/helpers/i3s-lod.ts"() {
7724
7587
  init_esm();
7725
7588
  init_esm2();
7589
+ cameraPositionCartesian = new Vector3();
7590
+ toEye = new Vector3();
7591
+ cameraPositionEnu = new Vector3();
7592
+ extraVertexEnu = new Vector3();
7593
+ projectedOriginVector = new Vector3();
7594
+ enuToCartesianMatrix = new Matrix4();
7595
+ cartesianToEnuMatrix = new Matrix4();
7726
7596
  }
7727
7597
  });
7728
7598
 
@@ -8056,7 +7926,7 @@
8056
7926
  var init_tile_3d = __esm({
8057
7927
  "src/tileset/tile-3d.ts"() {
8058
7928
  init_esm();
8059
- init_esm5();
7929
+ init_esm4();
8060
7930
  init_src3();
8061
7931
  init_constants3();
8062
7932
  init_bounding_volume();
@@ -8166,6 +8036,9 @@
8166
8036
  throw new Error("Unsupported tileset type");
8167
8037
  }
8168
8038
  }
8039
+ unselect() {
8040
+ this._selectedFrame = 0;
8041
+ }
8169
8042
  _getPriority() {
8170
8043
  const traverser = this.tileset._traverser;
8171
8044
  const { skipLevelOfDetail } = traverser.options;
@@ -8597,6 +8470,8 @@
8597
8470
  throttleRequests: true,
8598
8471
  maxRequests: 64,
8599
8472
  maximumMemoryUsage: 32,
8473
+ maximumTilesSelected: 0,
8474
+ debounceTime: 0,
8600
8475
  onTileLoad: () => {
8601
8476
  },
8602
8477
  onTileUnload: () => {
@@ -8627,6 +8502,7 @@
8627
8502
  TILES_GPU_MEMORY = "Tile Memory Use";
8628
8503
  Tileset3D = class {
8629
8504
  constructor(json, options) {
8505
+ this.updatePromise = null;
8630
8506
  assert2(json);
8631
8507
  this.options = { ...DEFAULT_PROPS4, ...options };
8632
8508
  this.tileset = json;
@@ -8710,18 +8586,36 @@
8710
8586
  hasExtension(extensionName) {
8711
8587
  return Boolean(this._extensionsUsed && this._extensionsUsed.indexOf(extensionName) > -1);
8712
8588
  }
8713
- update(viewports) {
8589
+ update(viewports = null) {
8590
+ if (!viewports && this.lastUpdatedVieports) {
8591
+ viewports = this.lastUpdatedVieports;
8592
+ } else {
8593
+ this.lastUpdatedVieports = viewports;
8594
+ }
8595
+ this.doUpdate(viewports);
8596
+ }
8597
+ async selectTiles(viewports = null) {
8598
+ if (viewports) {
8599
+ this.lastUpdatedVieports = viewports;
8600
+ }
8601
+ if (!this.updatePromise) {
8602
+ this.updatePromise = new Promise((resolve) => {
8603
+ setTimeout(() => {
8604
+ this.doUpdate(this.lastUpdatedVieports);
8605
+ resolve(this._frameNumber);
8606
+ this.updatePromise = null;
8607
+ }, this.options.debounceTime);
8608
+ });
8609
+ }
8610
+ return this.updatePromise;
8611
+ }
8612
+ doUpdate(viewports = null) {
8714
8613
  if ("loadTiles" in this.options && !this.options.loadTiles) {
8715
8614
  return;
8716
8615
  }
8717
8616
  if (this.traverseCounter > 0) {
8718
8617
  return;
8719
8618
  }
8720
- if (!viewports && this.lastUpdatedVieports) {
8721
- viewports = this.lastUpdatedVieports;
8722
- } else {
8723
- this.lastUpdatedVieports = viewports;
8724
- }
8725
8619
  if (!(viewports instanceof Array)) {
8726
8620
  viewports = [viewports];
8727
8621
  }
@@ -8766,7 +8660,11 @@
8766
8660
  }
8767
8661
  const currentFrameStateData = this.frameStateData[id];
8768
8662
  const selectedTiles = Object.values(this._traverser.selectedTiles);
8769
- currentFrameStateData.selectedTiles = selectedTiles;
8663
+ const [filteredSelectedTiles, unselectedTiles] = limitSelectedTiles(selectedTiles, frameState, this.options.maximumTilesSelected);
8664
+ currentFrameStateData.selectedTiles = filteredSelectedTiles;
8665
+ for (const tile of unselectedTiles) {
8666
+ tile.unselect();
8667
+ }
8770
8668
  currentFrameStateData._requestedTiles = Object.values(this._traverser.requestedTiles);
8771
8669
  currentFrameStateData._emptyTiles = Object.values(this._traverser.emptyTiles);
8772
8670
  this.traverseCounter--;