bruce-cesium 0.5.4 → 0.5.6

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,5 +1,5 @@
1
1
  import { BruceEvent, Cartes, Carto, Geometry, ZoomControl, Style, EntityTag, Calculator, EntityLod, EntityType, ClientFile, DelayQueue, Entity as Entity$1, BatchedDataGetter, ObjectUtils, Tileset, EntityCoords, EntityFilterGetter, EntitySource, MenuItem, ProjectView, ProjectViewBookmark, ProjectViewTile, ProjectViewLegacyTile, TilesetExtMapTiles, ProgramKey, Camera, MathUtils } from 'bruce-models';
2
- import { Cartesian2, Cartographic, Math as Math$1, Color, HeightReference, Cartesian3, Entity, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, PolygonHierarchy, ShadowMode, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Primitive, Cesium3DTileFeature, HeadingPitchRange, OrthographicFrustum, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, Matrix4, Cesium3DTileset, EllipsoidGeodesic, ColorMaterialProperty, Rectangle, Matrix3, EasingFunction, GeometryInstance, JulianDate, createOsmBuildings, Cesium3DTileStyle } from 'cesium';
2
+ import { Color, HeightReference, Cartographic, Cartesian3, Entity, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, PolygonHierarchy, ShadowMode, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Primitive, Cesium3DTileFeature, Cartesian2, HeadingPitchRange, OrthographicFrustum, Math as Math$1, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, Matrix4, Cesium3DTileset, EllipsoidGeodesic, ColorMaterialProperty, Rectangle, Matrix3, EasingFunction, GeometryInstance, JulianDate, createOsmBuildings, Cesium3DTileStyle } from 'cesium';
3
3
 
4
4
  var TIME_LAG = 300;
5
5
  var POSITION_CHECK_TIMER = 950;
@@ -436,17 +436,27 @@ function traverseEntity(cEntity, arr) {
436
436
  arr.push(cEntity);
437
437
  }
438
438
  var ORG_OPACITY_KEY = "_org_opacity_";
439
+ var NEW_OPACITY_KEY = "_new_opacity_";
439
440
  function getColor(viewer, material) {
440
- var _a;
441
- var color;
442
- if (material instanceof Color) {
443
- color = material;
444
- }
445
- else if ((_a = material) === null || _a === void 0 ? void 0 : _a.color) {
446
- var anyCol = material.color;
447
- color = anyCol.getValue ? anyCol.getValue(viewer.scene.lastRenderTime) : anyCol;
441
+ var _a, _b;
442
+ function findColor() {
443
+ var _a;
444
+ if (!material) {
445
+ return Color.WHITE;
446
+ }
447
+ if (material.getValue) {
448
+ material = material.getValue(viewer.scene.lastRenderTime);
449
+ }
450
+ if (material instanceof Color) {
451
+ return material;
452
+ }
453
+ var tmp = (_a = material) === null || _a === void 0 ? void 0 : _a.color;
454
+ if (tmp === null || tmp === void 0 ? void 0 : tmp.getValue) {
455
+ tmp = tmp.getValue(viewer.scene.lastRenderTime);
456
+ }
457
+ return tmp ? tmp : Color.WHITE;
448
458
  }
449
- return color;
459
+ return (_b = (_a = findColor()) === null || _a === void 0 ? void 0 : _a.clone) === null || _b === void 0 ? void 0 : _b.call(_a);
450
460
  }
451
461
  function applyOpacityToColor(viewer, opacity, material) {
452
462
  var color = getColor(viewer, material);
@@ -455,44 +465,82 @@ function applyOpacityToColor(viewer, opacity, material) {
455
465
  }
456
466
  return color;
457
467
  }
458
- function applyOpacityToGraphic(viewer, entity, graphicKey, opacity) {
459
- var color = applyOpacityToColor(viewer, opacity, entity[graphicKey].material);
468
+ function applyOpacityToGraphic(viewer, entity, graphicKey, materialKey, opacity) {
469
+ var color = applyOpacityToColor(viewer, opacity, entity[graphicKey][materialKey]);
460
470
  if (color) {
461
- entity[graphicKey].material = new ColorMaterialProperty(color);
471
+ entity[graphicKey][materialKey] = materialKey == "material" ? new ColorMaterialProperty(color) : color;
462
472
  }
463
473
  }
464
474
  function revertAppliedEntityOpacity(viewer, entity) {
465
- function processKey(graphicKey) {
466
- if (entity[graphicKey]) {
467
- var orgOpacity = entity[graphicKey][ORG_OPACITY_KEY];
468
- if (orgOpacity != null) {
469
- applyOpacityToGraphic(viewer, entity, graphicKey, orgOpacity);
475
+ entity[NEW_OPACITY_KEY] = null;
476
+ if (entity instanceof Entity) {
477
+ var processKey = function (graphicKey, materialKey) {
478
+ if (materialKey === void 0) { materialKey = "material"; }
479
+ if (entity[graphicKey]) {
480
+ var orgOpacity = entity[graphicKey][ORG_OPACITY_KEY];
481
+ if (orgOpacity != null) {
482
+ applyOpacityToGraphic(viewer, entity, graphicKey, materialKey, orgOpacity);
483
+ }
470
484
  entity[graphicKey][ORG_OPACITY_KEY] = null;
471
485
  }
486
+ };
487
+ processKey("polygon");
488
+ processKey("polyline");
489
+ processKey("point", "color");
490
+ processKey("ellipse");
491
+ processKey("model", "color");
492
+ }
493
+ else if (entity instanceof Cesium3DTileFeature) {
494
+ var orgOpacity = entity[ORG_OPACITY_KEY];
495
+ if (orgOpacity != null) {
496
+ var color = entity.color ? entity.color.clone() : new Color();
497
+ color.alpha = orgOpacity;
498
+ entity.color = color;
472
499
  }
500
+ entity[ORG_OPACITY_KEY] = null;
473
501
  }
474
- processKey("polygon");
475
- processKey("polyline");
476
- processKey("point");
477
- processKey("ellipse");
478
- processKey("model");
479
502
  }
480
503
  function applyOpacityToEntity(viewer, opacity, entity) {
481
- function processKey(graphicKey) {
482
- var _a;
483
- if (entity[graphicKey]) {
484
- var orgOpacity = entity[graphicKey][ORG_OPACITY_KEY];
485
- if (orgOpacity == null) {
486
- entity[graphicKey][ORG_OPACITY_KEY] = (_a = getColor(viewer, entity[graphicKey].material)) === null || _a === void 0 ? void 0 : _a.alpha;
504
+ entity[NEW_OPACITY_KEY] = opacity;
505
+ if (entity instanceof Entity) {
506
+ var processKey = function (graphicKey, materialKey) {
507
+ var _a;
508
+ if (materialKey === void 0) { materialKey = "material"; }
509
+ if (entity[graphicKey]) {
510
+ var orgOpacity = entity[graphicKey][ORG_OPACITY_KEY];
511
+ if (orgOpacity == null) {
512
+ entity[graphicKey][ORG_OPACITY_KEY] = (_a = getColor(viewer, entity[graphicKey][materialKey])) === null || _a === void 0 ? void 0 : _a.alpha;
513
+ }
514
+ if (orgOpacity == null) {
515
+ orgOpacity = 1;
516
+ }
517
+ applyOpacityToGraphic(viewer, entity, graphicKey, materialKey, opacity * orgOpacity);
487
518
  }
488
- applyOpacityToGraphic(viewer, entity, graphicKey, opacity);
519
+ };
520
+ processKey("polygon");
521
+ processKey("polyline");
522
+ processKey("point", "color");
523
+ processKey("ellipse");
524
+ processKey("model", "color");
525
+ }
526
+ else if (entity instanceof Cesium3DTileFeature) {
527
+ var orgOpacity = entity[ORG_OPACITY_KEY];
528
+ if (orgOpacity == null) {
529
+ entity[ORG_OPACITY_KEY] = entity.color ? entity.color.alpha : 1;
530
+ }
531
+ if (!orgOpacity) {
532
+ orgOpacity = 1;
489
533
  }
534
+ var color = entity.color ? entity.color.clone() : new Color();
535
+ color.alpha = opacity * orgOpacity;
536
+ if (color.equals(Color.WHITE)) {
537
+ color.blue = 0.0001;
538
+ }
539
+ entity.color = color;
490
540
  }
491
- processKey("polygon");
492
- processKey("polyline");
493
- processKey("point");
494
- processKey("ellipse");
495
- processKey("model");
541
+ }
542
+ function findOpacity(entity) {
543
+ return entity[NEW_OPACITY_KEY];
496
544
  }
497
545
  var EntityUtils;
498
546
  (function (EntityUtils) {
@@ -685,6 +733,17 @@ var EntityUtils;
685
733
  revertAppliedEntityOpacity(viewer, entity);
686
734
  }
687
735
  EntityUtils.RevertOpacity = RevertOpacity;
736
+ /**
737
+ * Gets opacity of the entity.
738
+ * This does not count opacity that it was rendered with.
739
+ * This is the opacity that was set post-rendering.
740
+ * @param viewer
741
+ * @param entity
742
+ */
743
+ function GetOpacity(entity) {
744
+ return findOpacity(entity);
745
+ }
746
+ EntityUtils.GetOpacity = GetOpacity;
688
747
  })(EntityUtils || (EntityUtils = {}));
689
748
 
690
749
  var RenderManager;
@@ -1932,67 +1991,89 @@ function unmarkEntity(visual) {
1932
1991
  }
1933
1992
  }
1934
1993
  }
1935
- function select(visual) {
1994
+ var ORG_COLOR_KEY = "_org_color_";
1995
+ function select(viewer, visual) {
1996
+ var _a;
1936
1997
  var color = Color.fromAlpha(Color.YELLOW, 0.5);
1937
1998
  if (visual instanceof Entity) {
1938
1999
  var entities = EntityUtils.GatherEntity(visual);
1939
- for (var i = 0; i < entities.length; i++) {
1940
- var cEntity = entities[i];
1941
- if (cEntity.point) {
1942
- cEntity.point._orgColor = cEntity.point.color;
1943
- cEntity.point.color = color.clone();
1944
- }
1945
- if (cEntity.polyline) {
1946
- cEntity.polyline._orgColor = cEntity.polyline.material;
1947
- cEntity.polyline.material = color.clone();
1948
- }
1949
- if (cEntity.polygon) {
1950
- cEntity.polygon._orgColor = cEntity.polygon.material;
1951
- cEntity.polygon.material = color.clone();
1952
- }
1953
- if (cEntity.model) {
1954
- cEntity.model._orgColor = cEntity.model.color;
1955
- cEntity.model.color = color.clone();
1956
- }
1957
- if (cEntity.billboard) {
1958
- cEntity.billboard._orgColor = cEntity.billboard.color;
1959
- cEntity.billboard.color = color.clone();
2000
+ var keyMapping = {
2001
+ "point": "color",
2002
+ "polygon": "material",
2003
+ "polyline": "material",
2004
+ "model": "color",
2005
+ "billboard": "color"
2006
+ };
2007
+ var _loop_1 = function (i) {
2008
+ var entity = entities[i];
2009
+ var processGraphic = function (graphicKey, materialKey) {
2010
+ if (entity[graphicKey]) {
2011
+ if (entity[graphicKey][ORG_COLOR_KEY] == null) {
2012
+ entity[graphicKey][ORG_COLOR_KEY] = entity[graphicKey][materialKey];
2013
+ }
2014
+ entity[graphicKey][materialKey] = color.clone();
2015
+ }
2016
+ };
2017
+ for (var key in keyMapping) {
2018
+ var map = keyMapping[key];
2019
+ processGraphic(key, map);
1960
2020
  }
2021
+ };
2022
+ for (var i = 0; i < entities.length; i++) {
2023
+ _loop_1(i);
1961
2024
  }
1962
2025
  }
1963
2026
  else if (visual instanceof Primitive) ;
1964
2027
  else if (visual instanceof Cesium3DTileFeature) {
1965
- var cPrim = visual;
1966
- cPrim._orgColor = cPrim.color;
1967
- cPrim.color = color.clone();
2028
+ var orgColor = visual[ORG_COLOR_KEY];
2029
+ if (orgColor == null) {
2030
+ orgColor = visual.color;
2031
+ visual[ORG_COLOR_KEY] = (_a = orgColor === null || orgColor === void 0 ? void 0 : orgColor.clone) === null || _a === void 0 ? void 0 : _a.call(orgColor);
2032
+ }
2033
+ visual.color = color.clone();
2034
+ }
2035
+ var opacity = EntityUtils.GetOpacity(visual);
2036
+ if (opacity != null) {
2037
+ EntityUtils.SetOpacity(viewer, visual, opacity);
1968
2038
  }
1969
2039
  }
1970
- function deselect(visual) {
2040
+ function deselect(viewer, visual) {
1971
2041
  if (visual instanceof Entity) {
1972
2042
  var entities = EntityUtils.GatherEntity(visual);
1973
- for (var i = 0; i < entities.length; i++) {
1974
- var cEntity = entities[i];
1975
- if (cEntity.point) {
1976
- cEntity.point.color = cEntity.point._orgColor;
1977
- }
1978
- if (cEntity.polyline) {
1979
- cEntity.polyline.material = cEntity.polyline._orgColor;
1980
- }
1981
- if (cEntity.polygon) {
1982
- cEntity.polygon.material = cEntity.polygon._orgColor;
1983
- }
1984
- if (cEntity.model) {
1985
- cEntity.model.color = cEntity.model._orgColor;
1986
- }
1987
- if (cEntity.billboard) {
1988
- cEntity.billboard.color = cEntity.billboard._orgColor;
2043
+ var keyMapping = {
2044
+ "point": "color",
2045
+ "polygon": "material",
2046
+ "polyline": "material",
2047
+ "model": "color",
2048
+ "billboard": "color"
2049
+ };
2050
+ var _loop_2 = function (i) {
2051
+ var entity = entities[i];
2052
+ var processGraphic = function (graphicKey, materialKey) {
2053
+ var _a;
2054
+ if ((_a = entity[graphicKey]) === null || _a === void 0 ? void 0 : _a[ORG_COLOR_KEY]) {
2055
+ entity[graphicKey][materialKey] = entity[graphicKey][ORG_COLOR_KEY];
2056
+ }
2057
+ };
2058
+ for (var key in keyMapping) {
2059
+ var map = keyMapping[key];
2060
+ processGraphic(key, map);
1989
2061
  }
2062
+ };
2063
+ for (var i = 0; i < entities.length; i++) {
2064
+ _loop_2(i);
1990
2065
  }
1991
2066
  }
1992
2067
  else if (visual instanceof Primitive) ;
1993
2068
  else if (visual instanceof Cesium3DTileFeature) {
1994
- var cPrim = visual;
1995
- cPrim.color = cPrim._orgColor;
2069
+ var orgColor = visual[ORG_COLOR_KEY];
2070
+ if (orgColor != null) {
2071
+ visual.color = orgColor;
2072
+ }
2073
+ }
2074
+ var opacity = EntityUtils.GetOpacity(visual);
2075
+ if (opacity != null) {
2076
+ EntityUtils.SetOpacity(viewer, visual, opacity);
1996
2077
  }
1997
2078
  }
1998
2079
  /**
@@ -2073,7 +2154,7 @@ var VisualsRegister;
2073
2154
  if (regos) {
2074
2155
  for (var i = 0; i < regos.length; i++) {
2075
2156
  var rego = regos[i];
2076
- select(rego.visual);
2157
+ select(this.viewer, rego.visual);
2077
2158
  }
2078
2159
  }
2079
2160
  }
@@ -2086,7 +2167,7 @@ var VisualsRegister;
2086
2167
  if (regos) {
2087
2168
  for (var i = 0; i < regos.length; i++) {
2088
2169
  var rego = regos[i];
2089
- deselect(rego.visual);
2170
+ deselect(this.viewer, rego.visual);
2090
2171
  }
2091
2172
  }
2092
2173
  }
@@ -2101,7 +2182,7 @@ var VisualsRegister;
2101
2182
  if (regos) {
2102
2183
  for (var i_1 = 0; i_1 < regos.length; i_1++) {
2103
2184
  var rego = regos[i_1];
2104
- deselect(rego.visual);
2185
+ deselect(this.viewer, rego.visual);
2105
2186
  }
2106
2187
  }
2107
2188
  }
@@ -2117,16 +2198,26 @@ var VisualsRegister;
2117
2198
  markEntity(this, rego, rego.visual);
2118
2199
  updateEntity(this.viewer, this.rego[entityId], this.GetAddons(entityId));
2119
2200
  if (this.selectedIds.includes(entityId)) {
2120
- select(rego.visual);
2201
+ select(this.viewer, rego.visual);
2121
2202
  }
2122
2203
  (_b = this.onUpdate) === null || _b === void 0 ? void 0 : _b.Trigger({ rego: rego, isAdding: true });
2123
2204
  };
2205
+ /**
2206
+ * Locates a visual corresponding to a given entity id.
2207
+ * If no menu item id is provided, then it will pick the "best" one.
2208
+ * @param entityId
2209
+ * @param menuItemId
2210
+ * @returns
2211
+ */
2124
2212
  Register.prototype.GetRego = function (entityId, menuItemId) {
2125
2213
  var entityRegos = this.rego[entityId];
2126
2214
  if (!entityRegos) {
2127
2215
  return [];
2128
2216
  }
2129
- return entityRegos.find(function (r) { return r.menuItemId === menuItemId; });
2217
+ if (menuItemId) {
2218
+ return entityRegos.find(function (r) { return r.menuItemId === menuItemId; });
2219
+ }
2220
+ return entityRegos.find(function (x) { return x.best; });
2130
2221
  };
2131
2222
  Register.prototype.GetRegos = function (entityId) {
2132
2223
  var entityRegos = this.rego[entityId];