bruce-cesium 0.5.3 → 0.5.5
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.
- package/dist/bruce-cesium.es5.js +226 -2
- package/dist/bruce-cesium.es5.js.map +1 -1
- package/dist/bruce-cesium.umd.js +225 -1
- package/dist/bruce-cesium.umd.js.map +1 -1
- package/dist/lib/rendering/visuals-register.js +11 -1
- package/dist/lib/rendering/visuals-register.js.map +1 -1
- package/dist/lib/utils/entity-utils.js +214 -0
- package/dist/lib/utils/entity-utils.js.map +1 -1
- package/dist/types/rendering/visuals-register.d.ts +8 -1
- package/dist/types/utils/entity-utils.d.ts +31 -0
- package/package.json +1 -1
package/dist/bruce-cesium.es5.js
CHANGED
|
@@ -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,
|
|
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';
|
|
3
3
|
|
|
4
4
|
var TIME_LAG = 300;
|
|
5
5
|
var POSITION_CHECK_TIMER = 950;
|
|
@@ -435,6 +435,100 @@ function traverseEntity(cEntity, arr) {
|
|
|
435
435
|
}
|
|
436
436
|
arr.push(cEntity);
|
|
437
437
|
}
|
|
438
|
+
var ORG_OPACITY_KEY = "_org_opacity_";
|
|
439
|
+
var NEW_OPACITY_KEY = "_new_opacity_";
|
|
440
|
+
function getColor(viewer, material) {
|
|
441
|
+
var _a;
|
|
442
|
+
var color;
|
|
443
|
+
if (material instanceof Color) {
|
|
444
|
+
color = material;
|
|
445
|
+
}
|
|
446
|
+
else if ((_a = material) === null || _a === void 0 ? void 0 : _a.color) {
|
|
447
|
+
var anyCol = material.color;
|
|
448
|
+
color = anyCol.getValue ? anyCol.getValue(viewer.scene.lastRenderTime) : anyCol;
|
|
449
|
+
}
|
|
450
|
+
return color;
|
|
451
|
+
}
|
|
452
|
+
function applyOpacityToColor(viewer, opacity, material) {
|
|
453
|
+
var color = getColor(viewer, material);
|
|
454
|
+
if (color) {
|
|
455
|
+
color.alpha = opacity;
|
|
456
|
+
}
|
|
457
|
+
return color;
|
|
458
|
+
}
|
|
459
|
+
function applyOpacityToGraphic(viewer, entity, graphicKey, opacity) {
|
|
460
|
+
var color = applyOpacityToColor(viewer, opacity, entity[graphicKey].material);
|
|
461
|
+
if (color) {
|
|
462
|
+
entity[graphicKey].material = new ColorMaterialProperty(color);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function revertAppliedEntityOpacity(viewer, entity) {
|
|
466
|
+
entity[NEW_OPACITY_KEY] = null;
|
|
467
|
+
if (entity instanceof Entity) {
|
|
468
|
+
var processKey = function (graphicKey) {
|
|
469
|
+
if (entity[graphicKey]) {
|
|
470
|
+
var orgOpacity = entity[graphicKey][ORG_OPACITY_KEY];
|
|
471
|
+
if (orgOpacity != null) {
|
|
472
|
+
applyOpacityToGraphic(viewer, entity, graphicKey, orgOpacity);
|
|
473
|
+
}
|
|
474
|
+
entity[graphicKey][ORG_OPACITY_KEY] = null;
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
processKey("polygon");
|
|
478
|
+
processKey("polyline");
|
|
479
|
+
processKey("point");
|
|
480
|
+
processKey("ellipse");
|
|
481
|
+
processKey("model");
|
|
482
|
+
}
|
|
483
|
+
else if (entity instanceof Cesium3DTileFeature) {
|
|
484
|
+
var orgOpacity = entity[ORG_OPACITY_KEY];
|
|
485
|
+
if (orgOpacity != null) {
|
|
486
|
+
var color = entity.color ? entity.color.clone() : new Color();
|
|
487
|
+
color.alpha = orgOpacity;
|
|
488
|
+
entity.color = color;
|
|
489
|
+
}
|
|
490
|
+
entity[ORG_OPACITY_KEY] = null;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
function applyOpacityToEntity(viewer, opacity, entity) {
|
|
494
|
+
entity[NEW_OPACITY_KEY] = opacity;
|
|
495
|
+
if (entity instanceof Entity) {
|
|
496
|
+
var processKey = function (graphicKey) {
|
|
497
|
+
var _a;
|
|
498
|
+
if (entity[graphicKey]) {
|
|
499
|
+
var orgOpacity = entity[graphicKey][ORG_OPACITY_KEY];
|
|
500
|
+
if (orgOpacity == null) {
|
|
501
|
+
entity[graphicKey][ORG_OPACITY_KEY] = (_a = getColor(viewer, entity[graphicKey].material)) === null || _a === void 0 ? void 0 : _a.alpha;
|
|
502
|
+
}
|
|
503
|
+
if (orgOpacity == null) {
|
|
504
|
+
orgOpacity = 1;
|
|
505
|
+
}
|
|
506
|
+
applyOpacityToGraphic(viewer, entity, graphicKey, opacity * orgOpacity);
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
processKey("polygon");
|
|
510
|
+
processKey("polyline");
|
|
511
|
+
processKey("point");
|
|
512
|
+
processKey("ellipse");
|
|
513
|
+
processKey("model");
|
|
514
|
+
}
|
|
515
|
+
else if (entity instanceof Cesium3DTileFeature) {
|
|
516
|
+
var orgOpacity = entity[ORG_OPACITY_KEY];
|
|
517
|
+
if (orgOpacity == null) {
|
|
518
|
+
entity[ORG_OPACITY_KEY] = entity.color ? entity.color.alpha : 1;
|
|
519
|
+
}
|
|
520
|
+
if (!orgOpacity) {
|
|
521
|
+
orgOpacity = 1;
|
|
522
|
+
}
|
|
523
|
+
var color = entity.color ? entity.color.clone() : new Color();
|
|
524
|
+
entity.color.alpha = opacity * orgOpacity;
|
|
525
|
+
entity.color = color;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function findOpacity(entity) {
|
|
529
|
+
var _a;
|
|
530
|
+
return (_a = entity[NEW_OPACITY_KEY]) !== null && _a !== void 0 ? _a : 1;
|
|
531
|
+
}
|
|
438
532
|
var EntityUtils;
|
|
439
533
|
(function (EntityUtils) {
|
|
440
534
|
/**
|
|
@@ -517,6 +611,126 @@ var EntityUtils;
|
|
|
517
611
|
return [entity];
|
|
518
612
|
}
|
|
519
613
|
EntityUtils.GatherEntity = GatherEntity;
|
|
614
|
+
/**
|
|
615
|
+
* Looks at given entities with least amount of movement.
|
|
616
|
+
* @param viewer
|
|
617
|
+
* @param entities
|
|
618
|
+
*/
|
|
619
|
+
function LookAtEntities(viewer, entities) {
|
|
620
|
+
var _a = [Rectangle, Cartographic, Cartesian3, Matrix3, Matrix4, EasingFunction], C3 = _a[2], M4 = _a[4];
|
|
621
|
+
var cutoffDistance = 2000;
|
|
622
|
+
var hoverHeight = 2000;
|
|
623
|
+
var duration = 0.5;
|
|
624
|
+
var centers = function (p) {
|
|
625
|
+
var PM = p.modelMatrix;
|
|
626
|
+
var instances = (function (i) { return (i instanceof GeometryInstance ? [i] : i); })(p.geometryInstances);
|
|
627
|
+
return instances.map(function (g) {
|
|
628
|
+
var _M = M4.multiply(PM, g.modelMatrix, new M4);
|
|
629
|
+
var G = g.geometry;
|
|
630
|
+
var _p = G.attributes.position;
|
|
631
|
+
var b = G.boundingSphere;
|
|
632
|
+
return [b.center, b.radius];
|
|
633
|
+
});
|
|
634
|
+
};
|
|
635
|
+
var currentTime = JulianDate.now();
|
|
636
|
+
var target = entities.flatMap(function (e) {
|
|
637
|
+
var _a;
|
|
638
|
+
if (e instanceof Cartesian3) {
|
|
639
|
+
return [[e, 0]];
|
|
640
|
+
}
|
|
641
|
+
if (e instanceof Entity) {
|
|
642
|
+
return [[(_a = e.position) === null || _a === void 0 ? void 0 : _a.getValue(currentTime), 0]];
|
|
643
|
+
}
|
|
644
|
+
if (e instanceof Primitive) {
|
|
645
|
+
return centers(e);
|
|
646
|
+
}
|
|
647
|
+
if (e instanceof Cesium3DTileFeature) {
|
|
648
|
+
var s = e.tileset.boundingSphere;
|
|
649
|
+
return [[s.center, s.radius]];
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
var bounds = function (list) {
|
|
653
|
+
var min = list[0][0];
|
|
654
|
+
var max = min;
|
|
655
|
+
for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
|
|
656
|
+
var _a = list_1[_i], p_1 = _a[0], r = _a[1];
|
|
657
|
+
var pMin = C3.subtract(p_1, new C3(r), new C3);
|
|
658
|
+
var pMax = C3.add(p_1, new C3(r), new C3);
|
|
659
|
+
min = C3.minimumByComponent(pMin, min, new C3);
|
|
660
|
+
max = C3.maximumByComponent(pMax, max, new C3);
|
|
661
|
+
}
|
|
662
|
+
var c = C3.multiplyByScalar(C3.add(max, min, new C3), 0.5, new C3);
|
|
663
|
+
return c;
|
|
664
|
+
};
|
|
665
|
+
var center = bounds(target);
|
|
666
|
+
var orient = function (p) {
|
|
667
|
+
var d = C3.subtract(center, p, new C3);
|
|
668
|
+
var dir = C3.normalize(d, new C3);
|
|
669
|
+
var up = viewer.scene.globe.ellipsoid.geodeticSurfaceNormal(center);
|
|
670
|
+
return [p, dir, up];
|
|
671
|
+
};
|
|
672
|
+
var shorten = function (v, l) {
|
|
673
|
+
var c = l / C3.magnitude(v);
|
|
674
|
+
return C3.multiplyByScalar(v, c, new C3);
|
|
675
|
+
};
|
|
676
|
+
var camera = viewer.camera;
|
|
677
|
+
var _b = orient(camera.position), p = _b[0], direction = _b[1], up = _b[2];
|
|
678
|
+
var orientation = { direction: direction, up: up };
|
|
679
|
+
camera.flyTo({
|
|
680
|
+
destination: p,
|
|
681
|
+
orientation: orientation,
|
|
682
|
+
duration: duration,
|
|
683
|
+
complete: function () {
|
|
684
|
+
if (C3.distance(p, center) > cutoffDistance) {
|
|
685
|
+
var d = C3.subtract(p, center, new C3);
|
|
686
|
+
d = shorten(d, cutoffDistance);
|
|
687
|
+
var h = C3.multiplyByScalar(C3.normalize(up, new C3), hoverHeight, new C3);
|
|
688
|
+
d = C3.add(d, h, new C3);
|
|
689
|
+
d = shorten(d, cutoffDistance);
|
|
690
|
+
d = C3.add(d, center, new C3);
|
|
691
|
+
var _a = orient(d), direction_1 = _a[1], u = _a[2];
|
|
692
|
+
camera.flyTo({
|
|
693
|
+
destination: d,
|
|
694
|
+
orientation: { direction: direction_1, up: u }
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
EntityUtils.LookAtEntities = LookAtEntities;
|
|
701
|
+
/**
|
|
702
|
+
* Sets opacity of given entity.
|
|
703
|
+
* Opacity will be multiplied by original opacity.
|
|
704
|
+
* Setting opacity puts original opacity into a temporary storage which can be reverted into.
|
|
705
|
+
* @param viewer
|
|
706
|
+
* @param entity
|
|
707
|
+
* @param opacity
|
|
708
|
+
*/
|
|
709
|
+
function SetOpacity(viewer, entity, opacity) {
|
|
710
|
+
applyOpacityToEntity(viewer, opacity, entity);
|
|
711
|
+
}
|
|
712
|
+
EntityUtils.SetOpacity = SetOpacity;
|
|
713
|
+
/**
|
|
714
|
+
* Reverts opacity of given entity to original opacity.
|
|
715
|
+
* If opacity was not updated using "SetOpacity" then nothing will happen.
|
|
716
|
+
* @param viewer
|
|
717
|
+
* @param entity
|
|
718
|
+
*/
|
|
719
|
+
function RevertOpacity(viewer, entity) {
|
|
720
|
+
revertAppliedEntityOpacity(viewer, entity);
|
|
721
|
+
}
|
|
722
|
+
EntityUtils.RevertOpacity = RevertOpacity;
|
|
723
|
+
/**
|
|
724
|
+
* Gets opacity of the entity.
|
|
725
|
+
* This does not count opacity that it was rendered with.
|
|
726
|
+
* This is the opacity that was set post-rendering.
|
|
727
|
+
* @param viewer
|
|
728
|
+
* @param entity
|
|
729
|
+
*/
|
|
730
|
+
function getOpacity(entity) {
|
|
731
|
+
return findOpacity(entity);
|
|
732
|
+
}
|
|
733
|
+
EntityUtils.getOpacity = getOpacity;
|
|
520
734
|
})(EntityUtils || (EntityUtils = {}));
|
|
521
735
|
|
|
522
736
|
var RenderManager;
|
|
@@ -1953,12 +2167,22 @@ var VisualsRegister;
|
|
|
1953
2167
|
}
|
|
1954
2168
|
(_b = this.onUpdate) === null || _b === void 0 ? void 0 : _b.Trigger({ rego: rego, isAdding: true });
|
|
1955
2169
|
};
|
|
2170
|
+
/**
|
|
2171
|
+
* Locates a visual corresponding to a given entity id.
|
|
2172
|
+
* If no menu item id is provided, then it will pick the "best" one.
|
|
2173
|
+
* @param entityId
|
|
2174
|
+
* @param menuItemId
|
|
2175
|
+
* @returns
|
|
2176
|
+
*/
|
|
1956
2177
|
Register.prototype.GetRego = function (entityId, menuItemId) {
|
|
1957
2178
|
var entityRegos = this.rego[entityId];
|
|
1958
2179
|
if (!entityRegos) {
|
|
1959
2180
|
return [];
|
|
1960
2181
|
}
|
|
1961
|
-
|
|
2182
|
+
if (menuItemId) {
|
|
2183
|
+
return entityRegos.find(function (r) { return r.menuItemId === menuItemId; });
|
|
2184
|
+
}
|
|
2185
|
+
return entityRegos.find(function (x) { return x.best; });
|
|
1962
2186
|
};
|
|
1963
2187
|
Register.prototype.GetRegos = function (entityId) {
|
|
1964
2188
|
var entityRegos = this.rego[entityId];
|