bruce-cesium 2.1.4 → 2.1.6

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.
@@ -2032,11 +2032,17 @@
2032
2032
  }
2033
2033
  var bColor = style.lineColor ? bruceModels.Calculator.GetColor(style.lineColor, entity, params.tags) : null;
2034
2034
  var cColor = bColor ? colorToCColor(bColor) : Cesium.Color.RED;
2035
+ if (cColor.alpha <= 0) {
2036
+ return null;
2037
+ }
2035
2038
  var width = style.lineWidth ? bruceModels.Calculator.GetNumber(style.lineWidth, entity, params.tags) : null;
2036
2039
  if (width == null) {
2037
2040
  width = 4;
2038
2041
  }
2039
2042
  width = EnsureNumber(width);
2043
+ if (width < 0.01) {
2044
+ width = 0;
2045
+ }
2040
2046
  if (width <= 0) {
2041
2047
  return null;
2042
2048
  }
@@ -2132,7 +2138,12 @@
2132
2138
  width = 4;
2133
2139
  }
2134
2140
  width = EnsureNumber(width);
2135
- if (width <= 0) {
2141
+ if (width < 0.01) {
2142
+ width = 0;
2143
+ }
2144
+ // If both outline and fill is not available then don't render anything.
2145
+ if ((width <= 0 || cLineColor.alpha <= 0) &&
2146
+ cFillColor.alpha <= 0) {
2136
2147
  return null;
2137
2148
  }
2138
2149
  var heightRef = getHeightRef(style);
@@ -4733,6 +4744,8 @@
4733
4744
  }
4734
4745
  return style;
4735
4746
  }
4747
+ var VIEWER_WATCH_KEY = "bruce-viewer-watch";
4748
+ var WATCH_KEY = "bruce-tileset-watch";
4736
4749
  /**
4737
4750
  * Creates and returns a tileset instance from a given url.
4738
4751
  * This is made to handle the difference between old and new cesium versions.
@@ -4743,15 +4756,21 @@
4743
4756
  */
4744
4757
  function createTileset(url, props) {
4745
4758
  return __awaiter(this, void 0, void 0, function () {
4746
- var C3DT;
4759
+ var defaultProps, C3DT;
4747
4760
  return __generator(this, function (_a) {
4761
+ defaultProps = {
4762
+ // "Optimization option. Reduce the screen space error for tiles that are further away from the camera.".
4763
+ dynamicScreenSpaceError: true,
4764
+ // "The maximum amount of memory in MB that can be used by the tileset.".
4765
+ maximumMemoryUsage: 512
4766
+ };
4748
4767
  C3DT = Cesium.Cesium3DTileset;
4749
4768
  if (C3DT.fromUrl) {
4750
4769
  // New cesium is running.
4751
- return [2 /*return*/, C3DT.fromUrl(url, __assign({}, props))];
4770
+ return [2 /*return*/, C3DT.fromUrl(url, __assign(__assign({}, defaultProps), props))];
4752
4771
  }
4753
4772
  // Old cesium is running.
4754
- return [2 /*return*/, new C3DT(__assign({ url: url }, props))];
4773
+ return [2 /*return*/, new C3DT(__assign(__assign({ url: url }, defaultProps), props))];
4755
4774
  });
4756
4775
  });
4757
4776
  }
@@ -4920,11 +4939,12 @@
4920
4939
  cTileset_1 = _a.sent();
4921
4940
  params.viewer.scene.primitives.add(cTileset_1);
4922
4941
  cTileset_1.readyPromise.then(function () {
4923
- var _a, _b, _c;
4942
+ var _a, _b, _c, _d;
4924
4943
  try {
4925
4944
  if (!isAlive(params.viewer, cTileset_1)) {
4926
4945
  return;
4927
4946
  }
4947
+ (_a = GetMemoryWatcher(params.viewer)) === null || _a === void 0 ? void 0 : _a.Watch(cTileset_1);
4928
4948
  var settings = params.tileset.settings;
4929
4949
  ApplySettings({
4930
4950
  cTileset: cTileset_1,
@@ -4935,9 +4955,9 @@
4935
4955
  ApplyPosition({
4936
4956
  cTileset: cTileset_1,
4937
4957
  position: {
4938
- ucs: (_a = params.coords) === null || _a === void 0 ? void 0 : _a.ucs,
4939
- location: ((_b = params.coords) === null || _b === void 0 ? void 0 : _b.location) == null ? settings.location : params.coords.location,
4940
- transform: ((_c = params.coords) === null || _c === void 0 ? void 0 : _c.transform) == null ? settings.transform : params.coords.transform
4958
+ ucs: (_b = params.coords) === null || _b === void 0 ? void 0 : _b.ucs,
4959
+ location: ((_c = params.coords) === null || _c === void 0 ? void 0 : _c.location) == null ? settings.location : params.coords.location,
4960
+ transform: ((_d = params.coords) === null || _d === void 0 ? void 0 : _d.transform) == null ? settings.transform : params.coords.transform
4941
4961
  }
4942
4962
  });
4943
4963
  }
@@ -4968,10 +4988,12 @@
4968
4988
  cTileset_2 = _a.sent();
4969
4989
  params.viewer.scene.primitives.add(cTileset_2);
4970
4990
  cTileset_2.readyPromise.then(function () {
4991
+ var _a;
4971
4992
  try {
4972
4993
  if (!isAlive(params.viewer, cTileset_2)) {
4973
4994
  return;
4974
4995
  }
4996
+ (_a = GetMemoryWatcher(params.viewer)) === null || _a === void 0 ? void 0 : _a.Watch(cTileset_2);
4975
4997
  var settings = params.tileset.settings;
4976
4998
  ApplySettings({
4977
4999
  cTileset: cTileset_2,
@@ -5044,10 +5066,12 @@
5044
5066
  cTileset = _a.sent();
5045
5067
  viewer.scene.primitives.add(cTileset);
5046
5068
  cTileset.readyPromise.then(function () {
5069
+ var _a;
5047
5070
  try {
5048
5071
  if (!isAlive(viewer, cTileset)) {
5049
5072
  return;
5050
5073
  }
5074
+ (_a = GetMemoryWatcher(params.viewer)) === null || _a === void 0 ? void 0 : _a.Watch(cTileset);
5051
5075
  if (tileset) {
5052
5076
  var settings_1 = tileset.Settings;
5053
5077
  settings_1 = __assign({}, settings_1);
@@ -5494,6 +5518,89 @@
5494
5518
  return Styler;
5495
5519
  }());
5496
5520
  TilesetRenderEngine.Styler = Styler;
5521
+ /**
5522
+ * The maximum memory in MB that can be used by all tilesets.
5523
+ * This is distributed evenly between all loaded tilesets.
5524
+ */
5525
+ TilesetRenderEngine.MAX_TILESET_MEMORY = 1024;
5526
+ /**
5527
+ * Watches tilesets in the viewer.
5528
+ * This will regulate their max memory param.
5529
+ * As more get watched their memory will be reduced.
5530
+ */
5531
+ var MemoryWatcher = /** @class */ (function () {
5532
+ function MemoryWatcher(viewer) {
5533
+ this.watched = [];
5534
+ this.viewer = viewer;
5535
+ }
5536
+ MemoryWatcher.prototype.distributeMemory = function () {
5537
+ this.clean();
5538
+ // Total 1gb as default.
5539
+ // We'll need to allow user to change this somehow.
5540
+ var maxMemory = TilesetRenderEngine.MAX_TILESET_MEMORY;
5541
+ // Minimum memory in MB per tileset.
5542
+ var minMemory = 80;
5543
+ var totalPerTileset = Math.max(this.watched.length ? maxMemory / this.watched.length : maxMemory, minMemory);
5544
+ this.watched.forEach(function (x) {
5545
+ x.maximumMemoryUsage = totalPerTileset;
5546
+ });
5547
+ };
5548
+ MemoryWatcher.prototype.destroy = function () {
5549
+ this.watched = [];
5550
+ };
5551
+ /**
5552
+ * Remove all dead tilesets.
5553
+ */
5554
+ MemoryWatcher.prototype.clean = function () {
5555
+ var _this = this;
5556
+ // Remove all dead tilesets.
5557
+ this.watched = this.watched.filter(function (x) { return isAlive(_this.viewer, x); });
5558
+ // Check if viewer is destroyed.
5559
+ if (!this.viewer || this.viewer.isDestroyed()) {
5560
+ this.destroy();
5561
+ }
5562
+ };
5563
+ MemoryWatcher.prototype.Watch = function (tileset) {
5564
+ if (!tileset) {
5565
+ return;
5566
+ }
5567
+ if (!tileset[WATCH_KEY]) {
5568
+ tileset[WATCH_KEY] = bruceModels.ObjectUtils.UId();
5569
+ }
5570
+ var index = this.watched.findIndex(function (x) { return x[WATCH_KEY] === tileset[WATCH_KEY]; });
5571
+ if (index >= 0) {
5572
+ return;
5573
+ }
5574
+ this.watched.push(tileset);
5575
+ this.distributeMemory();
5576
+ };
5577
+ MemoryWatcher.prototype.Unwatch = function (tileset) {
5578
+ if (!tileset) {
5579
+ return;
5580
+ }
5581
+ if (!tileset[WATCH_KEY]) {
5582
+ tileset[WATCH_KEY] = bruceModels.ObjectUtils.UId();
5583
+ }
5584
+ var index = this.watched.findIndex(function (x) { return (x === null || x === void 0 ? void 0 : x[WATCH_KEY]) === tileset[WATCH_KEY]; });
5585
+ if (index > -1) {
5586
+ this.watched.splice(index, 1);
5587
+ }
5588
+ this.distributeMemory();
5589
+ };
5590
+ return MemoryWatcher;
5591
+ }());
5592
+ TilesetRenderEngine.MemoryWatcher = MemoryWatcher;
5593
+ function GetMemoryWatcher(viewer) {
5594
+ // If viewer is dead return nothing.
5595
+ if (!viewer || viewer.isDestroyed()) {
5596
+ return null;
5597
+ }
5598
+ if (!viewer[VIEWER_WATCH_KEY]) {
5599
+ viewer[VIEWER_WATCH_KEY] = new MemoryWatcher(viewer);
5600
+ }
5601
+ return viewer[VIEWER_WATCH_KEY];
5602
+ }
5603
+ TilesetRenderEngine.GetMemoryWatcher = GetMemoryWatcher;
5497
5604
  })(exports.TilesetRenderEngine || (exports.TilesetRenderEngine = {}));
5498
5605
 
5499
5606
  (function (TilesetCadRenderManager) {
@@ -5769,16 +5876,17 @@
5769
5876
  this.doDispose();
5770
5877
  };
5771
5878
  Manager.prototype.doDispose = function () {
5772
- var _a;
5879
+ var _a, _b;
5773
5880
  if (this.cTileset) {
5774
5881
  var viewer = this.viewer;
5775
5882
  if (!(viewer === null || viewer === void 0 ? void 0 : viewer.isDestroyed()) && this.viewer.scene.primitives.contains(this.cTileset)) {
5776
5883
  this.cTileset.show = false;
5777
5884
  this.viewer.scene.primitives.remove(this.cTileset);
5885
+ (_a = exports.TilesetRenderEngine.GetMemoryWatcher(viewer)) === null || _a === void 0 ? void 0 : _a.Unwatch(this.cTileset);
5778
5886
  }
5779
5887
  this.cTileset = null;
5780
5888
  }
5781
- (_a = this.styler) === null || _a === void 0 ? void 0 : _a.Dispose();
5889
+ (_b = this.styler) === null || _b === void 0 ? void 0 : _b.Dispose();
5782
5890
  this.visualsManager.RemoveRegos({
5783
5891
  menuItemId: this.item.id
5784
5892
  });
@@ -6316,11 +6424,13 @@
6316
6424
  this.doDispose();
6317
6425
  };
6318
6426
  Manager.prototype.doDispose = function () {
6427
+ var _a;
6319
6428
  if (this.cTileset) {
6320
6429
  var viewer = this.viewer;
6321
6430
  if (!(viewer === null || viewer === void 0 ? void 0 : viewer.isDestroyed()) && this.viewer.scene.primitives.contains(this.cTileset)) {
6322
6431
  this.cTileset.show = false;
6323
6432
  this.viewer.scene.primitives.remove(this.cTileset);
6433
+ (_a = exports.TilesetRenderEngine.GetMemoryWatcher(viewer)) === null || _a === void 0 ? void 0 : _a.Unwatch(this.cTileset);
6324
6434
  }
6325
6435
  this.cTileset = null;
6326
6436
  }
@@ -6467,11 +6577,13 @@
6467
6577
  this.doDispose();
6468
6578
  };
6469
6579
  Manager.prototype.doDispose = function () {
6580
+ var _a;
6470
6581
  if (this.cTileset) {
6471
6582
  var viewer = this.viewer;
6472
6583
  if (!(viewer === null || viewer === void 0 ? void 0 : viewer.isDestroyed()) && this.viewer.scene.primitives.contains(this.cTileset)) {
6473
6584
  this.cTileset.show = false;
6474
6585
  this.viewer.scene.primitives.remove(this.cTileset);
6586
+ (_a = exports.TilesetRenderEngine.GetMemoryWatcher(viewer)) === null || _a === void 0 ? void 0 : _a.Unwatch(this.cTileset);
6475
6587
  }
6476
6588
  this.cTileset = null;
6477
6589
  }
@@ -6815,16 +6927,17 @@
6815
6927
  this.doDispose();
6816
6928
  };
6817
6929
  Manager.prototype.doDispose = function () {
6818
- var _a;
6930
+ var _a, _b;
6819
6931
  if (this.cTileset) {
6820
6932
  var viewer = this.viewer;
6821
6933
  if (!(viewer === null || viewer === void 0 ? void 0 : viewer.isDestroyed()) && this.viewer.scene.primitives.contains(this.cTileset)) {
6822
6934
  this.cTileset.show = false;
6823
6935
  this.viewer.scene.primitives.remove(this.cTileset);
6936
+ (_a = exports.TilesetRenderEngine.GetMemoryWatcher(viewer)) === null || _a === void 0 ? void 0 : _a.Unwatch(this.cTileset);
6824
6937
  }
6825
6938
  this.cTileset = null;
6826
6939
  }
6827
- (_a = this.styler) === null || _a === void 0 ? void 0 : _a.Dispose();
6940
+ (_b = this.styler) === null || _b === void 0 ? void 0 : _b.Dispose();
6828
6941
  this.visualsManager.RemoveRegos({
6829
6942
  menuItemId: this.item.id
6830
6943
  });