bruce-cesium 2.8.2 → 2.8.3

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.
@@ -1,6 +1,6 @@
1
1
  import { BruceEvent, Cartes, Carto, Entity as Entity$1, Geometry, Tileset, MathUtils, LRUCache, ZoomControl, Style, EntityTag, Calculator, EntityLod, EntityType, ClientFile, ObjectUtils, Bounds, EntityRelationType, DelayQueue, BatchedDataGetter, EntityCoords, EntityFilterGetter, EntitySource, MenuItem, EntityRelation, ENVIRONMENT, ProjectView, ProjectViewBookmark, ProjectViewTile, ProjectViewLegacyTile, ProgramKey, Camera, AbstractApi, EntityAttachment, EntityAttachmentType, EntityAttribute } from 'bruce-models';
2
2
  import * as Cesium from 'cesium';
3
- import { Cartographic, Cartesian2, CallbackProperty, Cartesian3, Color, Rectangle, Math as Math$1, JulianDate, SceneMode, HeightReference, DistanceDisplayCondition, NearFarScalar, Entity, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Primitive, Cesium3DTileFeature, Cesium3DTileColorBlendMode, HeadingPitchRange, Cesium3DTileStyle, createOsmBuildings, KmlDataSource, OrthographicFrustum, EasingFunction, Cesium3DTileset, Matrix4, Matrix3, IonResource, Ion, EllipsoidGeodesic, EllipsoidTerrainProvider, sampleTerrainMostDetailed, defined, Model, createWorldTerrain, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, CesiumInspector, PolygonPipeline, ColorMaterialProperty, GeometryInstance, ScreenSpaceEventHandler, ScreenSpaceEventType, BoundingSphere } from 'cesium';
3
+ import { Cartographic, Cartesian2, CallbackProperty, Cartesian3, Color, Rectangle, Math as Math$1, JulianDate, SceneMode, Entity, Primitive, Cesium3DTileFeature, HeightReference, DistanceDisplayCondition, NearFarScalar, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Cesium3DTileColorBlendMode, HeadingPitchRange, createOsmBuildings, Cesium3DTileStyle, KmlDataSource, SceneTransforms, Cesium3DTileset, Matrix4, Matrix3, IonResource, Ion, OrthographicFrustum, EasingFunction, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, CesiumInspector, defined, PolygonPipeline, EllipsoidGeodesic, sampleTerrainMostDetailed, Model, ColorMaterialProperty, GeometryInstance, ScreenSpaceEventHandler, ScreenSpaceEventType, BoundingSphere } from 'cesium';
4
4
 
5
5
  var TIME_LAG = 300;
6
6
  var POSITION_CHECK_TIMER = 950;
@@ -1844,6 +1844,7 @@ function getRenderGroupId(zoomItem, terrain) {
1844
1844
  return zoomItem.MinZoom + "-" + zoomItem.MaxZoom + "-" + shouldApplyFlatFix(terrain);
1845
1845
  }
1846
1846
  var _fileValidationCache = {};
1847
+ var _fileHeightCache = {};
1847
1848
  /**
1848
1849
  * @param min
1849
1850
  * @param max
@@ -2198,7 +2199,7 @@ var EntityRenderEngine;
2198
2199
  (function (Point) {
2199
2200
  function Render(params) {
2200
2201
  return __awaiter(this, void 0, void 0, function () {
2201
- 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;
2202
+ 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;
2202
2203
  return __generator(this, function (_a) {
2203
2204
  switch (_a.label) {
2204
2205
  case 0:
@@ -2213,7 +2214,7 @@ var EntityRenderEngine;
2213
2214
  }
2214
2215
  cEntity = null;
2215
2216
  siblings = [];
2216
- if (!(type == Style.EPointType.Icon)) return [3 /*break*/, 7];
2217
+ if (!(type == Style.EPointType.Icon)) return [3 /*break*/, 12];
2217
2218
  iconUrlRows = style.iconUrl == null ? [] : style.iconUrl;
2218
2219
  iconUrlRows.forEach(function (row) {
2219
2220
  if (row.type == Calculator.EValueType.Color) {
@@ -2221,41 +2222,66 @@ var EntityRenderEngine;
2221
2222
  }
2222
2223
  });
2223
2224
  icon = Calculator.GetString(iconUrlRows, entity, params.tags);
2224
- iconUrl = null;
2225
+ iconUrl_1 = null;
2225
2226
  if (typeof icon == "string") {
2226
- iconUrl = icon;
2227
+ iconUrl_1 = icon;
2227
2228
  }
2228
- if (!iconUrl && style.iconId) {
2229
- iconUrl = ClientFile.GetUrl({
2229
+ if (!iconUrl_1 && style.iconId) {
2230
+ iconUrl_1 = ClientFile.GetUrl({
2230
2231
  api: params.api,
2231
2232
  fileId: style.iconId
2232
2233
  });
2233
2234
  }
2234
- if (!iconUrl) return [3 /*break*/, 6];
2235
+ if (!iconUrl_1) return [3 /*break*/, 11];
2235
2236
  _a.label = 1;
2236
2237
  case 1:
2237
- _a.trys.push([1, 5, , 6]);
2238
- if (!(_fileValidationCache[iconUrl] == null)) return [3 /*break*/, 3];
2239
- return [4 /*yield*/, fetch(iconUrl)];
2238
+ _a.trys.push([1, 10, , 11]);
2239
+ if (!(_fileValidationCache[iconUrl_1] == null)) return [3 /*break*/, 8];
2240
+ return [4 /*yield*/, fetch(iconUrl_1)];
2240
2241
  case 2:
2241
2242
  res = _a.sent();
2242
- if (res.status != 200) {
2243
- iconUrl = null;
2244
- }
2245
- _fileValidationCache[iconUrl] = Boolean(iconUrl);
2246
- return [3 /*break*/, 4];
2243
+ if (!(res.status != 200)) return [3 /*break*/, 3];
2244
+ iconUrl_1 = null;
2245
+ return [3 /*break*/, 7];
2247
2246
  case 3:
2248
- if (!_fileValidationCache[iconUrl]) {
2249
- iconUrl = null;
2250
- }
2251
- _a.label = 4;
2252
- case 4: return [3 /*break*/, 6];
2247
+ _a.trys.push([3, 6, , 7]);
2248
+ return [4 /*yield*/, res.blob()];
2249
+ case 4:
2250
+ blob_1 = _a.sent();
2251
+ return [4 /*yield*/, new Promise(function (res) {
2252
+ var img = new Image();
2253
+ img.onload = function () {
2254
+ _fileHeightCache[iconUrl_1] = img.height;
2255
+ res(null);
2256
+ };
2257
+ img.onerror = function () {
2258
+ _fileHeightCache[iconUrl_1] = undefined;
2259
+ res(null);
2260
+ };
2261
+ img.src = URL.createObjectURL(blob_1);
2262
+ })];
2253
2263
  case 5:
2254
- e_4 = _a.sent();
2255
- iconUrl = null;
2256
- return [3 /*break*/, 6];
2264
+ _a.sent();
2265
+ return [3 /*break*/, 7];
2257
2266
  case 6:
2258
- if (iconUrl) {
2267
+ e_4 = _a.sent();
2268
+ console.error(e_4);
2269
+ return [3 /*break*/, 7];
2270
+ case 7:
2271
+ _fileValidationCache[iconUrl_1] = Boolean(iconUrl_1);
2272
+ return [3 /*break*/, 9];
2273
+ case 8:
2274
+ if (!_fileValidationCache[iconUrl_1]) {
2275
+ iconUrl_1 = null;
2276
+ }
2277
+ _a.label = 9;
2278
+ case 9: return [3 /*break*/, 11];
2279
+ case 10:
2280
+ e_5 = _a.sent();
2281
+ iconUrl_1 = null;
2282
+ return [3 /*break*/, 11];
2283
+ case 11:
2284
+ if (iconUrl_1) {
2259
2285
  iconScale = EnsureNumber(Calculator.GetNumber(style.iconScale, entity, params.tags));
2260
2286
  if (!iconScale && iconScale != 0) {
2261
2287
  iconScale = 1;
@@ -2267,11 +2293,12 @@ var EntityRenderEngine;
2267
2293
  billboard: {
2268
2294
  horizontalOrigin: HorizontalOrigin.CENTER,
2269
2295
  verticalOrigin: VerticalOrigin.BOTTOM,
2270
- image: iconUrl,
2296
+ image: iconUrl_1,
2271
2297
  heightReference: getHeightRef(style),
2272
2298
  scale: iconScale,
2273
2299
  disableDepthTestDistance: disableDepthTest ? Number.POSITIVE_INFINITY : undefined,
2274
2300
  distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance),
2301
+ height: _fileHeightCache[iconUrl_1]
2275
2302
  // Would be great once we have a setting for this.
2276
2303
  // translucencyByDistance: getTranslucencyByDistance(params.minDistance, params.maxDistance),
2277
2304
  },
@@ -2285,8 +2312,8 @@ var EntityRenderEngine;
2285
2312
  });
2286
2313
  }
2287
2314
  }
2288
- _a.label = 7;
2289
- case 7:
2315
+ _a.label = 12;
2316
+ case 12:
2290
2317
  if (type == Style.EPointType.Cylinder) {
2291
2318
  radius = EnsureNumber(Calculator.GetNumber(style.CylinderRadius, entity, params.tags));
2292
2319
  if (radius <= 0) {
@@ -3689,6 +3716,274 @@ var RelationRenderEngine;
3689
3716
  })(Parabola = RelationRenderEngine.Parabola || (RelationRenderEngine.Parabola = {}));
3690
3717
  })(RelationRenderEngine || (RelationRenderEngine = {}));
3691
3718
 
3719
+ // Key where the label instance is stored within the cesium entity.
3720
+ // Eg: cEntity[ATTACH_KEY] = new EntityLabel(...);
3721
+ var ATTACH_KEY = "nextspace-navigator-entity-label";
3722
+ /**
3723
+ * Returns cesium property's value.
3724
+ * This will check if it's one that changes over time, or just a fixed value.
3725
+ * Eg: const pos3d = getValue<Cesium.Cartesian3>(cViewer, cEntity.point.position);
3726
+ * @param viewer
3727
+ * @param obj
3728
+ */
3729
+ function getValue$1(viewer, obj) {
3730
+ if (obj === null || obj === void 0 ? void 0 : obj.getValue) {
3731
+ return obj.getValue(viewer.scene.lastRenderTime);
3732
+ }
3733
+ return obj;
3734
+ }
3735
+ /**
3736
+ * Util for generating labels within cesium space on entities.
3737
+ */
3738
+ var EntityLabel;
3739
+ (function (EntityLabel) {
3740
+ var Label = /** @class */ (function () {
3741
+ function Label(params) {
3742
+ var _this = this;
3743
+ // The label element itself.
3744
+ this.label = null;
3745
+ // Callback to kill render listener.
3746
+ this.renderRemoval = null;
3747
+ // Indicates the label was disposed and any actions will be ignored.
3748
+ this.disposed = false;
3749
+ this.creating = false;
3750
+ this.rego = params.rego;
3751
+ this.viewer = params.viewer;
3752
+ this.creating = true;
3753
+ this.createCLabel().then(function () {
3754
+ _this.creating = false;
3755
+ }).catch(function (e) {
3756
+ console.error("Failed to create label", e);
3757
+ _this.creating = false;
3758
+ });
3759
+ }
3760
+ Object.defineProperty(Label.prototype, "Disposed", {
3761
+ get: function () {
3762
+ return this.disposed;
3763
+ },
3764
+ enumerable: false,
3765
+ configurable: true
3766
+ });
3767
+ Object.defineProperty(Label.prototype, "Creating", {
3768
+ get: function () {
3769
+ return this.creating;
3770
+ },
3771
+ enumerable: false,
3772
+ configurable: true
3773
+ });
3774
+ /**
3775
+ * Disposes label and marks instance as disposed.
3776
+ * Recalling will be ignored.
3777
+ */
3778
+ Label.prototype.Dispose = function () {
3779
+ if (this.disposed) {
3780
+ return;
3781
+ }
3782
+ this.disposed = true;
3783
+ if (this.label &&
3784
+ this.label.parentElement) {
3785
+ this.label.parentElement.removeChild(this.label);
3786
+ this.label = null;
3787
+ }
3788
+ if (this.renderRemoval) {
3789
+ this.renderRemoval();
3790
+ this.renderRemoval = null;
3791
+ }
3792
+ };
3793
+ /**
3794
+ * Creates cesium entity for the label if one does not exist.
3795
+ */
3796
+ Label.prototype.createCLabel = function () {
3797
+ var _a, _b, _c;
3798
+ return __awaiter(this, void 0, void 0, function () {
3799
+ var pos3d, heightRef, heightOffset, pixelOffset, visual, isClamped, height, scale, carto, text, ele, _lastDistance, _lastCameraPos, getDistance, MAX_DISTANCE, updateLabel;
3800
+ var _this = this;
3801
+ return __generator(this, function (_d) {
3802
+ if (this.label || this.disposed) {
3803
+ return [2 /*return*/];
3804
+ }
3805
+ pos3d = null;
3806
+ heightRef = null;
3807
+ heightOffset = 10;
3808
+ pixelOffset = new Cartesian2(0, 0);
3809
+ visual = (_a = this.rego) === null || _a === void 0 ? void 0 : _a.visual;
3810
+ if (visual && visual instanceof Entity) {
3811
+ if (visual.polygon) {
3812
+ heightRef = getValue$1(this.viewer, visual.polygon.heightReference);
3813
+ }
3814
+ else if (visual.polyline) {
3815
+ isClamped = getValue$1(this.viewer, visual.polyline.clampToGround);
3816
+ heightRef = isClamped == false ? HeightReference.NONE : HeightReference.CLAMP_TO_GROUND;
3817
+ }
3818
+ else if (visual.model) {
3819
+ heightRef = getValue$1(this.viewer, visual.model.heightReference);
3820
+ }
3821
+ else if (visual.point) {
3822
+ heightRef = getValue$1(this.viewer, visual.point.heightReference);
3823
+ }
3824
+ else if (visual.billboard) {
3825
+ heightRef = getValue$1(this.viewer, visual.billboard.heightReference);
3826
+ height = getValue$1(this.viewer, visual.billboard.height);
3827
+ if (height) {
3828
+ scale = EnsureNumber(getValue$1(this.viewer, visual.billboard.scale), 1);
3829
+ pixelOffset.y = -(height * scale);
3830
+ }
3831
+ // Flat padding.
3832
+ pixelOffset.y -= 5;
3833
+ heightOffset = 0;
3834
+ }
3835
+ else if (visual.corridor) {
3836
+ heightRef = getValue$1(this.viewer, visual.corridor.heightReference);
3837
+ }
3838
+ else if (visual.ellipse) {
3839
+ heightRef = getValue$1(this.viewer, visual.ellipse.heightReference);
3840
+ }
3841
+ pos3d = getValue$1(this.viewer, visual.position);
3842
+ }
3843
+ if (isNaN(pos3d === null || pos3d === void 0 ? void 0 : pos3d.x)) {
3844
+ return [2 /*return*/];
3845
+ }
3846
+ carto = Cartographic.fromCartesian(pos3d);
3847
+ // TODO: Check if we need to use heightRef and adjust to absolute height.
3848
+ // TODO: We should be smarter and not just add 10m to the height. Eg: use polygon extrusion.
3849
+ carto.height += heightOffset;
3850
+ pos3d = Cartographic.toCartesian(carto);
3851
+ text = (_c = (_b = this.rego) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : "Unnamed Entity";
3852
+ ele = document.createElement("div");
3853
+ ele.innerHTML = text;
3854
+ ele.setAttribute("style", "\n position: absolute;\n z-index: 1;\n display: none;\n pointer-events: none;\n padding: 6px;\n border-radius: 6px;\n font-family: sans-serif;\n font-size: 12px;\n background-color: #000000;\n color: #ffffff;\n }");
3855
+ this.label = ele;
3856
+ this.viewer.container.appendChild(ele);
3857
+ _lastDistance = null;
3858
+ _lastCameraPos = null;
3859
+ getDistance = function () {
3860
+ var _a;
3861
+ if (_this.disposed) {
3862
+ return null;
3863
+ }
3864
+ var cameraPos = (_a = _this.viewer.camera) === null || _a === void 0 ? void 0 : _a.position;
3865
+ if (isNaN(cameraPos === null || cameraPos === void 0 ? void 0 : cameraPos.x)) {
3866
+ return null;
3867
+ }
3868
+ // If camera hasn't moved much then we can use the last distance.
3869
+ var TOLERANCE = 0.1;
3870
+ if (_lastCameraPos) {
3871
+ var totalMovement = Math.abs(_lastCameraPos.x - cameraPos.x) +
3872
+ Math.abs(_lastCameraPos.y - cameraPos.y) +
3873
+ Math.abs(_lastCameraPos.z - cameraPos.z);
3874
+ if (totalMovement < TOLERANCE) {
3875
+ return _lastDistance;
3876
+ }
3877
+ }
3878
+ // Check if there is a raycast collision between camera and pos3d.
3879
+ // We'll let the labels draw through a ground collision.
3880
+ // Commented out while it is WIP.
3881
+ // const direction = Cesium.Cartesian3.subtract(pos3d, cameraPos, new Cesium.Cartesian3());
3882
+ // const ray = new Cesium.Ray(pos3d.clone(), direction);
3883
+ // const objects = (this.viewer.scene as any).drillPickFromRay(ray, 1, [visuals]);
3884
+ // if (objects && objects.length > 0) {
3885
+ // for (let i = 0; i < objects.length; ++i) {
3886
+ // const obj = objects[i];
3887
+ // if (!visuals.find(x => x == obj?.id)) {
3888
+ // let isGround = true;
3889
+ // if (obj.object) {
3890
+ // const url = obj.object?.primitive?._basePath;
3891
+ // if (url && typeof url == "string") {
3892
+ // isGround = url.includes("tile.googleapis.com");
3893
+ // }
3894
+ // else {
3895
+ // isGround = false;
3896
+ // }
3897
+ // }
3898
+ // if (!isGround) {
3899
+ // return null;
3900
+ // }
3901
+ // }
3902
+ // }
3903
+ // }
3904
+ var distance = Cartesian3.distance(cameraPos, pos3d);
3905
+ _lastDistance = distance;
3906
+ _lastCameraPos = cameraPos.clone();
3907
+ return distance;
3908
+ };
3909
+ MAX_DISTANCE = 5000;
3910
+ updateLabel = function () {
3911
+ if (_this.disposed || isNaN(pos3d === null || pos3d === void 0 ? void 0 : pos3d.x)) {
3912
+ return;
3913
+ }
3914
+ var distance = getDistance();
3915
+ if (isNaN(distance) || distance >= MAX_DISTANCE) {
3916
+ ele.style.display = "none";
3917
+ return;
3918
+ }
3919
+ var pos2d = SceneTransforms.wgs84ToWindowCoordinates(_this.viewer.scene, pos3d);
3920
+ if (isNaN(pos2d === null || pos2d === void 0 ? void 0 : pos2d.x)) {
3921
+ ele.style.display = "none";
3922
+ return;
3923
+ }
3924
+ // If out of the screen then we can hide it.
3925
+ if (pos2d.x < 0 || pos2d.x > _this.viewer.canvas.clientWidth ||
3926
+ pos2d.y < 0 || pos2d.y > _this.viewer.canvas.clientHeight) {
3927
+ ele.style.display = "none";
3928
+ return;
3929
+ }
3930
+ ele.style.display = "block";
3931
+ // Check scale to apply based on distance between camera and pos3d.
3932
+ // We'll make the label smaller and less transparent when further away.
3933
+ var scale = 1 - (distance / MAX_DISTANCE);
3934
+ if (scale && scale > 0.15) {
3935
+ ele.style.transform = "scale(".concat(scale, ")");
3936
+ ele.style.opacity = "".concat(scale);
3937
+ var left = pos2d.x - (ele.clientWidth / 2) + pixelOffset.x;
3938
+ ele.style.left = "".concat(left, "px");
3939
+ var top_1 = pos2d.y - ele.clientHeight + (pixelOffset.y * scale);
3940
+ ele.style.top = "".concat(top_1, "px");
3941
+ }
3942
+ else {
3943
+ ele.style.transform = "";
3944
+ ele.style.opacity = "0";
3945
+ }
3946
+ };
3947
+ this.renderRemoval = this.viewer.scene.postUpdate.addEventListener(updateLabel);
3948
+ updateLabel();
3949
+ return [2 /*return*/];
3950
+ });
3951
+ });
3952
+ };
3953
+ return Label;
3954
+ }());
3955
+ EntityLabel.Label = Label;
3956
+ /**
3957
+ * Creates an entity label for a given rego.
3958
+ * If one exists then the action is ignored.
3959
+ */
3960
+ function Attach(params) {
3961
+ var rego = params.rego, viewer = params.viewer;
3962
+ if (!rego || !viewer || rego[ATTACH_KEY]) {
3963
+ return;
3964
+ }
3965
+ rego[ATTACH_KEY] = new Label({
3966
+ rego: rego,
3967
+ viewer: viewer
3968
+ });
3969
+ }
3970
+ EntityLabel.Attach = Attach;
3971
+ /**
3972
+ * Removes an entity label from a given rego.
3973
+ * If one doesn't exist then the action is ignored.
3974
+ */
3975
+ function Detatch(params) {
3976
+ var _a, _b;
3977
+ var rego = params.rego;
3978
+ if (!rego || !rego[ATTACH_KEY]) {
3979
+ return;
3980
+ }
3981
+ (_b = (_a = rego[ATTACH_KEY]).Dispose) === null || _b === void 0 ? void 0 : _b.call(_a);
3982
+ rego[ATTACH_KEY] = null;
3983
+ }
3984
+ EntityLabel.Detatch = Detatch;
3985
+ })(EntityLabel || (EntityLabel = {}));
3986
+
3692
3987
  /**
3693
3988
  * Returns if a given visual is alive and in the scene.
3694
3989
  * @param viewer
@@ -3817,7 +4112,24 @@ function updateEntity(viewer, entityId, register) {
3817
4112
  for (var i = 0; i < regos.length; i++) {
3818
4113
  var rego = regos[i];
3819
4114
  rego.best = rego === highestPriority;
3820
- updateEntityShow(viewer, rego.visual, rego.suppressShow ? false : getShowState(rego));
4115
+ var visible = rego.suppressShow ? false : getShowState(rego);
4116
+ updateEntityShow(viewer, rego.visual, visible);
4117
+ if (rego.best) {
4118
+ var isLabelled = register.GetIsLabelled({
4119
+ entityId: entityId
4120
+ });
4121
+ if (isLabelled && visible) {
4122
+ EntityLabel.Attach({
4123
+ rego: rego,
4124
+ viewer: viewer
4125
+ });
4126
+ }
4127
+ else {
4128
+ EntityLabel.Detatch({
4129
+ rego: rego
4130
+ });
4131
+ }
4132
+ }
3821
4133
  }
3822
4134
  }
3823
4135
  function markEntity(register, rego, visual, ignoreParent) {
@@ -3999,6 +4311,10 @@ var VisualsRegister;
3999
4311
  this.hiddenIds = [];
4000
4312
  // Entity id -> opacity for visual.
4001
4313
  this.opacity = {};
4314
+ // Array of entity ids for entities who have labels drawn for them.
4315
+ // It will be drawn on the "best" visual, and only while the entity is visible.
4316
+ // Warning: this sucks for CAD entities.
4317
+ this.labelledEntityIds = [];
4002
4318
  this.viewer = viewer;
4003
4319
  }
4004
4320
  Object.defineProperty(Register.prototype, "Id", {
@@ -4037,6 +4353,71 @@ var VisualsRegister;
4037
4353
  }
4038
4354
  this.viewer.scene.requestRender();
4039
4355
  };
4356
+ /**
4357
+ * Marks given entityIds as either labelled or not labelled.
4358
+ * When an entity is labelled a label will be drawn on the "best" visual for it.
4359
+ * @param params
4360
+ */
4361
+ Register.prototype.SetLabelled = function (params) {
4362
+ var labelled = params.labelled, entityIds = params.entityIds, requestRender = params.requestRender;
4363
+ var _loop_3 = function (i) {
4364
+ var id = entityIds[i];
4365
+ var index = this_1.labelledEntityIds.findIndex(function (x) { return x == id; });
4366
+ if (labelled) {
4367
+ if (index <= -1) {
4368
+ this_1.labelledEntityIds.push(id);
4369
+ updateEntity(this_1.viewer, id, this_1);
4370
+ }
4371
+ }
4372
+ else {
4373
+ if (index > -1) {
4374
+ this_1.labelledEntityIds.splice(index, 1);
4375
+ updateEntity(this_1.viewer, id, this_1);
4376
+ }
4377
+ }
4378
+ };
4379
+ var this_1 = this;
4380
+ for (var i = 0; i < entityIds.length; i++) {
4381
+ _loop_3(i);
4382
+ }
4383
+ if (requestRender != false) {
4384
+ this.viewer.scene.requestRender();
4385
+ }
4386
+ };
4387
+ /**
4388
+ * Returns if given entity id is labelled.
4389
+ * @param params
4390
+ */
4391
+ Register.prototype.GetIsLabelled = function (params) {
4392
+ var id = params.entityId;
4393
+ return this.labelledEntityIds.indexOf(id) !== -1;
4394
+ };
4395
+ /**
4396
+ * Clears all labelled entities.
4397
+ * @param params
4398
+ */
4399
+ Register.prototype.ClearLabelled = function (params) {
4400
+ var ids = [].concat(this.labelledEntityIds);
4401
+ this.labelledEntityIds = [];
4402
+ for (var i = 0; i < ids.length; i++) {
4403
+ var id = ids[i];
4404
+ updateEntity(this.viewer, id, this);
4405
+ }
4406
+ if ((params === null || params === void 0 ? void 0 : params.requestRender) != false) {
4407
+ this.viewer.scene.requestRender();
4408
+ }
4409
+ };
4410
+ /**
4411
+ * Returns all labelled entity ids.
4412
+ */
4413
+ Register.prototype.GetLabelled = function () {
4414
+ return this.labelledEntityIds;
4415
+ };
4416
+ /**
4417
+ * Updates the selection color.
4418
+ * This will not update the selection color for already selected entities.
4419
+ * @param color
4420
+ */
4040
4421
  Register.prototype.SetSelectionColor = function (color) {
4041
4422
  this.selectionColor = color;
4042
4423
  };
@@ -4362,26 +4743,26 @@ var VisualsRegister;
4362
4743
  return;
4363
4744
  }
4364
4745
  var menuItems = menuItemId ? [menuItemId] : entityRegos.map(function (x) { return x.menuItemId; });
4365
- var _loop_3 = function (i) {
4746
+ var _loop_4 = function (i) {
4366
4747
  var menuItemId_2 = menuItems[i];
4367
4748
  var rego = entityRegos.find(function (r) { return r.menuItemId === menuItemId_2; });
4368
4749
  if (!rego) {
4369
4750
  return { value: void 0 };
4370
4751
  }
4371
- removeEntity(this_1.viewer, rego.visual);
4372
- (_b = this_1.onUpdate) === null || _b === void 0 ? void 0 : _b.Trigger({
4752
+ removeEntity(this_2.viewer, rego.visual);
4753
+ (_b = this_2.onUpdate) === null || _b === void 0 ? void 0 : _b.Trigger({
4373
4754
  type: EVisualUpdateType.Remove,
4374
4755
  entityId: rego.entityId,
4375
4756
  rego: rego
4376
4757
  });
4377
- this_1.rego[entityId] = entityRegos.filter(function (r) { return r.menuItemId !== menuItemId_2; });
4758
+ this_2.rego[entityId] = entityRegos.filter(function (r) { return r.menuItemId !== menuItemId_2; });
4378
4759
  if (doUpdate && menuItemId_2) {
4379
- updateEntity(this_1.viewer, entityId, this_1);
4760
+ updateEntity(this_2.viewer, entityId, this_2);
4380
4761
  }
4381
4762
  };
4382
- var this_1 = this;
4763
+ var this_2 = this;
4383
4764
  for (var i = 0; i < menuItems.length; i++) {
4384
- var state_1 = _loop_3(i);
4765
+ var state_1 = _loop_4(i);
4385
4766
  if (typeof state_1 === "object")
4386
4767
  return state_1.value;
4387
4768
  }
@@ -12266,11 +12647,11 @@ function renderLegacyNavigator(iteration, params, bookmark, view) {
12266
12647
  * @param view
12267
12648
  */
12268
12649
  function renderNavigator(iteration, params, bookmark, view) {
12269
- 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;
12650
+ 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;
12270
12651
  return __awaiter(this, void 0, void 0, function () {
12271
- 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;
12272
- return __generator(this, function (_6) {
12273
- switch (_6.label) {
12652
+ 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;
12653
+ return __generator(this, function (_7) {
12654
+ switch (_7.label) {
12274
12655
  case 0:
12275
12656
  viewer = params.manager.Viewer;
12276
12657
  scene = viewer.scene;
@@ -12332,11 +12713,11 @@ function renderNavigator(iteration, params, bookmark, view) {
12332
12713
  viewer: params.manager.Viewer,
12333
12714
  })];
12334
12715
  case 1:
12335
- _6.sent();
12716
+ _7.sent();
12336
12717
  if (!assertIteration$1(params.viewer, iteration)) {
12337
12718
  return [2 /*return*/];
12338
12719
  }
12339
- _6.label = 2;
12720
+ _7.label = 2;
12340
12721
  case 2:
12341
12722
  hillShades = (_o = bookmark === null || bookmark === void 0 ? void 0 : bookmark.Settings) === null || _o === void 0 ? void 0 : _o.hillShades;
12342
12723
  if (hillShades == null) {
@@ -12496,10 +12877,21 @@ function renderNavigator(iteration, params, bookmark, view) {
12496
12877
  entityIds: isolatedIds
12497
12878
  });
12498
12879
  }
12880
+ params.manager.VisualsRegister.ClearLabelled();
12881
+ labelledIds = bSettings === null || bSettings === void 0 ? void 0 : bSettings.labelledEntityIds;
12882
+ if (labelledIds == null) {
12883
+ labelledIds = (_2 = defaults === null || defaults === void 0 ? void 0 : defaults.settings) === null || _2 === void 0 ? void 0 : _2.labelledEntityIds;
12884
+ }
12885
+ if (labelledIds != null) {
12886
+ params.manager.VisualsRegister.SetLabelled({
12887
+ labelled: true,
12888
+ entityIds: labelledIds
12889
+ });
12890
+ }
12499
12891
  params.manager.VisualsRegister.ClearOpacity();
12500
12892
  entityOpacityMap = bSettings === null || bSettings === void 0 ? void 0 : bSettings.entityOpacityMap;
12501
12893
  if (entityOpacityMap == null) {
12502
- entityOpacityMap = (_2 = defaults === null || defaults === void 0 ? void 0 : defaults.settings) === null || _2 === void 0 ? void 0 : _2.entityOpacityMap;
12894
+ entityOpacityMap = (_3 = defaults === null || defaults === void 0 ? void 0 : defaults.settings) === null || _3 === void 0 ? void 0 : _3.entityOpacityMap;
12503
12895
  }
12504
12896
  if (entityOpacityMap != null) {
12505
12897
  for (entityId in entityOpacityMap) {
@@ -12512,7 +12904,7 @@ function renderNavigator(iteration, params, bookmark, view) {
12512
12904
  }
12513
12905
  }
12514
12906
  }
12515
- imagery = (bSettings === null || bSettings === void 0 ? void 0 : bSettings.imagery) != null ? bSettings.imagery : (_3 = defaults.settings) === null || _3 === void 0 ? void 0 : _3.imagery;
12907
+ imagery = (bSettings === null || bSettings === void 0 ? void 0 : bSettings.imagery) != null ? bSettings.imagery : (_4 = defaults.settings) === null || _4 === void 0 ? void 0 : _4.imagery;
12516
12908
  if (imagery == null) {
12517
12909
  // TODO: Need global default.
12518
12910
  imagery = [
@@ -12539,7 +12931,7 @@ function renderNavigator(iteration, params, bookmark, view) {
12539
12931
  renderedRelationEntityIds = [];
12540
12932
  }
12541
12933
  curEnabled = params.manager.GetEnabledItemIds();
12542
- newItemIds = (_4 = bSettings === null || bSettings === void 0 ? void 0 : bSettings.menuItemIds) !== null && _4 !== void 0 ? _4 : [];
12934
+ newItemIds = (_5 = bSettings === null || bSettings === void 0 ? void 0 : bSettings.menuItemIds) !== null && _5 !== void 0 ? _5 : [];
12543
12935
  for (_i = 0, curEnabled_1 = curEnabled; _i < curEnabled_1.length; _i++) {
12544
12936
  id = curEnabled_1[_i];
12545
12937
  if (newItemIds.indexOf(id) === -1 ||
@@ -12557,11 +12949,11 @@ function renderNavigator(iteration, params, bookmark, view) {
12557
12949
  bookmark: bookmark
12558
12950
  })];
12559
12951
  case 3:
12560
- _6.sent();
12952
+ _7.sent();
12561
12953
  if (!assertIteration$1(params.viewer, iteration)) {
12562
12954
  return [2 /*return*/];
12563
12955
  }
12564
- _6.label = 4;
12956
+ _7.label = 4;
12565
12957
  case 4:
12566
12958
  if (!renderedRelationEntityIds.length) return [3 /*break*/, 6];
12567
12959
  menuItem = {
@@ -12577,15 +12969,15 @@ function renderNavigator(iteration, params, bookmark, view) {
12577
12969
  item: menuItem
12578
12970
  })];
12579
12971
  case 5:
12580
- _6.sent();
12972
+ _7.sent();
12581
12973
  if (!assertIteration$1(params.viewer, iteration)) {
12582
12974
  return [2 /*return*/];
12583
12975
  }
12584
- _6.label = 6;
12976
+ _7.label = 6;
12585
12977
  case 6:
12586
12978
  gOcclusion = bSettings === null || bSettings === void 0 ? void 0 : bSettings.groundOcclusion;
12587
12979
  if (gOcclusion == null) {
12588
- gOcclusion = (_5 = defaults === null || defaults === void 0 ? void 0 : defaults.settings) === null || _5 === void 0 ? void 0 : _5.groundOcclusion;
12980
+ gOcclusion = (_6 = defaults === null || defaults === void 0 ? void 0 : defaults.settings) === null || _6 === void 0 ? void 0 : _6.groundOcclusion;
12589
12981
  }
12590
12982
  if (gOcclusion == null) {
12591
12983
  // TODO: Need global default.
@@ -15489,7 +15881,7 @@ var ViewerUtils;
15489
15881
  ViewerUtils.CreateWidgets = CreateWidgets;
15490
15882
  })(ViewerUtils || (ViewerUtils = {}));
15491
15883
 
15492
- var VERSION$1 = "2.8.2";
15884
+ var VERSION$1 = "2.8.3";
15493
15885
 
15494
- export { VERSION$1 as VERSION, CesiumViewMonitor, ViewerUtils, MenuItemManager, EntityRenderEngine, MenuItemCreator, VisualsRegister, RenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, TilesetCadRenderManager, TilesetArbRenderManager, TilesetEntitiesRenderManager, TilesetOsmRenderManager, TilesetPointcloudRenderManager, TilesetGooglePhotosRenderManager, DataSourceStaticKmlManager, RelationsRenderManager, SharedGetters, CesiumParabola, ViewRenderEngine, TileRenderEngine, TilesetRenderEngine, CESIUM_INSPECTOR_KEY, ViewUtils, DrawingUtils, MeasureUtils, EntityUtils, Draw3dPolygon, Draw3dPolyline };
15886
+ export { VERSION$1 as VERSION, CesiumViewMonitor, ViewerUtils, MenuItemManager, EntityRenderEngine, MenuItemCreator, VisualsRegister, RenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, TilesetCadRenderManager, TilesetArbRenderManager, TilesetEntitiesRenderManager, TilesetOsmRenderManager, TilesetPointcloudRenderManager, TilesetGooglePhotosRenderManager, DataSourceStaticKmlManager, RelationsRenderManager, SharedGetters, CesiumParabola, EntityLabel, ViewRenderEngine, TileRenderEngine, TilesetRenderEngine, CESIUM_INSPECTOR_KEY, ViewUtils, DrawingUtils, MeasureUtils, EntityUtils, Draw3dPolygon, Draw3dPolyline };
15495
15887
  //# sourceMappingURL=bruce-cesium.es5.js.map