bruce-models 1.0.3 → 1.0.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.
@@ -3275,91 +3275,6 @@ var EntityType;
3275
3275
  EntityType.Update = Update;
3276
3276
  })(EntityType || (EntityType = {}));
3277
3277
 
3278
- class Cell {
3279
- constructor() {
3280
- this.Fetched = false;
3281
- this.IsFetched = null;
3282
- this.FetchPageIndex = 0;
3283
- this.Boundaries = null;
3284
- }
3285
- GetBounds() {
3286
- // Entity data works in -180 to 180 range.
3287
- function prepareRangeForBounds(range) {
3288
- if (range > 180) {
3289
- return range - 360;
3290
- }
3291
- return range;
3292
- }
3293
- // Add minor decimal as API crashes when giving it whole numbers.
3294
- const maxLon = prepareRangeForBounds(this.Boundaries.maxLongitude) + 0.00001;
3295
- const minLon = prepareRangeForBounds(this.Boundaries.minLongitude) - 0.00001;
3296
- const maxLat = prepareRangeForBounds(this.Boundaries.maxLatitude) + 0.00001;
3297
- const minLat = prepareRangeForBounds(this.Boundaries.minLatitude) - 0.00001;
3298
- return {
3299
- east: maxLon,
3300
- north: maxLat,
3301
- south: minLat,
3302
- west: minLon
3303
- };
3304
- }
3305
- }
3306
- function floorValueToCellSize(size, value) {
3307
- return Math.floor(value / size) * size;
3308
- }
3309
- function getCellSizeFromHeight(height) {
3310
- if (height < 1000) {
3311
- return 0.01;
3312
- }
3313
- if (height < 5000) {
3314
- return 0.025;
3315
- }
3316
- else if (height < 10000) {
3317
- return 0.05;
3318
- }
3319
- else if (height < 30000) {
3320
- return 0.1;
3321
- }
3322
- else if (height < 70000) {
3323
- return 0.2;
3324
- }
3325
- else if (height < 100000) {
3326
- return 0.3;
3327
- }
3328
- else if (height < 150000) {
3329
- return 0.4;
3330
- }
3331
- else if (height < 200000) {
3332
- return 0.5;
3333
- }
3334
- else if (height < 300000) {
3335
- return 0.6;
3336
- }
3337
- else if (height < 500000) {
3338
- return 1;
3339
- }
3340
- return 1.5;
3341
- }
3342
- function isCellFetched(cell) {
3343
- if (cell.Fetched) {
3344
- return true;
3345
- }
3346
- return false;
3347
- }
3348
- function getOrCreateCell(cells, cellSize, lon, maxLon, lat, maxLat) {
3349
- const id = cellSize + "_" + lon + "_" + maxLon + "_" + lat + "_" + maxLat;
3350
- let cell = cells[id];
3351
- if (!cell) {
3352
- cell = cells[id] = new Cell();
3353
- cell.Boundaries = {
3354
- minLatitude: lat,
3355
- maxLatitude: maxLat,
3356
- minLongitude: lon,
3357
- maxLongitude: maxLon
3358
- };
3359
- cell.IsFetched = () => isCellFetched(cell);
3360
- }
3361
- return [id, cell];
3362
- }
3363
3278
  /**
3364
3279
  * This is a helper for making entity requests based on a grid area.
3365
3280
  * It will return grid cells based on given view-area then will remember when stuff-
@@ -3367,6 +3282,35 @@ function getOrCreateCell(cells, cellSize, lon, maxLon, lat, maxLat) {
3367
3282
  */
3368
3283
  var EntityGlobe;
3369
3284
  (function (EntityGlobe) {
3285
+ class Cell {
3286
+ constructor() {
3287
+ this.Fetched = false;
3288
+ this.IsFetched = null;
3289
+ this.FetchPageIndex = 0;
3290
+ this.Boundaries = null;
3291
+ }
3292
+ GetBounds() {
3293
+ // Entity data works in -180 to 180 range.
3294
+ function prepareRangeForBounds(range) {
3295
+ if (range > 180) {
3296
+ return range - 360;
3297
+ }
3298
+ return range;
3299
+ }
3300
+ // Add minor decimal as API crashes when giving it whole numbers.
3301
+ const maxLon = prepareRangeForBounds(this.Boundaries.maxLongitude) + 0.00001;
3302
+ const minLon = prepareRangeForBounds(this.Boundaries.minLongitude) - 0.00001;
3303
+ const maxLat = prepareRangeForBounds(this.Boundaries.maxLatitude) + 0.00001;
3304
+ const minLat = prepareRangeForBounds(this.Boundaries.minLatitude) - 0.00001;
3305
+ return {
3306
+ east: maxLon,
3307
+ north: maxLat,
3308
+ south: minLat,
3309
+ west: minLon
3310
+ };
3311
+ }
3312
+ }
3313
+ EntityGlobe.Cell = Cell;
3370
3314
  class Grid {
3371
3315
  constructor() {
3372
3316
  this.cells = {};
@@ -3478,6 +3422,63 @@ function intersection(l, r) {
3478
3422
  function area(rect) {
3479
3423
  let { west: w, south: s, north: n, east: e } = rect;
3480
3424
  return Math.abs((e - w) * (n - s));
3425
+ }
3426
+ function floorValueToCellSize(size, value) {
3427
+ return Math.floor(value / size) * size;
3428
+ }
3429
+ function getCellSizeFromHeight(height) {
3430
+ if (height < 1000) {
3431
+ return 0.01;
3432
+ }
3433
+ if (height < 5000) {
3434
+ return 0.025;
3435
+ }
3436
+ else if (height < 10000) {
3437
+ return 0.05;
3438
+ }
3439
+ else if (height < 30000) {
3440
+ return 0.1;
3441
+ }
3442
+ else if (height < 70000) {
3443
+ return 0.2;
3444
+ }
3445
+ else if (height < 100000) {
3446
+ return 0.3;
3447
+ }
3448
+ else if (height < 150000) {
3449
+ return 0.4;
3450
+ }
3451
+ else if (height < 200000) {
3452
+ return 0.5;
3453
+ }
3454
+ else if (height < 300000) {
3455
+ return 0.6;
3456
+ }
3457
+ else if (height < 500000) {
3458
+ return 1;
3459
+ }
3460
+ return 1.5;
3461
+ }
3462
+ function isCellFetched(cell) {
3463
+ if (cell.Fetched) {
3464
+ return true;
3465
+ }
3466
+ return false;
3467
+ }
3468
+ function getOrCreateCell(cells, cellSize, lon, maxLon, lat, maxLat) {
3469
+ const id = cellSize + "_" + lon + "_" + maxLon + "_" + lat + "_" + maxLat;
3470
+ let cell = cells[id];
3471
+ if (!cell) {
3472
+ cell = cells[id] = new EntityGlobe.Cell();
3473
+ cell.Boundaries = {
3474
+ minLatitude: lat,
3475
+ maxLatitude: maxLat,
3476
+ minLongitude: lon,
3477
+ maxLongitude: maxLon
3478
+ };
3479
+ cell.IsFetched = () => isCellFetched(cell);
3480
+ }
3481
+ return [id, cell];
3481
3482
  }
3482
3483
 
3483
3484
  const MAX_AREA_IN_DEGREES = 90;
@@ -3517,6 +3518,7 @@ var EntityFilterGetter;
3517
3518
  this.onUpdate = null;
3518
3519
  this.LastStateUpdates = {};
3519
3520
  this.onStateUpdate = null;
3521
+ this.onScanUpdate = null;
3520
3522
  this.viewPortChangeRemoval = null;
3521
3523
  this.cells = null;
3522
3524
  this.registeredItems = {};
@@ -3545,6 +3547,12 @@ var EntityFilterGetter;
3545
3547
  }
3546
3548
  return this.onStateUpdate;
3547
3549
  }
3550
+ get OnScanUpdate() {
3551
+ if (!this.onScanUpdate) {
3552
+ this.onScanUpdate = new BruceEvent();
3553
+ }
3554
+ return this.onScanUpdate;
3555
+ }
3548
3556
  viewAreaSub() {
3549
3557
  this.viewAreaDispose();
3550
3558
  this.viewPortChangeRemoval = this.viewPort.Updated().Subscribe(() => {
@@ -3632,7 +3640,7 @@ var EntityFilterGetter;
3632
3640
  this.getterLoopId += 1;
3633
3641
  const loopId = this.getterLoopId;
3634
3642
  new Promise(() => __awaiter(this, void 0, void 0, function* () {
3635
- var _a, _b, _c, _d, _e;
3643
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3636
3644
  // Minor delay to stop 50 menu items enabling doing their first request all together.
3637
3645
  // This gives it time to recognize only 1 request is needed.
3638
3646
  // Would be better to not use this delay but we're on a clock.
@@ -3655,6 +3663,7 @@ var EntityFilterGetter;
3655
3663
  return;
3656
3664
  }
3657
3665
  const cells = this.cells.GetCellsForView(this.viewRect);
3666
+ (_a = this.onScanUpdate) === null || _a === void 0 ? void 0 : _a.Trigger(cells);
3658
3667
  let curCellIndex = cells.length > 0 ? 0 : null;
3659
3668
  let postedScanning = false;
3660
3669
  let postedLoading = false;
@@ -3675,6 +3684,7 @@ var EntityFilterGetter;
3675
3684
  if (!cells[curCellIndex]) {
3676
3685
  curCellIndex = null;
3677
3686
  }
3687
+ (_b = this.onScanUpdate) === null || _b === void 0 ? void 0 : _b.Trigger(cells);
3678
3688
  continue;
3679
3689
  }
3680
3690
  try {
@@ -3691,20 +3701,22 @@ var EntityFilterGetter;
3691
3701
  break;
3692
3702
  }
3693
3703
  if (page) {
3694
- (_a = this.onUpdate) === null || _a === void 0 ? void 0 : _a.Trigger(page);
3704
+ (_c = this.onUpdate) === null || _c === void 0 ? void 0 : _c.Trigger(page);
3695
3705
  }
3696
3706
  if (!postedLoading) {
3697
3707
  this.postStatus({ msg: EStatus.Loading, revoking: false });
3698
3708
  postedLoading = true;
3699
3709
  }
3710
+ // Only mark as fetched when ALL pages are done.
3700
3711
  if (page.length <= 0) {
3701
- curCell.Fetched = true; // Only mark as fetched when ALL pages are done.
3712
+ curCell.Fetched = true;
3713
+ (_d = this.onScanUpdate) === null || _d === void 0 ? void 0 : _d.Trigger(cells);
3702
3714
  continue;
3703
3715
  }
3704
3716
  // Checking to make sure it's not just the same batch over and over again.
3705
3717
  if (page.length > 0) {
3706
- const first = (_c = (_b = page[0]) === null || _b === void 0 ? void 0 : _b.Bruce) === null || _c === void 0 ? void 0 : _c.ID;
3707
- const last = (_e = (_d = page[page.length - 1]) === null || _d === void 0 ? void 0 : _d.Bruce) === null || _e === void 0 ? void 0 : _e.ID;
3718
+ const first = (_f = (_e = page[0]) === null || _e === void 0 ? void 0 : _e.Bruce) === null || _f === void 0 ? void 0 : _f.ID;
3719
+ const last = (_h = (_g = page[page.length - 1]) === null || _g === void 0 ? void 0 : _g.Bruce) === null || _h === void 0 ? void 0 : _h.ID;
3708
3720
  if (prevFirstId == first && prevLastId == last) {
3709
3721
  break;
3710
3722
  }