bruce-cesium 2.6.2 → 2.6.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.
@@ -1030,42 +1030,63 @@
1030
1030
  * @returns
1031
1031
  */
1032
1032
  function GetPosAsync(params) {
1033
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
1033
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1034
1034
  return __awaiter(this, void 0, void 0, function () {
1035
- var viewer, entityId, entity, tileset, tilesetId, visualRegister, returnHeightRef, recordHeightRef, api, e_1, pos3d, tSettings, alt, alt, heading, pitch, roll, matrix4, offset, m1, hpr, transform, transformedOffset;
1036
- return __generator(this, function (_l) {
1037
- switch (_l.label) {
1035
+ var viewer, entityId, entity, tileset, tilesetId, visualRegister, returnHeightRef, recordHeightRef, api, lat, lon, e_1, e_2, pos3d, tSettings, alt, alt, heading, pitch, roll, matrix4, offset, m1, hpr, transform, transformedOffset;
1036
+ return __generator(this, function (_o) {
1037
+ switch (_o.label) {
1038
1038
  case 0:
1039
1039
  viewer = params.viewer, entityId = params.entityId, entity = params.entity, tileset = params.tileset, tilesetId = params.tilesetId, visualRegister = params.visualRegister, returnHeightRef = params.returnHeightRef, recordHeightRef = params.recordHeightRef, api = params.api;
1040
- if (!!entity) return [3 /*break*/, 5];
1041
- _l.label = 1;
1040
+ if (!!entity) return [3 /*break*/, 9];
1041
+ lat = 0;
1042
+ lon = 0;
1043
+ _o.label = 1;
1042
1044
  case 1:
1043
- _l.trys.push([1, 3, , 5]);
1045
+ _o.trys.push([1, 3, , 4]);
1044
1046
  return [4 /*yield*/, bruceModels.Entity.Get({
1045
1047
  api: api,
1046
1048
  entityId: entityId,
1047
- expandLocation: true
1049
+ expandLocation: false
1048
1050
  })];
1049
1051
  case 2:
1050
- entity = (_l.sent()).entity;
1051
- return [3 /*break*/, 5];
1052
+ entity = (_o.sent()).entity;
1053
+ lat = +((_a = entity === null || entity === void 0 ? void 0 : entity.location) === null || _a === void 0 ? void 0 : _a.latitude);
1054
+ lon = +((_b = entity === null || entity === void 0 ? void 0 : entity.location) === null || _b === void 0 ? void 0 : _b.longitude);
1055
+ return [3 /*break*/, 4];
1052
1056
  case 3:
1053
- e_1 = _l.sent();
1054
- console.warn(e_1);
1057
+ e_1 = _o.sent();
1058
+ console.error(e_1);
1059
+ return [3 /*break*/, 4];
1060
+ case 4:
1061
+ if (!(entity && (isNaN(lat) || isNaN(lon) || (lat == 0 && lon == 0)))) return [3 /*break*/, 9];
1062
+ _o.label = 5;
1063
+ case 5:
1064
+ _o.trys.push([5, 7, , 9]);
1065
+ return [4 /*yield*/, bruceModels.Entity.Get({
1066
+ api: api,
1067
+ entityId: entityId,
1068
+ expandLocation: true
1069
+ })];
1070
+ case 6:
1071
+ entity = (_o.sent()).entity;
1072
+ return [3 /*break*/, 9];
1073
+ case 7:
1074
+ e_2 = _o.sent();
1075
+ console.warn(e_2);
1055
1076
  return [4 /*yield*/, bruceModels.Entity.Get({
1056
1077
  api: api,
1057
1078
  entityId: entityId,
1058
1079
  expandLocation: false
1059
1080
  })];
1060
- case 4:
1061
- entity = (_l.sent()).entity;
1062
- return [3 /*break*/, 5];
1063
- case 5:
1081
+ case 8:
1082
+ entity = (_o.sent()).entity;
1083
+ return [3 /*break*/, 9];
1084
+ case 9:
1064
1085
  if (!entity) {
1065
1086
  return [2 /*return*/, null];
1066
1087
  }
1067
1088
  if (!tilesetId) {
1068
- tilesetId = ((_a = entity.tilesetID) === null || _a === void 0 ? void 0 : _a.length) ? entity.tilesetID[0] : tilesetId;
1089
+ tilesetId = ((_c = entity.tilesetID) === null || _c === void 0 ? void 0 : _c.length) ? entity.tilesetID[0] : tilesetId;
1069
1090
  }
1070
1091
  pos3d = tilesetId ? null : GetPos({
1071
1092
  viewer: viewer,
@@ -1077,19 +1098,19 @@
1077
1098
  if (bruceModels.Cartes.ValidateCartes3(pos3d)) {
1078
1099
  return [2 /*return*/, pos3d];
1079
1100
  }
1080
- if (!!tileset) return [3 /*break*/, 7];
1081
- if (!tilesetId) return [3 /*break*/, 7];
1101
+ if (!!tileset) return [3 /*break*/, 11];
1102
+ if (!tilesetId) return [3 /*break*/, 11];
1082
1103
  return [4 /*yield*/, bruceModels.Tileset.Get({
1083
1104
  api: api,
1084
1105
  tilesetId: tilesetId
1085
1106
  })];
1086
- case 6:
1087
- tileset = (_l.sent()).tileset;
1088
- _l.label = 7;
1089
- case 7:
1107
+ case 10:
1108
+ tileset = (_o.sent()).tileset;
1109
+ _o.label = 11;
1110
+ case 11:
1090
1111
  tSettings = tileset === null || tileset === void 0 ? void 0 : tileset.settings;
1091
- if (((_b = entity.location) === null || _b === void 0 ? void 0 : _b.longitude) || ((_c = tSettings === null || tSettings === void 0 ? void 0 : tSettings.location) === null || _c === void 0 ? void 0 : _c.longitude)) {
1092
- if ((_d = entity === null || entity === void 0 ? void 0 : entity.location) === null || _d === void 0 ? void 0 : _d.longitude) {
1112
+ if (((_d = entity.location) === null || _d === void 0 ? void 0 : _d.longitude) || ((_e = tSettings === null || tSettings === void 0 ? void 0 : tSettings.location) === null || _e === void 0 ? void 0 : _e.longitude)) {
1113
+ if ((_f = entity === null || entity === void 0 ? void 0 : entity.location) === null || _f === void 0 ? void 0 : _f.longitude) {
1093
1114
  alt = +entity.location.altitude;
1094
1115
  if (isNaN(alt)) {
1095
1116
  alt = 0;
@@ -1108,22 +1129,22 @@
1108
1129
  heading = 0;
1109
1130
  pitch = 0;
1110
1131
  roll = 0;
1111
- if ((_e = entity === null || entity === void 0 ? void 0 : entity.transform) === null || _e === void 0 ? void 0 : _e.heading) {
1132
+ if ((_g = entity === null || entity === void 0 ? void 0 : entity.transform) === null || _g === void 0 ? void 0 : _g.heading) {
1112
1133
  heading = entity.transform.heading;
1113
1134
  }
1114
- else if ((_f = tSettings === null || tSettings === void 0 ? void 0 : tSettings.transform) === null || _f === void 0 ? void 0 : _f.heading) {
1135
+ else if ((_h = tSettings === null || tSettings === void 0 ? void 0 : tSettings.transform) === null || _h === void 0 ? void 0 : _h.heading) {
1115
1136
  heading = tSettings.transform.heading;
1116
1137
  }
1117
- if ((_g = entity === null || entity === void 0 ? void 0 : entity.transform) === null || _g === void 0 ? void 0 : _g.pitch) {
1138
+ if ((_j = entity === null || entity === void 0 ? void 0 : entity.transform) === null || _j === void 0 ? void 0 : _j.pitch) {
1118
1139
  pitch = entity.transform.pitch;
1119
1140
  }
1120
- else if ((_h = tSettings === null || tSettings === void 0 ? void 0 : tSettings.transform) === null || _h === void 0 ? void 0 : _h.pitch) {
1141
+ else if ((_k = tSettings === null || tSettings === void 0 ? void 0 : tSettings.transform) === null || _k === void 0 ? void 0 : _k.pitch) {
1121
1142
  pitch = tSettings.transform.pitch;
1122
1143
  }
1123
- if ((_j = entity === null || entity === void 0 ? void 0 : entity.transform) === null || _j === void 0 ? void 0 : _j.roll) {
1144
+ if ((_l = entity === null || entity === void 0 ? void 0 : entity.transform) === null || _l === void 0 ? void 0 : _l.roll) {
1124
1145
  roll = entity.transform.roll;
1125
1146
  }
1126
- else if ((_k = tSettings === null || tSettings === void 0 ? void 0 : tSettings.transform) === null || _k === void 0 ? void 0 : _k.roll) {
1147
+ else if ((_m = tSettings === null || tSettings === void 0 ? void 0 : tSettings.transform) === null || _m === void 0 ? void 0 : _m.roll) {
1127
1148
  roll = tSettings.transform.roll;
1128
1149
  }
1129
1150
  heading = +heading;
@@ -1628,6 +1649,43 @@
1628
1649
  }
1629
1650
  return data;
1630
1651
  }
1652
+ function getCylinderStyleExtrusion(style, entity, tags, heightRef) {
1653
+ var _a;
1654
+ if (!style) {
1655
+ return null;
1656
+ }
1657
+ try {
1658
+ var extrusion = +bruceModels.Calculator.GetNumber(style, entity, tags);
1659
+ if (!extrusion && extrusion != 0) {
1660
+ return null;
1661
+ }
1662
+ /*
1663
+ Cesium extrudes in strange way.
1664
+ If you want something that is 50 meters above sea, and 5 meters tall,
1665
+ You need to extrude by 55 meters, if you extrude by 5 it will extrude from sea and look flat.
1666
+ */
1667
+ var height = EnsureNumber((_a = entity.location) === null || _a === void 0 ? void 0 : _a.altitude, 0);
1668
+ return heightRef != Cesium.HeightReference.CLAMP_TO_GROUND ? extrusion + height : extrusion;
1669
+ }
1670
+ catch (e) {
1671
+ console.error(e);
1672
+ }
1673
+ return 0;
1674
+ }
1675
+ function getCylinderExtrusion(entity, tags, heightRef, style) {
1676
+ var data = {
1677
+ value: undefined,
1678
+ exHeightRef: heightRef == Cesium.HeightReference.CLAMP_TO_GROUND ? Cesium.HeightReference.RELATIVE_TO_GROUND : heightRef
1679
+ };
1680
+ var extrusion = getCylinderStyleExtrusion(style, entity, tags, heightRef);
1681
+ if (extrusion) {
1682
+ data.value = extrusion;
1683
+ }
1684
+ if (data.value != undefined) {
1685
+ data.value = EnsureNumber(data.value);
1686
+ }
1687
+ return data;
1688
+ }
1631
1689
  function getHeightRef(style, defaultStyle) {
1632
1690
  var _a;
1633
1691
  var heightRef = defaultStyle == null ? Cesium.HeightReference.CLAMP_TO_GROUND : defaultStyle;
@@ -1860,7 +1918,6 @@
1860
1918
  return __generator(this, function (_j) {
1861
1919
  switch (_j.label) {
1862
1920
  case 0:
1863
- console.log("Rendering entities", params);
1864
1921
  groupRenderParams = {
1865
1922
  apiGetter: params.apiGetter,
1866
1923
  viewer: params.viewer,
@@ -2112,7 +2169,7 @@
2112
2169
  (function (Point) {
2113
2170
  function Render(params) {
2114
2171
  return __awaiter(this, void 0, void 0, function () {
2115
- var entity, style, type, cEntity, siblings, iconUrlRows, icon, iconUrl, res, e_4, iconScale, disableDepthTest, heightRef, radius, bFill, cFill, outline, bOutline, cOutline, outlineWidth, outlineHeight, fillHeight, pos, cartographicPosition, bColor, cColor, size, heightRef;
2172
+ 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;
2116
2173
  return __generator(this, function (_a) {
2117
2174
  switch (_a.label) {
2118
2175
  case 0:
@@ -2209,35 +2266,60 @@
2209
2266
  bFill = style.CylinderFillColor ? bruceModels.Calculator.GetColor(style.CylinderFillColor, entity, params.tags) : null;
2210
2267
  cFill = bFill ? colorToCColor(bFill) : Cesium.Color.RED;
2211
2268
  outline = Boolean(style.CylinderBorderEnabled);
2212
- bOutline = style.CylinderBorderColor ? bruceModels.Calculator.GetColor(style.CylinderBorderColor, entity, params.tags) : null;
2213
- cOutline = bOutline ? colorToCColor(bOutline) : Cesium.Color.BLACK;
2214
- outlineWidth = EnsureNumber(bruceModels.Calculator.GetNumber(style.CylinderBorderWidth, entity, params.tags), 1);
2215
- outlineHeight = EnsureNumber(bruceModels.Calculator.GetNumber(style.CylinderBorderExtrusion, entity, params.tags), 0);
2216
- fillHeight = EnsureNumber(bruceModels.Calculator.GetNumber(style.CylinderFillExtrusion, entity, params.tags));
2217
- pos = exports.EntityUtils.GetPos({
2269
+ cOutline = null;
2270
+ outlineWidth = 1;
2271
+ if (outline) {
2272
+ bOutline = style.CylinderBorderColor ? bruceModels.Calculator.GetColor(style.CylinderBorderColor, entity, params.tags) : null;
2273
+ cOutline = bOutline ? colorToCColor(bOutline) : Cesium.Color.BLACK;
2274
+ outlineWidth = EnsureNumber(bruceModels.Calculator.GetNumber(style.CylinderBorderWidth, entity, params.tags), 1);
2275
+ }
2276
+ heightRef = getHeightRef(style);
2277
+ pos3d = exports.EntityUtils.GetPos({
2218
2278
  viewer: params.viewer,
2219
2279
  entity: entity,
2220
- recordHeightRef: Cesium.HeightReference.RELATIVE_TO_GROUND,
2221
- returnHeightRef: Cesium.HeightReference.RELATIVE_TO_GROUND
2280
+ recordHeightRef: heightRef,
2281
+ returnHeightRef: heightRef
2222
2282
  });
2223
- // Adjust the position to consider half the height of the cylinder
2224
- if (pos) {
2225
- cartographicPosition = Cesium.Cartographic.fromCartesian(pos);
2226
- cartographicPosition.height += fillHeight / 2;
2227
- pos = Cesium.Cartographic.toCartesian(cartographicPosition);
2228
- }
2283
+ extrusion = getCylinderExtrusion(entity, params.tags, heightRef, style.CylinderFillExtrusion);
2229
2284
  cEntity = new Cesium.Entity({
2230
- position: pos,
2231
- cylinder: {
2232
- length: fillHeight,
2233
- topRadius: radius,
2234
- bottomRadius: radius,
2285
+ ellipse: {
2286
+ semiMajorAxis: radius,
2287
+ semiMinorAxis: radius,
2235
2288
  material: cFill,
2236
- outline: outline,
2237
- outlineColor: cOutline,
2238
- outlineWidth: outlineWidth
2239
- }
2289
+ outlineWidth: null,
2290
+ extrudedHeight: extrusion.value,
2291
+ heightReference: heightRef,
2292
+ extrudedHeightReference: extrusion.exHeightRef,
2293
+ height: Cesium.Cartographic.fromCartesian(pos3d).height,
2294
+ zIndex: 1,
2295
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
2296
+ },
2297
+ position: pos3d === null || pos3d === void 0 ? void 0 : pos3d.clone(),
2298
+ show: true
2240
2299
  });
2300
+ if (outline && outlineWidth > 0) {
2301
+ outlineExtrusion = getCylinderExtrusion(entity, params.tags, heightRef, style.CylinderBorderExtrusion);
2302
+ // If this doesn't have its own extrusion, we must make it match the sibling.
2303
+ // This way they render in a uniform way.
2304
+ if (!outlineExtrusion.value && extrusion.value) {
2305
+ outlineExtrusion.exHeightRef = extrusion.exHeightRef;
2306
+ }
2307
+ siblings.push(new Cesium.Entity({
2308
+ ellipse: {
2309
+ semiMajorAxis: radius + outlineWidth,
2310
+ semiMinorAxis: radius + outlineWidth,
2311
+ material: cOutline,
2312
+ outlineWidth: undefined,
2313
+ extrudedHeight: outlineExtrusion.value,
2314
+ heightReference: heightRef,
2315
+ extrudedHeightReference: outlineExtrusion.exHeightRef,
2316
+ height: Cesium.Cartographic.fromCartesian(pos3d).height,
2317
+ zIndex: 2,
2318
+ distanceDisplayCondition: getDisplayCondition(params.minDistance, params.maxDistance)
2319
+ },
2320
+ position: pos3d === null || pos3d === void 0 ? void 0 : pos3d.clone()
2321
+ }));
2322
+ }
2241
2323
  }
2242
2324
  if (!cEntity) {
2243
2325
  bColor = style.color ? bruceModels.Calculator.GetColor(style.color, entity, params.tags) : null;
@@ -2266,8 +2348,6 @@
2266
2348
  }),
2267
2349
  show: true
2268
2350
  });
2269
- console.log("Created point", cEntity);
2270
- debugger;
2271
2351
  }
2272
2352
  if (cEntity) {
2273
2353
  cEntity._siblingGraphics = siblings;
@@ -14942,7 +15022,7 @@
14942
15022
  ViewerUtils.CreateWidgets = CreateWidgets;
14943
15023
  })(exports.ViewerUtils || (exports.ViewerUtils = {}));
14944
15024
 
14945
- var VERSION$1 = "2.5.9";
15025
+ var VERSION$1 = "2.6.4";
14946
15026
 
14947
15027
  exports.VERSION = VERSION$1;
14948
15028
  exports.CesiumViewMonitor = CesiumViewMonitor;