bruce-cesium 0.5.3 → 0.5.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.
- package/dist/bruce-cesium.es5.js +169 -1
- package/dist/bruce-cesium.es5.js.map +1 -1
- package/dist/bruce-cesium.umd.js +168 -0
- package/dist/bruce-cesium.umd.js.map +1 -1
- package/dist/lib/utils/entity-utils.js +168 -0
- package/dist/lib/utils/entity-utils.js.map +1 -1
- package/dist/types/utils/entity-utils.d.ts +23 -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,65 @@ function traverseEntity(cEntity, arr) {
|
|
|
435
435
|
}
|
|
436
436
|
arr.push(cEntity);
|
|
437
437
|
}
|
|
438
|
+
var ORG_OPACITY_KEY = "_org_opacity_";
|
|
439
|
+
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;
|
|
448
|
+
}
|
|
449
|
+
return color;
|
|
450
|
+
}
|
|
451
|
+
function applyOpacityToColor(viewer, opacity, material) {
|
|
452
|
+
var color = getColor(viewer, material);
|
|
453
|
+
if (color) {
|
|
454
|
+
color.alpha = opacity;
|
|
455
|
+
}
|
|
456
|
+
return color;
|
|
457
|
+
}
|
|
458
|
+
function applyOpacityToGraphic(viewer, entity, graphicKey, opacity) {
|
|
459
|
+
var color = applyOpacityToColor(viewer, opacity, entity[graphicKey].material);
|
|
460
|
+
if (color) {
|
|
461
|
+
entity[graphicKey].material = new ColorMaterialProperty(color);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
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);
|
|
470
|
+
entity[graphicKey][ORG_OPACITY_KEY] = null;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
processKey("polygon");
|
|
475
|
+
processKey("polyline");
|
|
476
|
+
processKey("point");
|
|
477
|
+
processKey("ellipse");
|
|
478
|
+
processKey("model");
|
|
479
|
+
}
|
|
480
|
+
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;
|
|
487
|
+
}
|
|
488
|
+
applyOpacityToGraphic(viewer, entity, graphicKey, opacity);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
processKey("polygon");
|
|
492
|
+
processKey("polyline");
|
|
493
|
+
processKey("point");
|
|
494
|
+
processKey("ellipse");
|
|
495
|
+
processKey("model");
|
|
496
|
+
}
|
|
438
497
|
var EntityUtils;
|
|
439
498
|
(function (EntityUtils) {
|
|
440
499
|
/**
|
|
@@ -517,6 +576,115 @@ var EntityUtils;
|
|
|
517
576
|
return [entity];
|
|
518
577
|
}
|
|
519
578
|
EntityUtils.GatherEntity = GatherEntity;
|
|
579
|
+
/**
|
|
580
|
+
* Looks at given entities with least amount of movement.
|
|
581
|
+
* @param viewer
|
|
582
|
+
* @param entities
|
|
583
|
+
*/
|
|
584
|
+
function LookAtEntities(viewer, entities) {
|
|
585
|
+
var _a = [Rectangle, Cartographic, Cartesian3, Matrix3, Matrix4, EasingFunction], C3 = _a[2], M4 = _a[4];
|
|
586
|
+
var cutoffDistance = 2000;
|
|
587
|
+
var hoverHeight = 2000;
|
|
588
|
+
var duration = 0.5;
|
|
589
|
+
var centers = function (p) {
|
|
590
|
+
var PM = p.modelMatrix;
|
|
591
|
+
var instances = (function (i) { return (i instanceof GeometryInstance ? [i] : i); })(p.geometryInstances);
|
|
592
|
+
return instances.map(function (g) {
|
|
593
|
+
var _M = M4.multiply(PM, g.modelMatrix, new M4);
|
|
594
|
+
var G = g.geometry;
|
|
595
|
+
var _p = G.attributes.position;
|
|
596
|
+
var b = G.boundingSphere;
|
|
597
|
+
return [b.center, b.radius];
|
|
598
|
+
});
|
|
599
|
+
};
|
|
600
|
+
var currentTime = JulianDate.now();
|
|
601
|
+
var target = entities.flatMap(function (e) {
|
|
602
|
+
var _a;
|
|
603
|
+
if (e instanceof Cartesian3) {
|
|
604
|
+
return [[e, 0]];
|
|
605
|
+
}
|
|
606
|
+
if (e instanceof Entity) {
|
|
607
|
+
return [[(_a = e.position) === null || _a === void 0 ? void 0 : _a.getValue(currentTime), 0]];
|
|
608
|
+
}
|
|
609
|
+
if (e instanceof Primitive) {
|
|
610
|
+
return centers(e);
|
|
611
|
+
}
|
|
612
|
+
if (e instanceof Cesium3DTileFeature) {
|
|
613
|
+
var s = e.tileset.boundingSphere;
|
|
614
|
+
return [[s.center, s.radius]];
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
var bounds = function (list) {
|
|
618
|
+
var min = list[0][0];
|
|
619
|
+
var max = min;
|
|
620
|
+
for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
|
|
621
|
+
var _a = list_1[_i], p_1 = _a[0], r = _a[1];
|
|
622
|
+
var pMin = C3.subtract(p_1, new C3(r), new C3);
|
|
623
|
+
var pMax = C3.add(p_1, new C3(r), new C3);
|
|
624
|
+
min = C3.minimumByComponent(pMin, min, new C3);
|
|
625
|
+
max = C3.maximumByComponent(pMax, max, new C3);
|
|
626
|
+
}
|
|
627
|
+
var c = C3.multiplyByScalar(C3.add(max, min, new C3), 0.5, new C3);
|
|
628
|
+
return c;
|
|
629
|
+
};
|
|
630
|
+
var center = bounds(target);
|
|
631
|
+
var orient = function (p) {
|
|
632
|
+
var d = C3.subtract(center, p, new C3);
|
|
633
|
+
var dir = C3.normalize(d, new C3);
|
|
634
|
+
var up = viewer.scene.globe.ellipsoid.geodeticSurfaceNormal(center);
|
|
635
|
+
return [p, dir, up];
|
|
636
|
+
};
|
|
637
|
+
var shorten = function (v, l) {
|
|
638
|
+
var c = l / C3.magnitude(v);
|
|
639
|
+
return C3.multiplyByScalar(v, c, new C3);
|
|
640
|
+
};
|
|
641
|
+
var camera = viewer.camera;
|
|
642
|
+
var _b = orient(camera.position), p = _b[0], direction = _b[1], up = _b[2];
|
|
643
|
+
var orientation = { direction: direction, up: up };
|
|
644
|
+
camera.flyTo({
|
|
645
|
+
destination: p,
|
|
646
|
+
orientation: orientation,
|
|
647
|
+
duration: duration,
|
|
648
|
+
complete: function () {
|
|
649
|
+
if (C3.distance(p, center) > cutoffDistance) {
|
|
650
|
+
var d = C3.subtract(p, center, new C3);
|
|
651
|
+
d = shorten(d, cutoffDistance);
|
|
652
|
+
var h = C3.multiplyByScalar(C3.normalize(up, new C3), hoverHeight, new C3);
|
|
653
|
+
d = C3.add(d, h, new C3);
|
|
654
|
+
d = shorten(d, cutoffDistance);
|
|
655
|
+
d = C3.add(d, center, new C3);
|
|
656
|
+
var _a = orient(d), direction_1 = _a[1], u = _a[2];
|
|
657
|
+
camera.flyTo({
|
|
658
|
+
destination: d,
|
|
659
|
+
orientation: { direction: direction_1, up: u }
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
EntityUtils.LookAtEntities = LookAtEntities;
|
|
666
|
+
/**
|
|
667
|
+
* Sets opacity of given entity.
|
|
668
|
+
* Opacity will be multiplied by original opacity.
|
|
669
|
+
* Setting opacity puts original opacity into a temporary storage which can be reverted into.
|
|
670
|
+
* @param viewer
|
|
671
|
+
* @param entity
|
|
672
|
+
* @param opacity
|
|
673
|
+
*/
|
|
674
|
+
function SetOpacity(viewer, entity, opacity) {
|
|
675
|
+
applyOpacityToEntity(viewer, opacity, entity);
|
|
676
|
+
}
|
|
677
|
+
EntityUtils.SetOpacity = SetOpacity;
|
|
678
|
+
/**
|
|
679
|
+
* Reverts opacity of given entity to original opacity.
|
|
680
|
+
* If opacity was not updated using "SetOpacity" then nothing will happen.
|
|
681
|
+
* @param viewer
|
|
682
|
+
* @param entity
|
|
683
|
+
*/
|
|
684
|
+
function RevertOpacity(viewer, entity) {
|
|
685
|
+
revertAppliedEntityOpacity(viewer, entity);
|
|
686
|
+
}
|
|
687
|
+
EntityUtils.RevertOpacity = RevertOpacity;
|
|
520
688
|
})(EntityUtils || (EntityUtils = {}));
|
|
521
689
|
|
|
522
690
|
var RenderManager;
|