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.
@@ -46,5 +46,5 @@ __exportStar(require("./utils/measure-utils"), exports);
46
46
  __exportStar(require("./utils/entity-utils"), exports);
47
47
  __exportStar(require("./widgets/common/draw-3d-polygon"), exports);
48
48
  __exportStar(require("./widgets/common/draw-3d-polyline"), exports);
49
- exports.VERSION = "3.4.6";
49
+ exports.VERSION = "3.4.7";
50
50
  //# sourceMappingURL=bruce-cesium.js.map
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OneTimeError = void 0;
4
+ var _logErrorCache = {};
5
+ /**
6
+ * Will only log the error once matching the key.
7
+ * @param key
8
+ * @param message
9
+ */
10
+ function OneTimeError(key, message) {
11
+ if (!_logErrorCache[key]) {
12
+ console.error(message);
13
+ _logErrorCache[key] = true;
14
+ }
15
+ }
16
+ exports.OneTimeError = OneTimeError;
17
+ //# sourceMappingURL=limited-log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limited-log.js","sourceRoot":"","sources":["../../../src/internal/limited-log.ts"],"names":[],"mappings":";;;AAAA,IAAI,cAAc,GAAG,EAAE,CAAC;AACxB;;;;GAIG;AACH,SAAgB,YAAY,CAAC,GAAW,EAAE,OAAoB;IAC1D,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;QACtB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACvB,cAAc,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;KAC9B;AACL,CAAC;AALD,oCAKC"}
@@ -54,6 +54,7 @@ var entity_utils_1 = require("../utils/entity-utils");
54
54
  var render_manager_1 = require("./render-managers/render-manager");
55
55
  var js_utils_1 = require("../internal/js-utils");
56
56
  var visual_register_culler_1 = require("./visual-register-culler");
57
+ var limited_log_1 = require("../internal/limited-log");
57
58
  function colorToCColor(color) {
58
59
  return new Cesium.Color(color.red ? color.red / 255 : 0, color.green ? color.green / 255 : 0, color.blue ? color.blue / 255 : 0, color.alpha);
59
60
  }
@@ -440,7 +441,7 @@ function getTranslucencyByDistance(min, max) {
440
441
  }
441
442
  return new Cesium.NearFarScalar(min, 1, max, 0);
442
443
  }
443
- var _billboardCache = new bruce_models_1.LRUCache(100);
444
+ var _billboardCache = new bruce_models_1.LRUCache(150);
444
445
  var POINT_BILLBOARD_PADDING = 1;
445
446
  var createCircleBillboard = function (size, colorCss) {
446
447
  var key = size + "-" + colorCss;
@@ -468,6 +469,53 @@ var createCircleBillboard = function (size, colorCss) {
468
469
  _billboardCache.Set(key, data);
469
470
  return data;
470
471
  };
472
+ var createImageBillboard = function (url) {
473
+ var cacheKey = "image-" + url;
474
+ var cacheData = _billboardCache.Get(cacheKey);
475
+ if (cacheData) {
476
+ return cacheData;
477
+ }
478
+ var prom = new Promise(function (res, rej) { return __awaiter(void 0, void 0, void 0, function () {
479
+ var response, blob, canvas_1, image_1, e_4;
480
+ return __generator(this, function (_a) {
481
+ switch (_a.label) {
482
+ case 0:
483
+ _a.trys.push([0, 3, , 4]);
484
+ return [4 /*yield*/, fetch(url)];
485
+ case 1:
486
+ response = _a.sent();
487
+ return [4 /*yield*/, response.blob()];
488
+ case 2:
489
+ blob = _a.sent();
490
+ canvas_1 = document.createElement("canvas");
491
+ image_1 = new Image();
492
+ image_1.onload = function () {
493
+ canvas_1.width = image_1.width;
494
+ canvas_1.height = image_1.height;
495
+ var context = canvas_1.getContext("2d");
496
+ context.drawImage(image_1, 0, 0);
497
+ var data = {
498
+ canvas: canvas_1,
499
+ height: image_1.height
500
+ };
501
+ res(data);
502
+ };
503
+ image_1.onerror = function () {
504
+ rej(null);
505
+ };
506
+ image_1.src = URL.createObjectURL(blob);
507
+ return [3 /*break*/, 4];
508
+ case 3:
509
+ e_4 = _a.sent();
510
+ rej(null);
511
+ return [3 /*break*/, 4];
512
+ case 4: return [2 /*return*/];
513
+ }
514
+ });
515
+ }); });
516
+ _billboardCache.Set(cacheKey, prom);
517
+ return prom;
518
+ };
471
519
  /**
472
520
  * Removes duplicate points in a row and returns a new array.
473
521
  * Passed array is not mutated.
@@ -518,6 +566,48 @@ function getModelEntity(url, scale) {
518
566
  });
519
567
  });
520
568
  }
569
+ /**
570
+ * Turns a hard-coded file url into pieces so we can properly load it using our libraries rather than directly.
571
+ * @param url eg: https://demoplantprocess.api.nextspace-uat.net/file/4c29bdf8-1f0b-4739-b0ee-421ea07ba4e5.png
572
+ */
573
+ function extractMetadataFromFileUrl(url) {
574
+ var _a;
575
+ url = url.toLowerCase();
576
+ // Bzzt, invalid url format for our purposes.
577
+ if (!url.includes(".api.") || !url.includes("/file/")) {
578
+ return null;
579
+ }
580
+ url = url.replace("https://", "").replace("http://", "");
581
+ var envId = bruce_models_1.Api.EEnv.PROD;
582
+ if (url.includes("-dev.net")) {
583
+ envId = bruce_models_1.Api.EEnv.DEV;
584
+ }
585
+ else if (url.includes("-stg.net")) {
586
+ envId = bruce_models_1.Api.EEnv.STG;
587
+ }
588
+ else if (url.includes("-uat.net")) {
589
+ envId = bruce_models_1.Api.EEnv.UAT;
590
+ }
591
+ var parts = url.split("/");
592
+ var host = parts[0];
593
+ var hostParts = host.split(".");
594
+ var accountId = hostParts[0];
595
+ var fileId = (_a = parts[2]) !== null && _a !== void 0 ? _a : "";
596
+ if (fileId.includes("?")) {
597
+ fileId = fileId.split("?")[0];
598
+ }
599
+ if (fileId.includes(".")) {
600
+ fileId = fileId.split(".")[0];
601
+ }
602
+ if (!fileId || !accountId) {
603
+ return null;
604
+ }
605
+ return {
606
+ accountId: accountId,
607
+ fileId: fileId,
608
+ envId: envId
609
+ };
610
+ }
521
611
  var EntityRenderEngine;
522
612
  (function (EntityRenderEngine) {
523
613
  function Render(params) {
@@ -791,10 +881,11 @@ var EntityRenderEngine;
791
881
  }
792
882
  Point.CreateCircleBillboard = CreateCircleBillboard;
793
883
  function Render(params) {
884
+ var _a, _b;
794
885
  return __awaiter(this, void 0, void 0, function () {
795
- 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;
796
- return __generator(this, function (_a) {
797
- switch (_a.label) {
886
+ 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;
887
+ return __generator(this, function (_c) {
888
+ switch (_c.label) {
798
889
  case 0:
799
890
  entity = params.entity;
800
891
  style = params.style;
@@ -807,7 +898,7 @@ var EntityRenderEngine;
807
898
  }
808
899
  cEntity = null;
809
900
  siblings = [];
810
- if (!(type == bruce_models_1.Style.EPointType.Icon)) return [3 /*break*/, 12];
901
+ if (!(type == bruce_models_1.Style.EPointType.Icon)) return [3 /*break*/, 9];
811
902
  iconUrlRows = style.iconUrl == null ? [] : style.iconUrl;
812
903
  iconUrlRows.forEach(function (row) {
813
904
  if (row.type == bruce_models_1.Calculator.EValueType.Color) {
@@ -815,67 +906,55 @@ var EntityRenderEngine;
815
906
  }
816
907
  });
817
908
  icon = bruce_models_1.Calculator.GetString(iconUrlRows, entity, params.tags);
818
- iconUrl_1 = null;
819
- if (typeof icon == "string") {
820
- iconUrl_1 = icon;
821
- }
822
- if (!iconUrl_1 && style.iconId) {
823
- iconUrl_1 = bruce_models_1.ClientFile.GetUrl({
824
- api: params.api,
825
- fileId: style.iconId,
826
- viaCdn: true
827
- });
828
- }
829
- if (!iconUrl_1) return [3 /*break*/, 11];
830
- _a.label = 1;
909
+ iconUrl = null;
910
+ if (!(typeof icon == "string")) return [3 /*break*/, 2];
911
+ iconUrl = icon;
912
+ metadata = extractMetadataFromFileUrl(iconUrl);
913
+ if (!metadata) return [3 /*break*/, 2];
914
+ api = params.apiGetter.getApi(metadata.accountId);
915
+ return [4 /*yield*/, api.Loading];
831
916
  case 1:
832
- _a.trys.push([1, 10, , 11]);
833
- if (!(_fileValidationCache[iconUrl_1] == null)) return [3 /*break*/, 8];
834
- return [4 /*yield*/, fetch(iconUrl_1)];
917
+ _c.sent();
918
+ iconUrl = bruce_models_1.ClientFile.GetUrl({
919
+ api: api,
920
+ fileId: metadata.fileId,
921
+ viaCdn: true
922
+ });
923
+ _c.label = 2;
835
924
  case 2:
836
- res = _a.sent();
837
- if (!(res.status != 200)) return [3 /*break*/, 3];
838
- iconUrl_1 = null;
839
- return [3 /*break*/, 7];
925
+ if (!(!iconUrl && style.iconId)) return [3 /*break*/, 4];
926
+ return [4 /*yield*/, params.api.Loading];
840
927
  case 3:
841
- _a.trys.push([3, 6, , 7]);
842
- return [4 /*yield*/, res.blob()];
928
+ _c.sent();
929
+ iconUrl = bruce_models_1.ClientFile.GetUrl({
930
+ api: params.api,
931
+ fileId: style.iconId,
932
+ viaCdn: true
933
+ });
934
+ _c.label = 4;
843
935
  case 4:
844
- blob_1 = _a.sent();
845
- return [4 /*yield*/, new Promise(function (res) {
846
- var img = new Image();
847
- img.onload = function () {
848
- _fileHeightCache[iconUrl_1] = img.height;
849
- res(null);
850
- };
851
- img.onerror = function () {
852
- _fileHeightCache[iconUrl_1] = undefined;
853
- res(null);
854
- };
855
- img.src = URL.createObjectURL(blob_1);
856
- })];
936
+ image = null;
937
+ if (!iconUrl) return [3 /*break*/, 8];
938
+ _c.label = 5;
857
939
  case 5:
858
- _a.sent();
859
- return [3 /*break*/, 7];
940
+ _c.trys.push([5, 7, , 8]);
941
+ return [4 /*yield*/, createImageBillboard(iconUrl)];
860
942
  case 6:
861
- e_4 = _a.sent();
862
- console.error(e_4);
863
- return [3 /*break*/, 7];
943
+ image = _c.sent();
944
+ return [3 /*break*/, 8];
864
945
  case 7:
865
- _fileValidationCache[iconUrl_1] = Boolean(iconUrl_1);
866
- return [3 /*break*/, 9];
946
+ e_5 = _c.sent();
947
+ // Expanding the logging here so we can figure out why this is happening.
948
+ // 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.
949
+ (0, limited_log_1.OneTimeError)("ENTITY_RENDER_ENGINE_ICON_URL_ERROR_" + iconUrl, {
950
+ error: e_5,
951
+ iconUrl: iconUrl,
952
+ apiUrl: (_a = params.api) === null || _a === void 0 ? void 0 : _a.GetBaseUrl(),
953
+ apiAccountId: (_b = params.api) === null || _b === void 0 ? void 0 : _b.AccountId
954
+ });
955
+ return [3 /*break*/, 8];
867
956
  case 8:
868
- if (!_fileValidationCache[iconUrl_1]) {
869
- iconUrl_1 = null;
870
- }
871
- _a.label = 9;
872
- case 9: return [3 /*break*/, 11];
873
- case 10:
874
- e_5 = _a.sent();
875
- iconUrl_1 = null;
876
- return [3 /*break*/, 11];
877
- case 11:
878
- if (iconUrl_1) {
957
+ if (image) {
879
958
  iconScale = (0, js_utils_1.EnsureNumber)(bruce_models_1.Calculator.GetNumber(style.iconScale, entity, params.tags));
880
959
  if (!iconScale && iconScale != 0) {
881
960
  iconScale = 1;
@@ -890,7 +969,7 @@ var EntityRenderEngine;
890
969
  billboard: {
891
970
  horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
892
971
  verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
893
- image: iconUrl_1,
972
+ image: image.canvas,
894
973
  heightReference: getHeightRef(style),
895
974
  scale: iconScale,
896
975
  disableDepthTestDistance: disableDepthTest ? Number.POSITIVE_INFINITY : undefined,
@@ -907,11 +986,11 @@ var EntityRenderEngine;
907
986
  }),
908
987
  show: true
909
988
  });
910
- cEntity.billboard._billboardSize = _fileHeightCache[iconUrl_1];
989
+ cEntity.billboard._billboardSize = image.height;
911
990
  }
912
991
  }
913
- _a.label = 12;
914
- case 12:
992
+ _c.label = 9;
993
+ case 9:
915
994
  if (type == bruce_models_1.Style.EPointType.Cylinder) {
916
995
  radius = (0, js_utils_1.EnsureNumber)(bruce_models_1.Calculator.GetNumber(style.CylinderRadius, entity, params.tags));
917
996
  if (radius <= 0) {
@@ -1070,6 +1149,7 @@ var EntityRenderEngine;
1070
1149
  tags: tags,
1071
1150
  viewer: params.viewer,
1072
1151
  api: api,
1152
+ apiGetter: params.apiGetter,
1073
1153
  maxDistance: zoomItem.MaxZoom,
1074
1154
  minDistance: zoomItem.MinZoom
1075
1155
  })];
@@ -1669,6 +1749,9 @@ var EntityRenderEngine;
1669
1749
  switch (_g.label) {
1670
1750
  case 0:
1671
1751
  api = params.apiGetter.getApi();
1752
+ return [4 /*yield*/, api.Loading];
1753
+ case 1:
1754
+ _g.sent();
1672
1755
  cEntities = {};
1673
1756
  reqBody = {
1674
1757
  "strict": false,
@@ -1676,32 +1759,32 @@ var EntityRenderEngine;
1676
1759
  "Items": []
1677
1760
  };
1678
1761
  i = 0;
1679
- _g.label = 1;
1680
- case 1:
1681
- if (!(i < params.entities.length)) return [3 /*break*/, 8];
1762
+ _g.label = 2;
1763
+ case 2:
1764
+ if (!(i < params.entities.length)) return [3 /*break*/, 9];
1682
1765
  entity = params.entities[i];
1683
1766
  zoomItem = params.zoomItems[entity.Bruce.ID];
1684
- if (!(zoomItem.StyleID != -1)) return [3 /*break*/, 3];
1767
+ if (!(zoomItem.StyleID != -1)) return [3 /*break*/, 4];
1685
1768
  return [4 /*yield*/, getStyle(api, entity, zoomItem.StyleID)];
1686
- case 2:
1687
- _f = (_a = (_g.sent())) === null || _a === void 0 ? void 0 : _a.Settings;
1688
- return [3 /*break*/, 4];
1689
1769
  case 3:
1690
- _f = zoomItem.Style;
1691
- _g.label = 4;
1770
+ _f = (_a = (_g.sent())) === null || _a === void 0 ? void 0 : _a.Settings;
1771
+ return [3 /*break*/, 5];
1692
1772
  case 4:
1773
+ _f = zoomItem.Style;
1774
+ _g.label = 5;
1775
+ case 5:
1693
1776
  style = _f;
1694
1777
  tagIds = entity.Bruce["Layer.ID"];
1695
1778
  tags = [];
1696
- if (!(tagIds && tagIds.length > 0)) return [3 /*break*/, 6];
1779
+ if (!(tagIds && tagIds.length > 0)) return [3 /*break*/, 7];
1697
1780
  return [4 /*yield*/, bruce_models_1.EntityTag.GetListByIds({
1698
1781
  api: api,
1699
1782
  tagIds: tagIds
1700
1783
  })];
1701
- case 5:
1702
- tags = (_g.sent()).tags;
1703
- _g.label = 6;
1704
1784
  case 6:
1785
+ tags = (_g.sent()).tags;
1786
+ _g.label = 7;
1787
+ case 7:
1705
1788
  mStyle = (_b = style === null || style === void 0 ? void 0 : style.modelStyle) !== null && _b !== void 0 ? _b : {};
1706
1789
  group = mStyle.lodGroup ? bruce_models_1.Calculator.GetString(mStyle.lodGroup, entity, tags) : null;
1707
1790
  if (!group) {
@@ -1721,15 +1804,15 @@ var EntityRenderEngine;
1721
1804
  "group": group,
1722
1805
  "level": level
1723
1806
  });
1724
- _g.label = 7;
1725
- case 7:
1807
+ _g.label = 8;
1808
+ case 8:
1726
1809
  i++;
1727
- return [3 /*break*/, 1];
1728
- case 8: return [4 /*yield*/, bruce_models_1.EntityLod.GetLods({
1810
+ return [3 /*break*/, 2];
1811
+ case 9: return [4 /*yield*/, bruce_models_1.EntityLod.GetLods({
1729
1812
  api: api,
1730
1813
  filter: reqBody
1731
1814
  })];
1732
- case 9:
1815
+ case 10:
1733
1816
  lodData = (_g.sent()).lods;
1734
1817
  _loop_2 = function (i) {
1735
1818
  var entity, zoomItem, style, _h, tagIds, tags, lod, mStyle, cEntity, name_5;
@@ -1791,17 +1874,17 @@ var EntityRenderEngine;
1791
1874
  });
1792
1875
  };
1793
1876
  i = 0;
1794
- _g.label = 10;
1795
- case 10:
1796
- if (!(i < params.entities.length)) return [3 /*break*/, 13];
1797
- return [5 /*yield**/, _loop_2(i)];
1877
+ _g.label = 11;
1798
1878
  case 11:
1799
- _g.sent();
1800
- _g.label = 12;
1879
+ if (!(i < params.entities.length)) return [3 /*break*/, 14];
1880
+ return [5 /*yield**/, _loop_2(i)];
1801
1881
  case 12:
1882
+ _g.sent();
1883
+ _g.label = 13;
1884
+ case 13:
1802
1885
  i++;
1803
- return [3 /*break*/, 10];
1804
- case 13: return [2 /*return*/, cEntities];
1886
+ return [3 /*break*/, 11];
1887
+ case 14: return [2 /*return*/, cEntities];
1805
1888
  }
1806
1889
  });
1807
1890
  });