bruce-cesium 2.8.2 → 2.8.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.
@@ -1739,7 +1739,7 @@
1739
1739
  type: type,
1740
1740
  defaultToId: false
1741
1741
  });
1742
- return [2 /*return*/, name_1 ? name_1 : "Unnamed entity"];
1742
+ return [2 /*return*/, name_1 ? name_1 : "Unnamed Entity"];
1743
1743
  }
1744
1744
  return [3 /*break*/, 4];
1745
1745
  case 3:
@@ -1842,6 +1842,7 @@
1842
1842
  return zoomItem.MinZoom + "-" + zoomItem.MaxZoom + "-" + shouldApplyFlatFix(terrain);
1843
1843
  }
1844
1844
  var _fileValidationCache = {};
1845
+ var _fileHeightCache = {};
1845
1846
  /**
1846
1847
  * @param min
1847
1848
  * @param max
@@ -2195,7 +2196,7 @@
2195
2196
  (function (Point) {
2196
2197
  function Render(params) {
2197
2198
  return __awaiter(this, void 0, void 0, function () {
2198
- var entity, style, type, cEntity, siblings, iconUrlRows, icon, iconUrl, res, e_4, iconScale, disableDepthTest, heightRef, radius, bFill, cFill, outline, cOutline, outlineWidth, bOutline, heightRef, pos3d, extrusion, outlineExtrusion, bColor, cColor, size, heightRef;
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;
2199
2200
  return __generator(this, function (_a) {
2200
2201
  switch (_a.label) {
2201
2202
  case 0:
@@ -2210,7 +2211,7 @@
2210
2211
  }
2211
2212
  cEntity = null;
2212
2213
  siblings = [];
2213
- if (!(type == bruceModels.Style.EPointType.Icon)) return [3 /*break*/, 7];
2214
+ if (!(type == bruceModels.Style.EPointType.Icon)) return [3 /*break*/, 12];
2214
2215
  iconUrlRows = style.iconUrl == null ? [] : style.iconUrl;
2215
2216
  iconUrlRows.forEach(function (row) {
2216
2217
  if (row.type == bruceModels.Calculator.EValueType.Color) {
@@ -2218,41 +2219,66 @@
2218
2219
  }
2219
2220
  });
2220
2221
  icon = bruceModels.Calculator.GetString(iconUrlRows, entity, params.tags);
2221
- iconUrl = null;
2222
+ iconUrl_1 = null;
2222
2223
  if (typeof icon == "string") {
2223
- iconUrl = icon;
2224
+ iconUrl_1 = icon;
2224
2225
  }
2225
- if (!iconUrl && style.iconId) {
2226
- iconUrl = bruceModels.ClientFile.GetUrl({
2226
+ if (!iconUrl_1 && style.iconId) {
2227
+ iconUrl_1 = bruceModels.ClientFile.GetUrl({
2227
2228
  api: params.api,
2228
2229
  fileId: style.iconId
2229
2230
  });
2230
2231
  }
2231
- if (!iconUrl) return [3 /*break*/, 6];
2232
+ if (!iconUrl_1) return [3 /*break*/, 11];
2232
2233
  _a.label = 1;
2233
2234
  case 1:
2234
- _a.trys.push([1, 5, , 6]);
2235
- if (!(_fileValidationCache[iconUrl] == null)) return [3 /*break*/, 3];
2236
- return [4 /*yield*/, fetch(iconUrl)];
2235
+ _a.trys.push([1, 10, , 11]);
2236
+ if (!(_fileValidationCache[iconUrl_1] == null)) return [3 /*break*/, 8];
2237
+ return [4 /*yield*/, fetch(iconUrl_1)];
2237
2238
  case 2:
2238
2239
  res = _a.sent();
2239
- if (res.status != 200) {
2240
- iconUrl = null;
2241
- }
2242
- _fileValidationCache[iconUrl] = Boolean(iconUrl);
2243
- return [3 /*break*/, 4];
2240
+ if (!(res.status != 200)) return [3 /*break*/, 3];
2241
+ iconUrl_1 = null;
2242
+ return [3 /*break*/, 7];
2244
2243
  case 3:
2245
- if (!_fileValidationCache[iconUrl]) {
2246
- iconUrl = null;
2247
- }
2248
- _a.label = 4;
2249
- case 4: return [3 /*break*/, 6];
2244
+ _a.trys.push([3, 6, , 7]);
2245
+ return [4 /*yield*/, res.blob()];
2246
+ case 4:
2247
+ blob_1 = _a.sent();
2248
+ return [4 /*yield*/, new Promise(function (res) {
2249
+ var img = new Image();
2250
+ img.onload = function () {
2251
+ _fileHeightCache[iconUrl_1] = img.height;
2252
+ res(null);
2253
+ };
2254
+ img.onerror = function () {
2255
+ _fileHeightCache[iconUrl_1] = undefined;
2256
+ res(null);
2257
+ };
2258
+ img.src = URL.createObjectURL(blob_1);
2259
+ })];
2250
2260
  case 5:
2251
- e_4 = _a.sent();
2252
- iconUrl = null;
2253
- return [3 /*break*/, 6];
2261
+ _a.sent();
2262
+ return [3 /*break*/, 7];
2254
2263
  case 6:
2255
- if (iconUrl) {
2264
+ e_4 = _a.sent();
2265
+ console.error(e_4);
2266
+ return [3 /*break*/, 7];
2267
+ case 7:
2268
+ _fileValidationCache[iconUrl_1] = Boolean(iconUrl_1);
2269
+ return [3 /*break*/, 9];
2270
+ case 8:
2271
+ if (!_fileValidationCache[iconUrl_1]) {
2272
+ iconUrl_1 = null;
2273
+ }
2274
+ _a.label = 9;
2275
+ case 9: return [3 /*break*/, 11];
2276
+ case 10:
2277
+ e_5 = _a.sent();
2278
+ iconUrl_1 = null;
2279
+ return [3 /*break*/, 11];
2280
+ case 11:
2281
+ if (iconUrl_1) {
2256
2282
  iconScale = EnsureNumber(bruceModels.Calculator.GetNumber(style.iconScale, entity, params.tags));
2257
2283
  if (!iconScale && iconScale != 0) {
2258
2284
  iconScale = 1;
@@ -2264,11 +2290,12 @@
2264
2290
  billboard: {
2265
2291
  horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
2266
2292
  verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
2267
- image: iconUrl,
2293
+ image: iconUrl_1,
2268
2294
  heightReference: getHeightRef(style),
2269
2295
  scale: iconScale,
2270
2296
  disableDepthTestDistance: disableDepthTest ? Number.POSITIVE_INFINITY : undefined,
2271
2297
  distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance),
2298
+ height: _fileHeightCache[iconUrl_1]
2272
2299
  // Would be great once we have a setting for this.
2273
2300
  // translucencyByDistance: getTranslucencyByDistance(params.minDistance, params.maxDistance),
2274
2301
  },
@@ -2282,8 +2309,8 @@
2282
2309
  });
2283
2310
  }
2284
2311
  }
2285
- _a.label = 7;
2286
- case 7:
2312
+ _a.label = 12;
2313
+ case 12:
2287
2314
  if (type == bruceModels.Style.EPointType.Cylinder) {
2288
2315
  radius = EnsureNumber(bruceModels.Calculator.GetNumber(style.CylinderRadius, entity, params.tags));
2289
2316
  if (radius <= 0) {
@@ -3686,6 +3713,366 @@
3686
3713
  })(Parabola = RelationRenderEngine.Parabola || (RelationRenderEngine.Parabola = {}));
3687
3714
  })(RelationRenderEngine || (RelationRenderEngine = {}));
3688
3715
 
3716
+ /**
3717
+ * Returns cesium property's value.
3718
+ * This will check if it's one that changes over time, or just a fixed value.
3719
+ * Eg: const pos3d = getValue<Cesium.Cartesian3>(cViewer, cEntity.point.position);
3720
+ * @param viewer
3721
+ * @param obj
3722
+ */
3723
+ function getValue$1(viewer, obj) {
3724
+ if (obj === null || obj === void 0 ? void 0 : obj.getValue) {
3725
+ return obj.getValue(viewer.scene.lastRenderTime);
3726
+ }
3727
+ return obj;
3728
+ }
3729
+ (function (EntityLabel) {
3730
+ // Key where the label instance is stored within the cesium entity.
3731
+ // Eg: rego[ATTACH_KEY] = new EntityLabel(...);
3732
+ EntityLabel.ATTACH_KEY = "nextspace-navigator-entity-label";
3733
+ var Label = /** @class */ (function () {
3734
+ function Label(params) {
3735
+ var _this = this;
3736
+ // The label element itself.
3737
+ this.label = null;
3738
+ // Callback to kill render listener.
3739
+ this.renderRemoval = null;
3740
+ // Indicates the label was disposed and any actions will be ignored.
3741
+ this.disposed = false;
3742
+ this.creating = false;
3743
+ // Calculated pos3d for the label.
3744
+ // Override to make it draw at a different position.
3745
+ this.pos3d = null;
3746
+ this.rego = params.rego;
3747
+ this.viewer = params.viewer;
3748
+ this.api = params.api;
3749
+ this.visualRegister = params.visualRegister;
3750
+ this.creating = true;
3751
+ this.createCLabel(params.pos3d).then(function () {
3752
+ _this.creating = false;
3753
+ }).catch(function (e) {
3754
+ console.error("Failed to create label", e);
3755
+ _this.creating = false;
3756
+ });
3757
+ }
3758
+ Object.defineProperty(Label.prototype, "Rego", {
3759
+ get: function () {
3760
+ return this.rego;
3761
+ },
3762
+ enumerable: false,
3763
+ configurable: true
3764
+ });
3765
+ Object.defineProperty(Label.prototype, "Disposed", {
3766
+ get: function () {
3767
+ return this.disposed;
3768
+ },
3769
+ enumerable: false,
3770
+ configurable: true
3771
+ });
3772
+ Object.defineProperty(Label.prototype, "Creating", {
3773
+ get: function () {
3774
+ return this.creating;
3775
+ },
3776
+ enumerable: false,
3777
+ configurable: true
3778
+ });
3779
+ /**
3780
+ * Disposes label and marks instance as disposed.
3781
+ * Recalling will be ignored.
3782
+ */
3783
+ Label.prototype.Dispose = function () {
3784
+ if (this.disposed) {
3785
+ return;
3786
+ }
3787
+ this.disposed = true;
3788
+ if (this.label &&
3789
+ this.label.parentElement) {
3790
+ this.label.parentElement.removeChild(this.label);
3791
+ this.label = null;
3792
+ }
3793
+ if (this.renderRemoval) {
3794
+ this.renderRemoval();
3795
+ this.renderRemoval = null;
3796
+ }
3797
+ };
3798
+ /**
3799
+ * Creates cesium entity for the label if one does not exist.
3800
+ * @param pos23 optional position to create label at.
3801
+ */
3802
+ Label.prototype.createCLabel = function (pos3d) {
3803
+ var _a, _b, _c, _d, _e, _f;
3804
+ return __awaiter(this, void 0, void 0, function () {
3805
+ var heightRef, heightOffset, pixelOffset, visual, isClamped, height, scale, featureAny, propertyNames, latProp, lonProp, lat, lon, latIsRad, lonIsRad, latIsDeg, lonIsDeg, carto, text, ele, _lastDistance, _lastCameraPos, getDistance, MAX_DISTANCE, updateLabel;
3806
+ var _this = this;
3807
+ return __generator(this, function (_g) {
3808
+ switch (_g.label) {
3809
+ case 0:
3810
+ if (this.label || this.disposed) {
3811
+ return [2 /*return*/];
3812
+ }
3813
+ heightRef = null;
3814
+ heightOffset = 10;
3815
+ pixelOffset = new Cesium.Cartesian2(0, 0);
3816
+ if (!isNaN(pos3d === null || pos3d === void 0 ? void 0 : pos3d.x)) return [3 /*break*/, 3];
3817
+ visual = (_a = this.rego) === null || _a === void 0 ? void 0 : _a.visual;
3818
+ if (visual && visual instanceof Cesium.Entity) {
3819
+ if (visual.polygon) {
3820
+ heightRef = getValue$1(this.viewer, visual.polygon.heightReference);
3821
+ }
3822
+ else if (visual.polyline) {
3823
+ isClamped = getValue$1(this.viewer, visual.polyline.clampToGround);
3824
+ heightRef = isClamped == false ? Cesium.HeightReference.NONE : Cesium.HeightReference.CLAMP_TO_GROUND;
3825
+ }
3826
+ else if (visual.model) {
3827
+ heightRef = getValue$1(this.viewer, visual.model.heightReference);
3828
+ }
3829
+ else if (visual.point) {
3830
+ heightRef = getValue$1(this.viewer, visual.point.heightReference);
3831
+ }
3832
+ else if (visual.billboard) {
3833
+ heightRef = getValue$1(this.viewer, visual.billboard.heightReference);
3834
+ height = getValue$1(this.viewer, visual.billboard.height);
3835
+ if (height) {
3836
+ scale = EnsureNumber(getValue$1(this.viewer, visual.billboard.scale), 1);
3837
+ pixelOffset.y = -(height * scale);
3838
+ }
3839
+ // Flat padding.
3840
+ pixelOffset.y -= 5;
3841
+ heightOffset = 0;
3842
+ }
3843
+ else if (visual.corridor) {
3844
+ heightRef = getValue$1(this.viewer, visual.corridor.heightReference);
3845
+ }
3846
+ else if (visual.ellipse) {
3847
+ heightRef = getValue$1(this.viewer, visual.ellipse.heightReference);
3848
+ }
3849
+ pos3d = getValue$1(this.viewer, visual.position);
3850
+ }
3851
+ else if (visual instanceof Cesium.Cesium3DTileFeature) {
3852
+ featureAny = visual;
3853
+ propertyNames = featureAny.getPropertyNames ? featureAny.getPropertyNames() : (_b = featureAny.getPropertyIds) === null || _b === void 0 ? void 0 : _b.call(featureAny);
3854
+ if (propertyNames === null || propertyNames === void 0 ? void 0 : propertyNames.length) {
3855
+ latProp = propertyNames.find(function (x) { return x.toLowerCase().includes("lat"); });
3856
+ lonProp = propertyNames.find(function (x) { return x.toLowerCase().includes("lon"); });
3857
+ lat = latProp ? featureAny.getProperty(latProp) : null;
3858
+ lon = lonProp ? featureAny.getProperty(lonProp) : null;
3859
+ if (lat && lon) {
3860
+ latIsRad = typeof lat == "number" && lat > -Math.PI && lat < Math.PI;
3861
+ lonIsRad = typeof lon == "number" && lon > -Math.PI && lon < Math.PI;
3862
+ latIsDeg = typeof lat == "number" && lat > -180 && lat < 180;
3863
+ lonIsDeg = typeof lon == "number" && lon > -180 && lon < 180;
3864
+ if (latIsRad && lonIsRad) {
3865
+ pos3d = Cesium.Cartographic.toCartesian(Cesium.Cartographic.fromRadians(lon, lat, 0));
3866
+ }
3867
+ else if (latIsDeg && lonIsDeg) {
3868
+ pos3d = Cesium.Cartographic.toCartesian(Cesium.Cartographic.fromDegrees(lon, lat, 0));
3869
+ }
3870
+ heightRef = Cesium.HeightReference.CLAMP_TO_GROUND;
3871
+ }
3872
+ }
3873
+ }
3874
+ if (!isNaN(pos3d === null || pos3d === void 0 ? void 0 : pos3d.x)) return [3 /*break*/, 2];
3875
+ return [4 /*yield*/, exports.EntityUtils.GetPosAsync({
3876
+ viewer: this.viewer,
3877
+ api: this.api,
3878
+ entityId: (_c = this.rego) === null || _c === void 0 ? void 0 : _c.entityId,
3879
+ returnHeightRef: Cesium.HeightReference.NONE,
3880
+ tilesetId: (_d = this.rego) === null || _d === void 0 ? void 0 : _d.tilesetId,
3881
+ visualRegister: this.visualRegister
3882
+ })];
3883
+ case 1:
3884
+ pos3d = _g.sent();
3885
+ heightRef = Cesium.HeightReference.NONE;
3886
+ _g.label = 2;
3887
+ case 2: return [3 /*break*/, 4];
3888
+ case 3:
3889
+ heightRef = Cesium.HeightReference.NONE;
3890
+ // Flat padding.
3891
+ heightOffset = 0;
3892
+ pixelOffset.y = -15;
3893
+ _g.label = 4;
3894
+ case 4:
3895
+ if (isNaN(pos3d === null || pos3d === void 0 ? void 0 : pos3d.x)) {
3896
+ return [2 /*return*/];
3897
+ }
3898
+ pos3d = exports.DrawingUtils.EnsurePosHeight({
3899
+ desiredHeightRef: Cesium.HeightReference.NONE,
3900
+ heightRef: heightRef,
3901
+ pos3d: pos3d,
3902
+ viewer: this.viewer
3903
+ });
3904
+ if (isNaN(pos3d === null || pos3d === void 0 ? void 0 : pos3d.x)) {
3905
+ return [2 /*return*/];
3906
+ }
3907
+ if (heightOffset) {
3908
+ carto = Cesium.Cartographic.fromCartesian(pos3d);
3909
+ // TODO: Check if we need to use heightRef and adjust to absolute height.
3910
+ // TODO: We should be smarter and not just add 10m to the height. Eg: use polygon extrusion.
3911
+ carto.height += heightOffset;
3912
+ pos3d = Cesium.Cartographic.toCartesian(carto);
3913
+ }
3914
+ this.pos3d = pos3d;
3915
+ text = (_f = (_e = this.rego) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : "Unnamed Entity";
3916
+ ele = document.createElement("div");
3917
+ ele.innerHTML = text;
3918
+ ele.setAttribute("style", "\n position: absolute;\n z-index: 1;\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 }");
3919
+ this.label = ele;
3920
+ this.viewer.container.appendChild(ele);
3921
+ _lastDistance = null;
3922
+ _lastCameraPos = null;
3923
+ getDistance = function () {
3924
+ var _a;
3925
+ if (_this.disposed) {
3926
+ return null;
3927
+ }
3928
+ var cameraPos = (_a = _this.viewer.camera) === null || _a === void 0 ? void 0 : _a.position;
3929
+ if (isNaN(cameraPos === null || cameraPos === void 0 ? void 0 : cameraPos.x)) {
3930
+ return null;
3931
+ }
3932
+ // If camera hasn't moved much then we can use the last distance.
3933
+ var TOLERANCE = 0.1;
3934
+ if (_lastCameraPos) {
3935
+ var totalMovement = Math.abs(_lastCameraPos.x - cameraPos.x) +
3936
+ Math.abs(_lastCameraPos.y - cameraPos.y) +
3937
+ Math.abs(_lastCameraPos.z - cameraPos.z);
3938
+ if (totalMovement < TOLERANCE) {
3939
+ return _lastDistance;
3940
+ }
3941
+ }
3942
+ // Check if there is a raycast collision between camera and pos3d.
3943
+ // We'll let the labels draw through a ground collision.
3944
+ // Commented out while it is WIP.
3945
+ // const direction = Cesium.Cartesian3.subtract(pos3d, cameraPos, new Cesium.Cartesian3());
3946
+ // const ray = new Cesium.Ray(pos3d.clone(), direction);
3947
+ // const objects = (this.viewer.scene as any).drillPickFromRay(ray, 1, [visuals]);
3948
+ // if (objects && objects.length > 0) {
3949
+ // for (let i = 0; i < objects.length; ++i) {
3950
+ // const obj = objects[i];
3951
+ // if (!visuals.find(x => x == obj?.id)) {
3952
+ // let isGround = true;
3953
+ // if (obj.object) {
3954
+ // const url = obj.object?.primitive?._basePath;
3955
+ // if (url && typeof url == "string") {
3956
+ // isGround = url.includes("tile.googleapis.com");
3957
+ // }
3958
+ // else {
3959
+ // isGround = false;
3960
+ // }
3961
+ // }
3962
+ // if (!isGround) {
3963
+ // return null;
3964
+ // }
3965
+ // }
3966
+ // }
3967
+ // }
3968
+ var distance = Cesium.Cartesian3.distance(cameraPos, _this.pos3d);
3969
+ _lastDistance = distance;
3970
+ _lastCameraPos = cameraPos.clone();
3971
+ return distance;
3972
+ };
3973
+ MAX_DISTANCE = 5000;
3974
+ updateLabel = function () {
3975
+ var _a;
3976
+ if (_this.disposed || isNaN((_a = _this.pos3d) === null || _a === void 0 ? void 0 : _a.x)) {
3977
+ return;
3978
+ }
3979
+ var distance = getDistance();
3980
+ if (isNaN(distance) || distance >= MAX_DISTANCE) {
3981
+ ele.style.display = "none";
3982
+ return;
3983
+ }
3984
+ var pos2d = Cesium.SceneTransforms.wgs84ToWindowCoordinates(_this.viewer.scene, _this.pos3d);
3985
+ if (isNaN(pos2d === null || pos2d === void 0 ? void 0 : pos2d.x)) {
3986
+ ele.style.display = "none";
3987
+ return;
3988
+ }
3989
+ // If out of the screen then we can hide it.
3990
+ if (pos2d.x < 0 || pos2d.x > _this.viewer.canvas.clientWidth ||
3991
+ pos2d.y < 0 || pos2d.y > _this.viewer.canvas.clientHeight) {
3992
+ ele.style.display = "none";
3993
+ return;
3994
+ }
3995
+ ele.style.display = "block";
3996
+ // Check scale to apply based on distance between camera and pos3d.
3997
+ // We'll make the label smaller and less transparent when further away.
3998
+ var scale = 1 - (distance / MAX_DISTANCE);
3999
+ if (scale && scale > 0.15) {
4000
+ ele.style.transform = "scale(".concat(scale, ")");
4001
+ ele.style.opacity = "".concat(scale);
4002
+ var left = pos2d.x - (ele.clientWidth / 2) + pixelOffset.x;
4003
+ ele.style.left = "".concat(left, "px");
4004
+ var top_1 = pos2d.y - ele.clientHeight + (pixelOffset.y * scale);
4005
+ ele.style.top = "".concat(top_1, "px");
4006
+ }
4007
+ else {
4008
+ ele.style.transform = "";
4009
+ ele.style.opacity = "0";
4010
+ }
4011
+ };
4012
+ this.renderRemoval = this.viewer.scene.postUpdate.addEventListener(updateLabel);
4013
+ updateLabel();
4014
+ return [2 /*return*/];
4015
+ }
4016
+ });
4017
+ });
4018
+ };
4019
+ return Label;
4020
+ }());
4021
+ EntityLabel.Label = Label;
4022
+ /**
4023
+ * Creates an entity label for a given rego.
4024
+ * If one exists then the action is ignored.
4025
+ */
4026
+ function Attach(params) {
4027
+ var rego = params.rego, viewer = params.viewer, pos3d = params.pos3d, visualRegister = params.visualRegister, api = params.api;
4028
+ if (!rego || !viewer || rego[EntityLabel.ATTACH_KEY]) {
4029
+ return;
4030
+ }
4031
+ rego[EntityLabel.ATTACH_KEY] = new Label({
4032
+ rego: rego,
4033
+ viewer: viewer,
4034
+ pos3d: pos3d,
4035
+ visualRegister: visualRegister,
4036
+ api: api
4037
+ });
4038
+ return rego[EntityLabel.ATTACH_KEY];
4039
+ }
4040
+ EntityLabel.Attach = Attach;
4041
+ /**
4042
+ * Removes an entity label from a given rego.
4043
+ * If one doesn't exist then the action is ignored.
4044
+ */
4045
+ function Detatch(params) {
4046
+ var _a, _b, _c;
4047
+ var rego = params.rego, label = params.label;
4048
+ if (!rego && label) {
4049
+ rego = label.Rego;
4050
+ }
4051
+ if (!rego || !rego[EntityLabel.ATTACH_KEY]) {
4052
+ if (label) {
4053
+ (_a = label.Dispose) === null || _a === void 0 ? void 0 : _a.call(label);
4054
+ }
4055
+ return;
4056
+ }
4057
+ (_c = (_b = rego[EntityLabel.ATTACH_KEY]).Dispose) === null || _c === void 0 ? void 0 : _c.call(_b);
4058
+ rego[EntityLabel.ATTACH_KEY] = null;
4059
+ }
4060
+ EntityLabel.Detatch = Detatch;
4061
+ /**
4062
+ * Returns label instance from given rego if one exists.
4063
+ * @param params
4064
+ * @returns
4065
+ */
4066
+ function GetLabel(params) {
4067
+ var rego = params.rego;
4068
+ if (!rego) {
4069
+ return null;
4070
+ }
4071
+ return rego[EntityLabel.ATTACH_KEY];
4072
+ }
4073
+ EntityLabel.GetLabel = GetLabel;
4074
+ })(exports.EntityLabel || (exports.EntityLabel = {}));
4075
+
3689
4076
  /**
3690
4077
  * Returns if a given visual is alive and in the scene.
3691
4078
  * @param viewer
@@ -3814,7 +4201,26 @@
3814
4201
  for (var i = 0; i < regos.length; i++) {
3815
4202
  var rego = regos[i];
3816
4203
  rego.best = rego === highestPriority;
3817
- updateEntityShow(viewer, rego.visual, rego.suppressShow ? false : getShowState(rego));
4204
+ var visible = rego.suppressShow ? false : getShowState(rego);
4205
+ updateEntityShow(viewer, rego.visual, visible);
4206
+ if (rego.best) {
4207
+ var isLabelled = register.GetIsLabelled({
4208
+ entityId: entityId
4209
+ });
4210
+ if (isLabelled && visible) {
4211
+ exports.EntityLabel.Attach({
4212
+ rego: rego,
4213
+ viewer: viewer,
4214
+ api: register.ApiGetters.GetBruceApi(),
4215
+ visualRegister: register
4216
+ });
4217
+ }
4218
+ else {
4219
+ exports.EntityLabel.Detatch({
4220
+ rego: rego
4221
+ });
4222
+ }
4223
+ }
3818
4224
  }
3819
4225
  }
3820
4226
  function markEntity(register, rego, visual, ignoreParent) {
@@ -3982,7 +4388,7 @@
3982
4388
  EVisualUpdateType["DeselectAll"] = "DESELECT_ALL";
3983
4389
  })(EVisualUpdateType = VisualsRegister.EVisualUpdateType || (VisualsRegister.EVisualUpdateType = {}));
3984
4390
  var Register = /** @class */ (function () {
3985
- function Register(viewer) {
4391
+ function Register(params) {
3986
4392
  this.id = bruceModels.ObjectUtils.UId();
3987
4393
  this.rego = {};
3988
4394
  this.onUpdate = null;
@@ -3991,7 +4397,12 @@
3991
4397
  this.hiddenIds = [];
3992
4398
  // Entity id -> opacity for visual.
3993
4399
  this.opacity = {};
3994
- this.viewer = viewer;
4400
+ // Array of entity ids for entities who have labels drawn for them.
4401
+ // It will be drawn on the "best" visual, and only while the entity is visible.
4402
+ // Warning: this sucks for CAD entities.
4403
+ this.labelledEntityIds = [];
4404
+ this.viewer = params.viewer;
4405
+ this.apiGetters = params.apiGetters;
3995
4406
  }
3996
4407
  Object.defineProperty(Register.prototype, "Id", {
3997
4408
  get: function () {
@@ -4007,6 +4418,13 @@
4007
4418
  enumerable: false,
4008
4419
  configurable: true
4009
4420
  });
4421
+ Object.defineProperty(Register.prototype, "ApiGetters", {
4422
+ get: function () {
4423
+ return this.apiGetters;
4424
+ },
4425
+ enumerable: false,
4426
+ configurable: true
4427
+ });
4010
4428
  Object.defineProperty(Register.prototype, "OnUpdate", {
4011
4429
  get: function () {
4012
4430
  if (!this.onUpdate) {
@@ -4029,6 +4447,71 @@
4029
4447
  }
4030
4448
  this.viewer.scene.requestRender();
4031
4449
  };
4450
+ /**
4451
+ * Marks given entityIds as either labelled or not labelled.
4452
+ * When an entity is labelled a label will be drawn on the "best" visual for it.
4453
+ * @param params
4454
+ */
4455
+ Register.prototype.SetLabelled = function (params) {
4456
+ var labelled = params.labelled, entityIds = params.entityIds, requestRender = params.requestRender;
4457
+ var _loop_3 = function (i) {
4458
+ var id = entityIds[i];
4459
+ var index = this_1.labelledEntityIds.findIndex(function (x) { return x == id; });
4460
+ if (labelled) {
4461
+ if (index <= -1) {
4462
+ this_1.labelledEntityIds.push(id);
4463
+ updateEntity(this_1.viewer, id, this_1);
4464
+ }
4465
+ }
4466
+ else {
4467
+ if (index > -1) {
4468
+ this_1.labelledEntityIds.splice(index, 1);
4469
+ updateEntity(this_1.viewer, id, this_1);
4470
+ }
4471
+ }
4472
+ };
4473
+ var this_1 = this;
4474
+ for (var i = 0; i < entityIds.length; i++) {
4475
+ _loop_3(i);
4476
+ }
4477
+ if (requestRender != false) {
4478
+ this.viewer.scene.requestRender();
4479
+ }
4480
+ };
4481
+ /**
4482
+ * Returns if given entity id is labelled.
4483
+ * @param params
4484
+ */
4485
+ Register.prototype.GetIsLabelled = function (params) {
4486
+ var id = params.entityId;
4487
+ return this.labelledEntityIds.indexOf(id) !== -1;
4488
+ };
4489
+ /**
4490
+ * Clears all labelled entities.
4491
+ * @param params
4492
+ */
4493
+ Register.prototype.ClearLabelled = function (params) {
4494
+ var ids = [].concat(this.labelledEntityIds);
4495
+ this.labelledEntityIds = [];
4496
+ for (var i = 0; i < ids.length; i++) {
4497
+ var id = ids[i];
4498
+ updateEntity(this.viewer, id, this);
4499
+ }
4500
+ if ((params === null || params === void 0 ? void 0 : params.requestRender) != false) {
4501
+ this.viewer.scene.requestRender();
4502
+ }
4503
+ };
4504
+ /**
4505
+ * Returns all labelled entity ids.
4506
+ */
4507
+ Register.prototype.GetLabelled = function () {
4508
+ return this.labelledEntityIds;
4509
+ };
4510
+ /**
4511
+ * Updates the selection color.
4512
+ * This will not update the selection color for already selected entities.
4513
+ * @param color
4514
+ */
4032
4515
  Register.prototype.SetSelectionColor = function (color) {
4033
4516
  this.selectionColor = color;
4034
4517
  };
@@ -4354,26 +4837,26 @@
4354
4837
  return;
4355
4838
  }
4356
4839
  var menuItems = menuItemId ? [menuItemId] : entityRegos.map(function (x) { return x.menuItemId; });
4357
- var _loop_3 = function (i) {
4840
+ var _loop_4 = function (i) {
4358
4841
  var menuItemId_2 = menuItems[i];
4359
4842
  var rego = entityRegos.find(function (r) { return r.menuItemId === menuItemId_2; });
4360
4843
  if (!rego) {
4361
4844
  return { value: void 0 };
4362
4845
  }
4363
- removeEntity(this_1.viewer, rego.visual);
4364
- (_b = this_1.onUpdate) === null || _b === void 0 ? void 0 : _b.Trigger({
4846
+ removeEntity(this_2.viewer, rego.visual);
4847
+ (_b = this_2.onUpdate) === null || _b === void 0 ? void 0 : _b.Trigger({
4365
4848
  type: EVisualUpdateType.Remove,
4366
4849
  entityId: rego.entityId,
4367
4850
  rego: rego
4368
4851
  });
4369
- this_1.rego[entityId] = entityRegos.filter(function (r) { return r.menuItemId !== menuItemId_2; });
4852
+ this_2.rego[entityId] = entityRegos.filter(function (r) { return r.menuItemId !== menuItemId_2; });
4370
4853
  if (doUpdate && menuItemId_2) {
4371
- updateEntity(this_1.viewer, entityId, this_1);
4854
+ updateEntity(this_2.viewer, entityId, this_2);
4372
4855
  }
4373
4856
  };
4374
- var this_1 = this;
4857
+ var this_2 = this;
4375
4858
  for (var i = 0; i < menuItems.length; i++) {
4376
- var state_1 = _loop_3(i);
4859
+ var state_1 = _loop_4(i);
4377
4860
  if (typeof state_1 === "object")
4378
4861
  return state_1.value;
4379
4862
  }
@@ -9500,15 +9983,29 @@
9500
9983
  function Manager(params) {
9501
9984
  this.items = [];
9502
9985
  this.onUpdate = null;
9503
- var viewer = params.viewer, visualsRegister = params.visualsRegister;
9986
+ var viewer = params.viewer, visualsRegister = params.visualsRegister, getters = params.getters;
9504
9987
  this.viewer = viewer;
9988
+ if (!getters) {
9989
+ getters = bruceModels.ENVIRONMENT.Api();
9990
+ }
9991
+ this.getters = getters;
9505
9992
  if (!visualsRegister) {
9506
- visualsRegister = new exports.VisualsRegister.Register(viewer);
9993
+ visualsRegister = new exports.VisualsRegister.Register({
9994
+ viewer: this.viewer,
9995
+ apiGetters: getters
9996
+ });
9507
9997
  }
9508
9998
  this.visualsRegister = visualsRegister;
9509
9999
  this.sharedGetters = new exports.SharedGetters.Cache();
9510
10000
  this.sharedMonitor = new CesiumViewMonitor(this.viewer);
9511
10001
  }
10002
+ Object.defineProperty(Manager.prototype, "Getters", {
10003
+ get: function () {
10004
+ return this.getters;
10005
+ },
10006
+ enumerable: false,
10007
+ configurable: true
10008
+ });
9512
10009
  Object.defineProperty(Manager.prototype, "Viewer", {
9513
10010
  get: function () {
9514
10011
  return this.viewer;
@@ -9551,11 +10048,15 @@
9551
10048
  if (this.viewer.isDestroyed()) {
9552
10049
  return null;
9553
10050
  }
10051
+ if (!params.getters) {
10052
+ params.getters = this.getters;
10053
+ }
10054
+ // Deprecated. Backwards compatibility.
9554
10055
  if (!params.getters) {
9555
10056
  params.getters = bruceModels.ENVIRONMENT.Api();
9556
10057
  }
9557
- if (params.apiGetter && !params.getters) {
9558
- console.warn("RenderItem(): Please pass getters instead of apiGetter. This is now deprecated due to needing access to other kinds of apis.");
10058
+ if (params.apiGetter && !this.getters) {
10059
+ console.warn("RenderItem(): Please pass getters within menu-item-manager constructor. 'getters' and 'apiGetter' within RenderItem are now deprecated.");
9559
10060
  }
9560
10061
  else if (!params.apiGetter) {
9561
10062
  params.apiGetter = params.getters.GetBruceGetter();
@@ -12214,11 +12715,11 @@
12214
12715
  * @param view
12215
12716
  */
12216
12717
  function renderNavigator(iteration, params, bookmark, view) {
12217
- 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;
12718
+ 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;
12218
12719
  return __awaiter(this, void 0, void 0, function () {
12219
- 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, entityOpacityMap, entityId, opacity, imagery, renderedRelationEntityIds, curEnabled, newItemIds, _i, curEnabled_1, id, menuItem, gOcclusion;
12220
- return __generator(this, function (_6) {
12221
- switch (_6.label) {
12720
+ 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;
12721
+ return __generator(this, function (_7) {
12722
+ switch (_7.label) {
12222
12723
  case 0:
12223
12724
  viewer = params.manager.Viewer;
12224
12725
  scene = viewer.scene;
@@ -12280,11 +12781,11 @@
12280
12781
  viewer: params.manager.Viewer,
12281
12782
  })];
12282
12783
  case 1:
12283
- _6.sent();
12784
+ _7.sent();
12284
12785
  if (!assertIteration$1(params.viewer, iteration)) {
12285
12786
  return [2 /*return*/];
12286
12787
  }
12287
- _6.label = 2;
12788
+ _7.label = 2;
12288
12789
  case 2:
12289
12790
  hillShades = (_o = bookmark === null || bookmark === void 0 ? void 0 : bookmark.Settings) === null || _o === void 0 ? void 0 : _o.hillShades;
12290
12791
  if (hillShades == null) {
@@ -12444,10 +12945,21 @@
12444
12945
  entityIds: isolatedIds
12445
12946
  });
12446
12947
  }
12948
+ params.manager.VisualsRegister.ClearLabelled();
12949
+ labelledIds = bSettings === null || bSettings === void 0 ? void 0 : bSettings.labelledEntityIds;
12950
+ if (labelledIds == null) {
12951
+ labelledIds = (_2 = defaults === null || defaults === void 0 ? void 0 : defaults.settings) === null || _2 === void 0 ? void 0 : _2.labelledEntityIds;
12952
+ }
12953
+ if (labelledIds != null) {
12954
+ params.manager.VisualsRegister.SetLabelled({
12955
+ labelled: true,
12956
+ entityIds: labelledIds
12957
+ });
12958
+ }
12447
12959
  params.manager.VisualsRegister.ClearOpacity();
12448
12960
  entityOpacityMap = bSettings === null || bSettings === void 0 ? void 0 : bSettings.entityOpacityMap;
12449
12961
  if (entityOpacityMap == null) {
12450
- entityOpacityMap = (_2 = defaults === null || defaults === void 0 ? void 0 : defaults.settings) === null || _2 === void 0 ? void 0 : _2.entityOpacityMap;
12962
+ entityOpacityMap = (_3 = defaults === null || defaults === void 0 ? void 0 : defaults.settings) === null || _3 === void 0 ? void 0 : _3.entityOpacityMap;
12451
12963
  }
12452
12964
  if (entityOpacityMap != null) {
12453
12965
  for (entityId in entityOpacityMap) {
@@ -12460,7 +12972,7 @@
12460
12972
  }
12461
12973
  }
12462
12974
  }
12463
- imagery = (bSettings === null || bSettings === void 0 ? void 0 : bSettings.imagery) != null ? bSettings.imagery : (_3 = defaults.settings) === null || _3 === void 0 ? void 0 : _3.imagery;
12975
+ imagery = (bSettings === null || bSettings === void 0 ? void 0 : bSettings.imagery) != null ? bSettings.imagery : (_4 = defaults.settings) === null || _4 === void 0 ? void 0 : _4.imagery;
12464
12976
  if (imagery == null) {
12465
12977
  // TODO: Need global default.
12466
12978
  imagery = [
@@ -12487,7 +12999,7 @@
12487
12999
  renderedRelationEntityIds = [];
12488
13000
  }
12489
13001
  curEnabled = params.manager.GetEnabledItemIds();
12490
- newItemIds = (_4 = bSettings === null || bSettings === void 0 ? void 0 : bSettings.menuItemIds) !== null && _4 !== void 0 ? _4 : [];
13002
+ newItemIds = (_5 = bSettings === null || bSettings === void 0 ? void 0 : bSettings.menuItemIds) !== null && _5 !== void 0 ? _5 : [];
12491
13003
  for (_i = 0, curEnabled_1 = curEnabled; _i < curEnabled_1.length; _i++) {
12492
13004
  id = curEnabled_1[_i];
12493
13005
  if (newItemIds.indexOf(id) === -1 ||
@@ -12505,11 +13017,11 @@
12505
13017
  bookmark: bookmark
12506
13018
  })];
12507
13019
  case 3:
12508
- _6.sent();
13020
+ _7.sent();
12509
13021
  if (!assertIteration$1(params.viewer, iteration)) {
12510
13022
  return [2 /*return*/];
12511
13023
  }
12512
- _6.label = 4;
13024
+ _7.label = 4;
12513
13025
  case 4:
12514
13026
  if (!renderedRelationEntityIds.length) return [3 /*break*/, 6];
12515
13027
  menuItem = {
@@ -12525,15 +13037,15 @@
12525
13037
  item: menuItem
12526
13038
  })];
12527
13039
  case 5:
12528
- _6.sent();
13040
+ _7.sent();
12529
13041
  if (!assertIteration$1(params.viewer, iteration)) {
12530
13042
  return [2 /*return*/];
12531
13043
  }
12532
- _6.label = 6;
13044
+ _7.label = 6;
12533
13045
  case 6:
12534
13046
  gOcclusion = bSettings === null || bSettings === void 0 ? void 0 : bSettings.groundOcclusion;
12535
13047
  if (gOcclusion == null) {
12536
- gOcclusion = (_5 = defaults === null || defaults === void 0 ? void 0 : defaults.settings) === null || _5 === void 0 ? void 0 : _5.groundOcclusion;
13048
+ gOcclusion = (_6 = defaults === null || defaults === void 0 ? void 0 : defaults.settings) === null || _6 === void 0 ? void 0 : _6.groundOcclusion;
12537
13049
  }
12538
13050
  if (gOcclusion == null) {
12539
13051
  // TODO: Need global default.
@@ -15146,7 +15658,7 @@
15146
15658
  defaultToId: false
15147
15659
  });
15148
15660
  if (!name_1) {
15149
- name_1 = "Unnamed entity";
15661
+ name_1 = "Unnamed Entity";
15150
15662
  }
15151
15663
  this._title.style.display = "block";
15152
15664
  this._flyTo.style.display = "flex";
@@ -15371,12 +15883,15 @@
15371
15883
  * @returns
15372
15884
  */
15373
15885
  function GetManager(params) {
15374
- var viewer = params.viewer, createIfMissing = params.createIfMissing;
15886
+ var viewer = params.viewer, createIfMissing = params.createIfMissing, getters = params.getters;
15375
15887
  if (viewer[CESIUM_VIEWER_MANAGER_KEY]) {
15376
15888
  return viewer[CESIUM_VIEWER_MANAGER_KEY];
15377
15889
  }
15378
15890
  else if (createIfMissing != false) {
15379
- var manager = new exports.MenuItemManager.Manager({ viewer: viewer });
15891
+ var manager = new exports.MenuItemManager.Manager({
15892
+ viewer: viewer,
15893
+ getters: getters
15894
+ });
15380
15895
  viewer[CESIUM_VIEWER_MANAGER_KEY] = manager;
15381
15896
  return manager;
15382
15897
  }
@@ -15435,7 +15950,7 @@
15435
15950
  ViewerUtils.CreateWidgets = CreateWidgets;
15436
15951
  })(exports.ViewerUtils || (exports.ViewerUtils = {}));
15437
15952
 
15438
- var VERSION$1 = "2.8.2";
15953
+ var VERSION$1 = "2.8.4";
15439
15954
 
15440
15955
  exports.VERSION = VERSION$1;
15441
15956
  exports.CesiumViewMonitor = CesiumViewMonitor;