bruce-cesium 3.4.6 → 3.4.7

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.
@@ -3347,6 +3347,19 @@
3347
3347
  VisualRegisterCuller.MarkShouldRecheck = MarkShouldRecheck;
3348
3348
  })(VisualRegisterCuller || (VisualRegisterCuller = {}));
3349
3349
 
3350
+ var _logErrorCache = {};
3351
+ /**
3352
+ * Will only log the error once matching the key.
3353
+ * @param key
3354
+ * @param message
3355
+ */
3356
+ function OneTimeError(key, message) {
3357
+ if (!_logErrorCache[key]) {
3358
+ console.error(message);
3359
+ _logErrorCache[key] = true;
3360
+ }
3361
+ }
3362
+
3350
3363
  function colorToCColor(color) {
3351
3364
  return new Cesium.Color(color.red ? color.red / 255 : 0, color.green ? color.green / 255 : 0, color.blue ? color.blue / 255 : 0, color.alpha);
3352
3365
  }
@@ -3618,8 +3631,6 @@
3618
3631
  }
3619
3632
  return zoomItem.MinZoom + "-" + zoomItem.MaxZoom + "-" + shouldApplyFlatFix(terrain);
3620
3633
  }
3621
- var _fileValidationCache = {};
3622
- var _fileHeightCache = {};
3623
3634
  // Key = url + scale.
3624
3635
  var _fileRadiusCache = new bruceModels.LRUCache(1000);
3625
3636
  /**
@@ -3716,7 +3727,7 @@
3716
3727
  }
3717
3728
  return length;
3718
3729
  }
3719
- var _billboardCache = new bruceModels.LRUCache(100);
3730
+ var _billboardCache = new bruceModels.LRUCache(150);
3720
3731
  var POINT_BILLBOARD_PADDING = 1;
3721
3732
  var createCircleBillboard = function (size, colorCss) {
3722
3733
  var key = size + "-" + colorCss;
@@ -3744,6 +3755,53 @@
3744
3755
  _billboardCache.Set(key, data);
3745
3756
  return data;
3746
3757
  };
3758
+ var createImageBillboard = function (url) {
3759
+ var cacheKey = "image-" + url;
3760
+ var cacheData = _billboardCache.Get(cacheKey);
3761
+ if (cacheData) {
3762
+ return cacheData;
3763
+ }
3764
+ var prom = new Promise(function (res, rej) { return __awaiter(void 0, void 0, void 0, function () {
3765
+ var response, blob, canvas_1, image_1, e_4;
3766
+ return __generator(this, function (_a) {
3767
+ switch (_a.label) {
3768
+ case 0:
3769
+ _a.trys.push([0, 3, , 4]);
3770
+ return [4 /*yield*/, fetch(url)];
3771
+ case 1:
3772
+ response = _a.sent();
3773
+ return [4 /*yield*/, response.blob()];
3774
+ case 2:
3775
+ blob = _a.sent();
3776
+ canvas_1 = document.createElement("canvas");
3777
+ image_1 = new Image();
3778
+ image_1.onload = function () {
3779
+ canvas_1.width = image_1.width;
3780
+ canvas_1.height = image_1.height;
3781
+ var context = canvas_1.getContext("2d");
3782
+ context.drawImage(image_1, 0, 0);
3783
+ var data = {
3784
+ canvas: canvas_1,
3785
+ height: image_1.height
3786
+ };
3787
+ res(data);
3788
+ };
3789
+ image_1.onerror = function () {
3790
+ rej(null);
3791
+ };
3792
+ image_1.src = URL.createObjectURL(blob);
3793
+ return [3 /*break*/, 4];
3794
+ case 3:
3795
+ e_4 = _a.sent();
3796
+ rej(null);
3797
+ return [3 /*break*/, 4];
3798
+ case 4: return [2 /*return*/];
3799
+ }
3800
+ });
3801
+ }); });
3802
+ _billboardCache.Set(cacheKey, prom);
3803
+ return prom;
3804
+ };
3747
3805
  /**
3748
3806
  * Removes duplicate points in a row and returns a new array.
3749
3807
  * Passed array is not mutated.
@@ -3794,6 +3852,48 @@
3794
3852
  });
3795
3853
  });
3796
3854
  }
3855
+ /**
3856
+ * Turns a hard-coded file url into pieces so we can properly load it using our libraries rather than directly.
3857
+ * @param url eg: https://demoplantprocess.api.nextspace-uat.net/file/4c29bdf8-1f0b-4739-b0ee-421ea07ba4e5.png
3858
+ */
3859
+ function extractMetadataFromFileUrl(url) {
3860
+ var _a;
3861
+ url = url.toLowerCase();
3862
+ // Bzzt, invalid url format for our purposes.
3863
+ if (!url.includes(".api.") || !url.includes("/file/")) {
3864
+ return null;
3865
+ }
3866
+ url = url.replace("https://", "").replace("http://", "");
3867
+ var envId = bruceModels.Api.EEnv.PROD;
3868
+ if (url.includes("-dev.net")) {
3869
+ envId = bruceModels.Api.EEnv.DEV;
3870
+ }
3871
+ else if (url.includes("-stg.net")) {
3872
+ envId = bruceModels.Api.EEnv.STG;
3873
+ }
3874
+ else if (url.includes("-uat.net")) {
3875
+ envId = bruceModels.Api.EEnv.UAT;
3876
+ }
3877
+ var parts = url.split("/");
3878
+ var host = parts[0];
3879
+ var hostParts = host.split(".");
3880
+ var accountId = hostParts[0];
3881
+ var fileId = (_a = parts[2]) !== null && _a !== void 0 ? _a : "";
3882
+ if (fileId.includes("?")) {
3883
+ fileId = fileId.split("?")[0];
3884
+ }
3885
+ if (fileId.includes(".")) {
3886
+ fileId = fileId.split(".")[0];
3887
+ }
3888
+ if (!fileId || !accountId) {
3889
+ return null;
3890
+ }
3891
+ return {
3892
+ accountId: accountId,
3893
+ fileId: fileId,
3894
+ envId: envId
3895
+ };
3896
+ }
3797
3897
  (function (EntityRenderEngine) {
3798
3898
  function Render(params) {
3799
3899
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -4066,10 +4166,11 @@
4066
4166
  }
4067
4167
  Point.CreateCircleBillboard = CreateCircleBillboard;
4068
4168
  function Render(params) {
4169
+ var _a, _b;
4069
4170
  return __awaiter(this, void 0, void 0, function () {
4070
- var entity, style, type, cEntity, siblings, iconUrlRows, icon, iconUrl_1, res, blob_1, e_4, e_5, iconScale, disableDepthTest, bColor, cColor, heightRef, radius, bFill, cFill, outline, cOutline, outlineWidth, bOutline, heightRef, pos3d, extrusion, outlineExtrusion, bColor, cColor, size, heightRef, circleBillboard;
4071
- return __generator(this, function (_a) {
4072
- switch (_a.label) {
4171
+ var entity, style, type, cEntity, siblings, iconUrlRows, icon, iconUrl, metadata, api, image, e_5, iconScale, disableDepthTest, bColor, cColor, heightRef, radius, bFill, cFill, outline, cOutline, outlineWidth, bOutline, heightRef, pos3d, extrusion, outlineExtrusion, bColor, cColor, size, heightRef, circleBillboard;
4172
+ return __generator(this, function (_c) {
4173
+ switch (_c.label) {
4073
4174
  case 0:
4074
4175
  entity = params.entity;
4075
4176
  style = params.style;
@@ -4082,7 +4183,7 @@
4082
4183
  }
4083
4184
  cEntity = null;
4084
4185
  siblings = [];
4085
- if (!(type == bruceModels.Style.EPointType.Icon)) return [3 /*break*/, 12];
4186
+ if (!(type == bruceModels.Style.EPointType.Icon)) return [3 /*break*/, 9];
4086
4187
  iconUrlRows = style.iconUrl == null ? [] : style.iconUrl;
4087
4188
  iconUrlRows.forEach(function (row) {
4088
4189
  if (row.type == bruceModels.Calculator.EValueType.Color) {
@@ -4090,67 +4191,55 @@
4090
4191
  }
4091
4192
  });
4092
4193
  icon = bruceModels.Calculator.GetString(iconUrlRows, entity, params.tags);
4093
- iconUrl_1 = null;
4094
- if (typeof icon == "string") {
4095
- iconUrl_1 = icon;
4096
- }
4097
- if (!iconUrl_1 && style.iconId) {
4098
- iconUrl_1 = bruceModels.ClientFile.GetUrl({
4099
- api: params.api,
4100
- fileId: style.iconId,
4101
- viaCdn: true
4102
- });
4103
- }
4104
- if (!iconUrl_1) return [3 /*break*/, 11];
4105
- _a.label = 1;
4194
+ iconUrl = null;
4195
+ if (!(typeof icon == "string")) return [3 /*break*/, 2];
4196
+ iconUrl = icon;
4197
+ metadata = extractMetadataFromFileUrl(iconUrl);
4198
+ if (!metadata) return [3 /*break*/, 2];
4199
+ api = params.apiGetter.getApi(metadata.accountId);
4200
+ return [4 /*yield*/, api.Loading];
4106
4201
  case 1:
4107
- _a.trys.push([1, 10, , 11]);
4108
- if (!(_fileValidationCache[iconUrl_1] == null)) return [3 /*break*/, 8];
4109
- return [4 /*yield*/, fetch(iconUrl_1)];
4202
+ _c.sent();
4203
+ iconUrl = bruceModels.ClientFile.GetUrl({
4204
+ api: api,
4205
+ fileId: metadata.fileId,
4206
+ viaCdn: true
4207
+ });
4208
+ _c.label = 2;
4110
4209
  case 2:
4111
- res = _a.sent();
4112
- if (!(res.status != 200)) return [3 /*break*/, 3];
4113
- iconUrl_1 = null;
4114
- return [3 /*break*/, 7];
4210
+ if (!(!iconUrl && style.iconId)) return [3 /*break*/, 4];
4211
+ return [4 /*yield*/, params.api.Loading];
4115
4212
  case 3:
4116
- _a.trys.push([3, 6, , 7]);
4117
- return [4 /*yield*/, res.blob()];
4213
+ _c.sent();
4214
+ iconUrl = bruceModels.ClientFile.GetUrl({
4215
+ api: params.api,
4216
+ fileId: style.iconId,
4217
+ viaCdn: true
4218
+ });
4219
+ _c.label = 4;
4118
4220
  case 4:
4119
- blob_1 = _a.sent();
4120
- return [4 /*yield*/, new Promise(function (res) {
4121
- var img = new Image();
4122
- img.onload = function () {
4123
- _fileHeightCache[iconUrl_1] = img.height;
4124
- res(null);
4125
- };
4126
- img.onerror = function () {
4127
- _fileHeightCache[iconUrl_1] = undefined;
4128
- res(null);
4129
- };
4130
- img.src = URL.createObjectURL(blob_1);
4131
- })];
4221
+ image = null;
4222
+ if (!iconUrl) return [3 /*break*/, 8];
4223
+ _c.label = 5;
4132
4224
  case 5:
4133
- _a.sent();
4134
- return [3 /*break*/, 7];
4225
+ _c.trys.push([5, 7, , 8]);
4226
+ return [4 /*yield*/, createImageBillboard(iconUrl)];
4135
4227
  case 6:
4136
- e_4 = _a.sent();
4137
- console.error(e_4);
4138
- return [3 /*break*/, 7];
4228
+ image = _c.sent();
4229
+ return [3 /*break*/, 8];
4139
4230
  case 7:
4140
- _fileValidationCache[iconUrl_1] = Boolean(iconUrl_1);
4141
- return [3 /*break*/, 9];
4231
+ e_5 = _c.sent();
4232
+ // Expanding the logging here so we can figure out why this is happening.
4233
+ // Most of the time the file is missing but we're getting some strange errors so I am including logging on the API settings as well.
4234
+ OneTimeError("ENTITY_RENDER_ENGINE_ICON_URL_ERROR_" + iconUrl, {
4235
+ error: e_5,
4236
+ iconUrl: iconUrl,
4237
+ apiUrl: (_a = params.api) === null || _a === void 0 ? void 0 : _a.GetBaseUrl(),
4238
+ apiAccountId: (_b = params.api) === null || _b === void 0 ? void 0 : _b.AccountId
4239
+ });
4240
+ return [3 /*break*/, 8];
4142
4241
  case 8:
4143
- if (!_fileValidationCache[iconUrl_1]) {
4144
- iconUrl_1 = null;
4145
- }
4146
- _a.label = 9;
4147
- case 9: return [3 /*break*/, 11];
4148
- case 10:
4149
- e_5 = _a.sent();
4150
- iconUrl_1 = null;
4151
- return [3 /*break*/, 11];
4152
- case 11:
4153
- if (iconUrl_1) {
4242
+ if (image) {
4154
4243
  iconScale = EnsureNumber(bruceModels.Calculator.GetNumber(style.iconScale, entity, params.tags));
4155
4244
  if (!iconScale && iconScale != 0) {
4156
4245
  iconScale = 1;
@@ -4165,7 +4254,7 @@
4165
4254
  billboard: {
4166
4255
  horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
4167
4256
  verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
4168
- image: iconUrl_1,
4257
+ image: image.canvas,
4169
4258
  heightReference: getHeightRef(style),
4170
4259
  scale: iconScale,
4171
4260
  disableDepthTestDistance: disableDepthTest ? Number.POSITIVE_INFINITY : undefined,
@@ -4182,11 +4271,11 @@
4182
4271
  }),
4183
4272
  show: true
4184
4273
  });
4185
- cEntity.billboard._billboardSize = _fileHeightCache[iconUrl_1];
4274
+ cEntity.billboard._billboardSize = image.height;
4186
4275
  }
4187
4276
  }
4188
- _a.label = 12;
4189
- case 12:
4277
+ _c.label = 9;
4278
+ case 9:
4190
4279
  if (type == bruceModels.Style.EPointType.Cylinder) {
4191
4280
  radius = EnsureNumber(bruceModels.Calculator.GetNumber(style.CylinderRadius, entity, params.tags));
4192
4281
  if (radius <= 0) {
@@ -4345,6 +4434,7 @@
4345
4434
  tags: tags,
4346
4435
  viewer: params.viewer,
4347
4436
  api: api,
4437
+ apiGetter: params.apiGetter,
4348
4438
  maxDistance: zoomItem.MaxZoom,
4349
4439
  minDistance: zoomItem.MinZoom
4350
4440
  })];
@@ -4944,6 +5034,9 @@
4944
5034
  switch (_g.label) {
4945
5035
  case 0:
4946
5036
  api = params.apiGetter.getApi();
5037
+ return [4 /*yield*/, api.Loading];
5038
+ case 1:
5039
+ _g.sent();
4947
5040
  cEntities = {};
4948
5041
  reqBody = {
4949
5042
  "strict": false,
@@ -4951,32 +5044,32 @@
4951
5044
  "Items": []
4952
5045
  };
4953
5046
  i = 0;
4954
- _g.label = 1;
4955
- case 1:
4956
- if (!(i < params.entities.length)) return [3 /*break*/, 8];
5047
+ _g.label = 2;
5048
+ case 2:
5049
+ if (!(i < params.entities.length)) return [3 /*break*/, 9];
4957
5050
  entity = params.entities[i];
4958
5051
  zoomItem = params.zoomItems[entity.Bruce.ID];
4959
- if (!(zoomItem.StyleID != -1)) return [3 /*break*/, 3];
5052
+ if (!(zoomItem.StyleID != -1)) return [3 /*break*/, 4];
4960
5053
  return [4 /*yield*/, getStyle(api, entity, zoomItem.StyleID)];
4961
- case 2:
4962
- _f = (_a = (_g.sent())) === null || _a === void 0 ? void 0 : _a.Settings;
4963
- return [3 /*break*/, 4];
4964
5054
  case 3:
4965
- _f = zoomItem.Style;
4966
- _g.label = 4;
5055
+ _f = (_a = (_g.sent())) === null || _a === void 0 ? void 0 : _a.Settings;
5056
+ return [3 /*break*/, 5];
4967
5057
  case 4:
5058
+ _f = zoomItem.Style;
5059
+ _g.label = 5;
5060
+ case 5:
4968
5061
  style = _f;
4969
5062
  tagIds = entity.Bruce["Layer.ID"];
4970
5063
  tags = [];
4971
- if (!(tagIds && tagIds.length > 0)) return [3 /*break*/, 6];
5064
+ if (!(tagIds && tagIds.length > 0)) return [3 /*break*/, 7];
4972
5065
  return [4 /*yield*/, bruceModels.EntityTag.GetListByIds({
4973
5066
  api: api,
4974
5067
  tagIds: tagIds
4975
5068
  })];
4976
- case 5:
4977
- tags = (_g.sent()).tags;
4978
- _g.label = 6;
4979
5069
  case 6:
5070
+ tags = (_g.sent()).tags;
5071
+ _g.label = 7;
5072
+ case 7:
4980
5073
  mStyle = (_b = style === null || style === void 0 ? void 0 : style.modelStyle) !== null && _b !== void 0 ? _b : {};
4981
5074
  group = mStyle.lodGroup ? bruceModels.Calculator.GetString(mStyle.lodGroup, entity, tags) : null;
4982
5075
  if (!group) {
@@ -4996,15 +5089,15 @@
4996
5089
  "group": group,
4997
5090
  "level": level
4998
5091
  });
4999
- _g.label = 7;
5000
- case 7:
5092
+ _g.label = 8;
5093
+ case 8:
5001
5094
  i++;
5002
- return [3 /*break*/, 1];
5003
- case 8: return [4 /*yield*/, bruceModels.EntityLod.GetLods({
5095
+ return [3 /*break*/, 2];
5096
+ case 9: return [4 /*yield*/, bruceModels.EntityLod.GetLods({
5004
5097
  api: api,
5005
5098
  filter: reqBody
5006
5099
  })];
5007
- case 9:
5100
+ case 10:
5008
5101
  lodData = (_g.sent()).lods;
5009
5102
  _loop_2 = function (i) {
5010
5103
  var entity, zoomItem, style, _h, tagIds, tags, lod, mStyle, cEntity, name_5;
@@ -5066,17 +5159,17 @@
5066
5159
  });
5067
5160
  };
5068
5161
  i = 0;
5069
- _g.label = 10;
5070
- case 10:
5071
- if (!(i < params.entities.length)) return [3 /*break*/, 13];
5072
- return [5 /*yield**/, _loop_2(i)];
5162
+ _g.label = 11;
5073
5163
  case 11:
5074
- _g.sent();
5075
- _g.label = 12;
5164
+ if (!(i < params.entities.length)) return [3 /*break*/, 14];
5165
+ return [5 /*yield**/, _loop_2(i)];
5076
5166
  case 12:
5167
+ _g.sent();
5168
+ _g.label = 13;
5169
+ case 13:
5077
5170
  i++;
5078
- return [3 /*break*/, 10];
5079
- case 13: return [2 /*return*/, cEntities];
5171
+ return [3 /*break*/, 11];
5172
+ case 14: return [2 /*return*/, cEntities];
5080
5173
  }
5081
5174
  });
5082
5175
  });
@@ -21449,7 +21542,7 @@
21449
21542
  CesiumViewMonitor.Monitor = Monitor;
21450
21543
  })(exports.CesiumViewMonitor || (exports.CesiumViewMonitor = {}));
21451
21544
 
21452
- var VERSION$1 = "3.4.6";
21545
+ var VERSION$1 = "3.4.7";
21453
21546
 
21454
21547
  exports.VERSION = VERSION$1;
21455
21548
  exports.CesiumParabola = CesiumParabola;