bruce-cesium 2.8.7 → 2.8.9

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.
@@ -1937,6 +1937,34 @@
1937
1937
  }
1938
1938
  return length;
1939
1939
  }
1940
+ var _billboardCache = new bruceModels.LRUCache(100);
1941
+ var POINT_BILLBOARD_PADDING = 1;
1942
+ var createCircleBillboard = function (size, colorCss) {
1943
+ var key = size + "-" + colorCss;
1944
+ var cacheData = _billboardCache.Get(key);
1945
+ if ((cacheData === null || cacheData === void 0 ? void 0 : cacheData.canvas) instanceof HTMLCanvasElement) {
1946
+ return cacheData;
1947
+ }
1948
+ // Slight padding to avoid corners clipping.
1949
+ var canvasSize = size + (POINT_BILLBOARD_PADDING * 4);
1950
+ var canvas = document.createElement("canvas");
1951
+ canvas.width = canvasSize;
1952
+ canvas.height = canvasSize;
1953
+ var context = canvas.getContext("2d");
1954
+ context.beginPath();
1955
+ context.arc(canvasSize / 2, canvasSize / 2, size / 2, 0, 2 * Math.PI, false);
1956
+ context.fillStyle = colorCss;
1957
+ context.fill();
1958
+ var data = {
1959
+ canvas: canvas,
1960
+ colorCss: colorCss,
1961
+ size: size,
1962
+ height: canvasSize,
1963
+ width: canvasSize
1964
+ };
1965
+ _billboardCache.Set(key, data);
1966
+ return data;
1967
+ };
1940
1968
  (function (EntityRenderEngine) {
1941
1969
  function Render(params) {
1942
1970
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -2196,7 +2224,7 @@
2196
2224
  (function (Point) {
2197
2225
  function Render(params) {
2198
2226
  return __awaiter(this, void 0, void 0, function () {
2199
- var entity, style, type, cEntity, siblings, iconUrlRows, icon, iconUrl_1, res, blob_1, e_4, e_5, iconScale, disableDepthTest, heightRef, radius, bFill, cFill, outline, cOutline, outlineWidth, bOutline, heightRef, pos3d, extrusion, outlineExtrusion, bColor, cColor, size, heightRef;
2227
+ var entity, style, type, cEntity, siblings, iconUrlRows, icon, iconUrl_1, res, blob_1, e_4, e_5, iconScale, disableDepthTest, heightRef, radius, bFill, cFill, outline, cOutline, outlineWidth, bOutline, heightRef, pos3d, extrusion, outlineExtrusion, bColor, cColor, size, heightRef, circleBillboard;
2200
2228
  return __generator(this, function (_a) {
2201
2229
  switch (_a.label) {
2202
2230
  case 0:
@@ -2294,8 +2322,7 @@
2294
2322
  heightReference: getHeightRef(style),
2295
2323
  scale: iconScale,
2296
2324
  disableDepthTestDistance: disableDepthTest ? Number.POSITIVE_INFINITY : undefined,
2297
- distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance),
2298
- height: _fileHeightCache[iconUrl_1]
2325
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
2299
2326
  // Would be great once we have a setting for this.
2300
2327
  // translucencyByDistance: getTranslucencyByDistance(params.minDistance, params.maxDistance),
2301
2328
  },
@@ -2307,6 +2334,7 @@
2307
2334
  }),
2308
2335
  show: true
2309
2336
  });
2337
+ cEntity.billboard._billboardSize = _fileHeightCache[iconUrl_1];
2310
2338
  }
2311
2339
  }
2312
2340
  _a.label = 12;
@@ -2386,11 +2414,22 @@
2386
2414
  return [2 /*return*/, null];
2387
2415
  }
2388
2416
  heightRef = getHeightRef(style);
2417
+ circleBillboard = createCircleBillboard(size, cColor.toCssColorString());
2389
2418
  cEntity = new Cesium.Entity({
2390
- point: {
2391
- pixelSize: size,
2392
- color: cColor,
2393
- heightReference: getHeightRef(style),
2419
+ // point: {
2420
+ // pixelSize: size,
2421
+ // color: cColor,
2422
+ // heightReference: getHeightRef(style),
2423
+ // distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
2424
+ // },
2425
+ // We are generating a billboard instead of using the point.
2426
+ // This is because points were behaving strangely where they would appear oblong shapes.
2427
+ // This occurred consistently when rendering many icons and points at the same time.
2428
+ billboard: {
2429
+ height: circleBillboard.height,
2430
+ width: circleBillboard.width,
2431
+ image: circleBillboard.canvas,
2432
+ heightReference: heightRef,
2394
2433
  distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
2395
2434
  },
2396
2435
  position: exports.EntityUtils.GetPos({
@@ -2401,6 +2440,7 @@
2401
2440
  }),
2402
2441
  show: true
2403
2442
  });
2443
+ cEntity.billboard._billboardSize = Math.ceil(circleBillboard.height / 2);
2404
2444
  }
2405
2445
  if (cEntity) {
2406
2446
  cEntity._siblingGraphics = siblings;
@@ -3803,12 +3843,12 @@
3803
3843
  return __generator(this, function (_h) {
3804
3844
  switch (_h.label) {
3805
3845
  case 0:
3846
+ this.removeLabel();
3806
3847
  pos3d = starterPos3d ? starterPos3d.clone() : null;
3807
3848
  counter = ++this.counter;
3808
3849
  if (this.disposed) {
3809
3850
  return [2 /*return*/];
3810
3851
  }
3811
- this.removeLabel();
3812
3852
  sizeInM = 0;
3813
3853
  heightRef = null;
3814
3854
  pixelOffset = new Cesium.Cartesian2(0, -5);
@@ -3893,7 +3933,7 @@
3893
3933
  }
3894
3934
  else if (visual.billboard) {
3895
3935
  heightRef = getValue$1(this.viewer, visual.billboard.heightReference);
3896
- height = getValue$1(this.viewer, visual.billboard.height);
3936
+ height = visual.billboard._billboardSize;
3897
3937
  if (height) {
3898
3938
  scale = EnsureNumber(getValue$1(this.viewer, visual.billboard.scale), 1);
3899
3939
  pixelOffset.y = -(height * scale);
@@ -3943,7 +3983,7 @@
3943
3983
  case 1:
3944
3984
  pos3d = _h.sent();
3945
3985
  heightRef = Cesium.HeightReference.NONE;
3946
- if (this.counter != counter) {
3986
+ if (this.counter != counter || this.disposed) {
3947
3987
  return [2 /*return*/];
3948
3988
  }
3949
3989
  _h.label = 2;
@@ -4000,11 +4040,17 @@
4000
4040
  if (this.disposed || this.counter != counter) {
4001
4041
  return [2 /*return*/];
4002
4042
  }
4003
- ele = document.createElement("div");
4004
- ele.innerHTML = text;
4005
- ele.setAttribute("style", "\n position: absolute;\n z-index: 0;\n display: none;\n pointer-events: none;\n padding: 6px 8px;\n border-radius: 6px;\n font-family: Arial;\n font-size: 12px;\n -webkit-backdrop-filter: blur(20px);\n backdrop-filter: blur(20px);\n background: rgba(33,39,42,.8);\n border-radius: 9px;\n box-shadow: 0 0 1px rgba(18,22,25,.36),0 18px 36px -4px rgba(18,22,25,.36);\n color: #ffffff;\n }");
4006
- this.label = ele;
4007
- this.viewer.container.appendChild(ele);
4043
+ ele = null;
4044
+ if (this.label) {
4045
+ ele = this.label;
4046
+ }
4047
+ else {
4048
+ ele = document.createElement("div");
4049
+ ele.innerHTML = text;
4050
+ ele.setAttribute("style", "\n position: absolute;\n z-index: 0;\n display: none;\n pointer-events: none;\n padding: 6px 8px;\n border-radius: 6px;\n font-family: Arial;\n font-size: 12px;\n -webkit-backdrop-filter: blur(20px);\n backdrop-filter: blur(20px);\n background: rgba(33,39,42,.8);\n border-radius: 9px;\n box-shadow: 0 0 1px rgba(18,22,25,.36),0 18px 36px -4px rgba(18,22,25,.36);\n color: #ffffff;\n }");
4051
+ this.label = ele;
4052
+ this.viewer.container.appendChild(ele);
4053
+ }
4008
4054
  _lastDistance = null;
4009
4055
  _lastCameraPos = null;
4010
4056
  getDistance = function () {
@@ -4107,12 +4153,12 @@
4107
4153
  updateLabel();
4108
4154
  terrTimeout = null;
4109
4155
  this.terrChangedRemoval = this.viewer.scene.terrainProviderChanged.addEventListener(function () {
4110
- if (_this.disposed) {
4156
+ clearTimeout(terrTimeout);
4157
+ if (_this.disposed || _this.counter != counter) {
4111
4158
  return;
4112
4159
  }
4113
- clearTimeout(terrTimeout);
4114
4160
  terrTimeout = setTimeout(function () {
4115
- if (counter != _this.counter) {
4161
+ if (_this.disposed || counter != _this.counter) {
4116
4162
  return;
4117
4163
  }
4118
4164
  _this.createLabel(starterPos3d);
@@ -4346,6 +4392,11 @@
4346
4392
  });
4347
4393
  }
4348
4394
  }
4395
+ else {
4396
+ exports.EntityLabel.Detatch({
4397
+ rego: rego
4398
+ });
4399
+ }
4349
4400
  }
4350
4401
  }
4351
4402
  function markEntity(register, rego, visual, ignoreParent) {
@@ -4940,6 +4991,9 @@
4940
4991
  if (shouldRetain) {
4941
4992
  continue;
4942
4993
  }
4994
+ exports.EntityLabel.Detatch({
4995
+ rego: rego
4996
+ });
4943
4997
  removeEntity(this.viewer, rego.visual);
4944
4998
  var doesInclude = this.rego[entityId_4].find(function (r) { return r.menuItemId === menuItemId; });
4945
4999
  if (doesInclude) {
@@ -4968,6 +5022,9 @@
4968
5022
  if (!rego) {
4969
5023
  return { value: void 0 };
4970
5024
  }
5025
+ exports.EntityLabel.Detatch({
5026
+ rego: rego
5027
+ });
4971
5028
  removeEntity(this_2.viewer, rego.visual);
4972
5029
  (_b = this_2.onUpdate) === null || _b === void 0 ? void 0 : _b.Trigger({
4973
5030
  type: EVisualUpdateType.Remove,
@@ -4995,6 +5052,9 @@
4995
5052
  if (!rego) {
4996
5053
  continue;
4997
5054
  }
5055
+ exports.EntityLabel.Detatch({
5056
+ rego: rego
5057
+ });
4998
5058
  removeEntity(this.viewer, rego.visual);
4999
5059
  this.rego[entityId_5] = entityRegos.filter(function (r) { return r.menuItemId !== menuItemId; });
5000
5060
  (_c = this.onUpdate) === null || _c === void 0 ? void 0 : _c.Trigger({
@@ -5015,7 +5075,7 @@
5015
5075
  /**
5016
5076
  * Returns an array of drilled visuals associated with this register.
5017
5077
  * The top array item is the first found.
5018
- * @param cursor
5078
+ * @param params
5019
5079
  * @returns
5020
5080
  */
5021
5081
  Register.prototype.GetRegosFromCursor = function (params) {
@@ -9906,11 +9966,17 @@
9906
9966
  * @param relation
9907
9967
  */
9908
9968
  Manager.prototype.shouldRenderRelation = function (relation) {
9909
- var _a, _b, _c;
9910
- if (((_a = this.item.relationTypeIds) === null || _a === void 0 ? void 0 : _a.length) && !this.item.relationTypeIds.includes(relation["Relation.Type.ID"])) {
9911
- return false;
9969
+ var _a, _b, _c, _d;
9970
+ if ((_a = this.item.relations) === null || _a === void 0 ? void 0 : _a.length) {
9971
+ // Find group for the same relationship type.
9972
+ var typeRelations = this.item.relations.find(function (x) { return x.relationTypeId == relation["Relation.Type.ID"]; });
9973
+ // See if group contains the parent entity ID.
9974
+ if ((_b = typeRelations === null || typeRelations === void 0 ? void 0 : typeRelations.entityIds) === null || _b === void 0 ? void 0 : _b.find(function (x) { return x == relation["Principal.Entity.ID"]; })) {
9975
+ return true;
9976
+ }
9912
9977
  }
9913
- var renderedIds = (_c = (_b = this.item) === null || _b === void 0 ? void 0 : _b.BruceEntity) === null || _c === void 0 ? void 0 : _c.EntityIds;
9978
+ // Backwards compatability.
9979
+ var renderedIds = (_d = (_c = this.item) === null || _c === void 0 ? void 0 : _c.BruceEntity) === null || _d === void 0 ? void 0 : _d.EntityIds;
9914
9980
  if (!renderedIds) {
9915
9981
  return false;
9916
9982
  }
@@ -10362,8 +10428,7 @@
10362
10428
  /**
10363
10429
  * Disables a menu item by its id.
10364
10430
  * This will disable all children as well.
10365
- * @param id
10366
- * @param recursive
10431
+ * @param params
10367
10432
  */
10368
10433
  Manager.prototype.RemoveItemById = function (params) {
10369
10434
  var _a, _b;
@@ -12685,6 +12750,7 @@
12685
12750
  }
12686
12751
  /**
12687
12752
  * Renders DATA_VERSION = 1 navigator.
12753
+ * param iteration
12688
12754
  * @param params
12689
12755
  * @param bookmark
12690
12756
  * @param view
@@ -12808,33 +12874,32 @@
12808
12874
  }
12809
12875
  _f.label = 3;
12810
12876
  case 3:
12811
- if (!((_e = bSettings === null || bSettings === void 0 ? void 0 : bSettings.drawnRelationEntityIDs) === null || _e === void 0 ? void 0 : _e.length)) return [3 /*break*/, 5];
12812
- menuItem = {
12813
- id: RELATION_MENU_ITEM_ID,
12814
- Caption: "Entity relations",
12815
- BruceEntity: {
12816
- EntityIds: bSettings.drawnRelationEntityIDs
12817
- },
12818
- Type: bruceModels.MenuItem.EType.Relations
12819
- };
12820
- return [4 /*yield*/, params.manager.RenderItem({
12877
+ if ((_e = bSettings === null || bSettings === void 0 ? void 0 : bSettings.drawnRelationEntityIDs) === null || _e === void 0 ? void 0 : _e.length) {
12878
+ menuItem = {
12879
+ id: RELATION_MENU_ITEM_ID,
12880
+ Caption: "Entity relations",
12881
+ BruceEntity: {
12882
+ EntityIds: bSettings.drawnRelationEntityIDs
12883
+ },
12884
+ Type: bruceModels.MenuItem.EType.Relations
12885
+ };
12886
+ params.manager.RenderItem({
12821
12887
  apiGetter: params.apiGetter,
12822
12888
  getters: params.getters,
12823
12889
  item: menuItem
12824
- })];
12825
- case 4:
12826
- _f.sent();
12827
- if (!assertIteration$1(params.viewer, iteration)) {
12828
- return [2 /*return*/];
12890
+ });
12891
+ if (!assertIteration$1(params.viewer, iteration)) {
12892
+ return [2 /*return*/];
12893
+ }
12829
12894
  }
12830
- _f.label = 5;
12831
- case 5: return [2 /*return*/];
12895
+ return [2 /*return*/];
12832
12896
  }
12833
12897
  });
12834
12898
  });
12835
12899
  }
12836
12900
  /**
12837
12901
  * Renders DATA_VERSION > 1 navigator.
12902
+ * @param iteration
12838
12903
  * @param params
12839
12904
  * @param bookmark
12840
12905
  * @param view
@@ -12842,7 +12907,7 @@
12842
12907
  function renderNavigator(iteration, params, bookmark, view) {
12843
12908
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6;
12844
12909
  return __awaiter(this, void 0, void 0, function () {
12845
- var viewer, scene, vSettings, bSettings, defaults, camera, newLens, shouldBe2d, curIs2d, transition, pos, terrain, hillShades, baseColor, globeHidden, terrainWireframe, globeAlpha, shadows, size, ambientOcclusion, AO, lighting, light, quality, fxaa, dateTime, clock, selectedIds, hiddenIds, isolatedIds, labelledIds, entityOpacityMap, entityId, opacity, imagery, renderedRelationEntityIds, curEnabled, newItemIds, _i, curEnabled_1, id, menuItem, gOcclusion;
12910
+ var viewer, scene, vSettings, bSettings, defaults, camera, newLens, shouldBe2d, curIs2d, transition, pos, terrain, hillShades, baseColor, globeHidden, terrainWireframe, globeAlpha, shadows, size, ambientOcclusion, AO, lighting, light, quality, fxaa, dateTime, clock, selectedIds, hiddenIds, isolatedIds, labelledIds, curLabelledIds, toUnLabel, entityOpacityMap, entityId, opacity, imagery, legacyRelationIds, relations, curEnabled, newItemIds, _i, curEnabled_1, id, menuItem, gOcclusion;
12846
12911
  return __generator(this, function (_7) {
12847
12912
  switch (_7.label) {
12848
12913
  case 0:
@@ -13070,15 +13135,24 @@
13070
13135
  entityIds: isolatedIds
13071
13136
  });
13072
13137
  }
13073
- params.manager.VisualsRegister.ClearLabelled();
13074
13138
  labelledIds = bSettings === null || bSettings === void 0 ? void 0 : bSettings.labelledEntityIds;
13075
13139
  if (labelledIds == null) {
13076
13140
  labelledIds = (_2 = defaults === null || defaults === void 0 ? void 0 : defaults.settings) === null || _2 === void 0 ? void 0 : _2.labelledEntityIds;
13077
13141
  }
13078
- if (labelledIds != null) {
13142
+ if (!(labelledIds === null || labelledIds === void 0 ? void 0 : labelledIds.length)) {
13143
+ params.manager.VisualsRegister.ClearLabelled();
13144
+ }
13145
+ else {
13146
+ curLabelledIds = params.manager.VisualsRegister.GetLabelled();
13079
13147
  params.manager.VisualsRegister.SetLabelled({
13080
13148
  labelled: true,
13081
- entityIds: labelledIds
13149
+ entityIds: labelledIds,
13150
+ requestRender: false
13151
+ });
13152
+ toUnLabel = curLabelledIds.filter(function (id) { return labelledIds.indexOf(id) === -1; });
13153
+ params.manager.VisualsRegister.SetLabelled({
13154
+ labelled: false,
13155
+ entityIds: toUnLabel
13082
13156
  });
13083
13157
  }
13084
13158
  params.manager.VisualsRegister.ClearOpacity();
@@ -13119,16 +13193,20 @@
13119
13193
  tiles: imagery,
13120
13194
  viewer: params.manager.Viewer,
13121
13195
  });
13122
- renderedRelationEntityIds = bSettings === null || bSettings === void 0 ? void 0 : bSettings.renderedEntityRelations;
13123
- if (!renderedRelationEntityIds) {
13124
- renderedRelationEntityIds = [];
13196
+ legacyRelationIds = bSettings === null || bSettings === void 0 ? void 0 : bSettings.renderedEntityRelations;
13197
+ if (!legacyRelationIds) {
13198
+ legacyRelationIds = [];
13199
+ }
13200
+ relations = bSettings === null || bSettings === void 0 ? void 0 : bSettings.renderedRelations;
13201
+ if (!relations) {
13202
+ relations = [];
13125
13203
  }
13126
13204
  curEnabled = params.manager.GetEnabledItemIds();
13127
13205
  newItemIds = (_5 = bSettings === null || bSettings === void 0 ? void 0 : bSettings.menuItemIds) !== null && _5 !== void 0 ? _5 : [];
13128
13206
  for (_i = 0, curEnabled_1 = curEnabled; _i < curEnabled_1.length; _i++) {
13129
13207
  id = curEnabled_1[_i];
13130
- if (newItemIds.indexOf(id) === -1 ||
13131
- (id == RELATION_MENU_ITEM_ID && !renderedRelationEntityIds.length)) {
13208
+ if ((newItemIds.indexOf(id) === -1 && id != RELATION_MENU_ITEM_ID) ||
13209
+ (id == RELATION_MENU_ITEM_ID && !legacyRelationIds.length && !relations.length)) {
13132
13210
  params.manager.RemoveItemById({
13133
13211
  menuItemId: id
13134
13212
  });
@@ -13148,26 +13226,24 @@
13148
13226
  }
13149
13227
  _7.label = 4;
13150
13228
  case 4:
13151
- if (!renderedRelationEntityIds.length) return [3 /*break*/, 6];
13152
- menuItem = {
13153
- id: RELATION_MENU_ITEM_ID,
13154
- Caption: "Entity relations",
13155
- BruceEntity: {
13156
- EntityIds: renderedRelationEntityIds
13157
- },
13158
- Type: bruceModels.MenuItem.EType.Relations
13159
- };
13160
- return [4 /*yield*/, params.manager.RenderItem({
13229
+ if (legacyRelationIds.length || relations.length) {
13230
+ menuItem = {
13231
+ id: RELATION_MENU_ITEM_ID,
13232
+ Caption: "Entity relations",
13233
+ BruceEntity: {
13234
+ EntityIds: legacyRelationIds
13235
+ },
13236
+ relations: relations,
13237
+ Type: bruceModels.MenuItem.EType.Relations
13238
+ };
13239
+ params.manager.RenderItem({
13161
13240
  getters: params.getters,
13162
13241
  item: menuItem
13163
- })];
13164
- case 5:
13165
- _7.sent();
13166
- if (!assertIteration$1(params.viewer, iteration)) {
13167
- return [2 /*return*/];
13242
+ });
13243
+ if (!assertIteration$1(params.viewer, iteration)) {
13244
+ return [2 /*return*/];
13245
+ }
13168
13246
  }
13169
- _7.label = 6;
13170
- case 6:
13171
13247
  gOcclusion = bSettings === null || bSettings === void 0 ? void 0 : bSettings.groundOcclusion;
13172
13248
  if (gOcclusion == null) {
13173
13249
  gOcclusion = (_6 = defaults === null || defaults === void 0 ? void 0 : defaults.settings) === null || _6 === void 0 ? void 0 : _6.groundOcclusion;
@@ -15920,9 +15996,13 @@
15920
15996
  // We check in case something else is also requesting renders.
15921
15997
  var lastRenderTime = viewer.scene.lastRenderTime;
15922
15998
  if (!lastRenderTime || Cesium.JulianDate.secondsDifference(Cesium.JulianDate.now(), lastRenderTime) > 3) {
15923
- viewer.scene.requestRender();
15999
+ // Check if window is active/in focus.
16000
+ // TODO: Should render the moment it is in focus as well.
16001
+ if (document.hasFocus()) {
16002
+ viewer.scene.requestRender();
16003
+ }
15924
16004
  }
15925
- }, 3500);
16005
+ }, 1500);
15926
16006
  }
15927
16007
  (function (ViewerUtils) {
15928
16008
  /**
@@ -16075,7 +16155,7 @@
16075
16155
  ViewerUtils.CreateWidgets = CreateWidgets;
16076
16156
  })(exports.ViewerUtils || (exports.ViewerUtils = {}));
16077
16157
 
16078
- var VERSION$1 = "2.8.7";
16158
+ var VERSION$1 = "2.8.9";
16079
16159
 
16080
16160
  exports.VERSION = VERSION$1;
16081
16161
  exports.CesiumViewMonitor = CesiumViewMonitor;