bruce-cesium 7.9.4 → 7.9.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 +177 -9
- package/dist/bruce-cesium.es5.js.map +1 -1
- package/dist/bruce-cesium.umd.js +170 -6
- package/dist/bruce-cesium.umd.js.map +1 -1
- package/dist/lib/bruce-cesium.js +1 -1
- package/dist/lib/viewer/camera-controls.js +174 -6
- package/dist/lib/viewer/camera-controls.js.map +1 -1
- package/dist/types/bruce-cesium.d.ts +1 -1
- package/dist/types/viewer/camera-controls.d.ts +26 -0
- package/package.json +1 -1
package/dist/bruce-cesium.umd.js
CHANGED
|
@@ -1385,6 +1385,20 @@ void main()
|
|
|
1385
1385
|
const HIDDEN_GLOBE_MAX_HEIGHT = 10000000;
|
|
1386
1386
|
// Marks a tileset that stands in for the globe, such as Google's photorealistic tiles.
|
|
1387
1387
|
const GROUND_TILESET_KEY = "_nextspace_camera_ground";
|
|
1388
|
+
// A viewer's own mouse scheme and wheel direction, kept on the viewer so a host may set them before Attach.
|
|
1389
|
+
const MOUSE_KEY = "_nextspace_camera_mouse";
|
|
1390
|
+
// Marks a wheel event these controls turned round, so it is not turned back again.
|
|
1391
|
+
const MIRRORED_WHEEL_KEY = "_nextspace_mirrored";
|
|
1392
|
+
(function (ECameraMouseScheme) {
|
|
1393
|
+
// CesiumJS's own: left drag pans, middle or ctrl drag orbits, right drag zooms.
|
|
1394
|
+
ECameraMouseScheme["Default"] = "default";
|
|
1395
|
+
// Autodesk Fusion, Revit, Navisworks and AutoCAD: middle drag pans, shift+middle orbits, ctrl+shift+middle zooms.
|
|
1396
|
+
ECameraMouseScheme["Autodesk"] = "autodesk";
|
|
1397
|
+
// SketchUp: middle drag orbits, shift+middle pans.
|
|
1398
|
+
ECameraMouseScheme["SketchUp"] = "sketchup";
|
|
1399
|
+
})(exports.ECameraMouseScheme || (exports.ECameraMouseScheme = {}));
|
|
1400
|
+
// What a viewer without its own setting uses: the app user's preference, set once for every viewer the app makes.
|
|
1401
|
+
const _mouseDefault = { scheme: exports.ECameraMouseScheme.Default, wheelReversed: false };
|
|
1388
1402
|
var EDrag;
|
|
1389
1403
|
(function (EDrag) {
|
|
1390
1404
|
EDrag["Pan"] = "pan";
|
|
@@ -1396,7 +1410,7 @@ void main()
|
|
|
1396
1410
|
* Takes over mouse drag and wheel navigation close to the ground; CesiumJS keeps planet scale, pinch and look.
|
|
1397
1411
|
*/
|
|
1398
1412
|
function Attach(viewer) {
|
|
1399
|
-
var _a, _b, _c;
|
|
1413
|
+
var _a, _b, _c, _d;
|
|
1400
1414
|
if (!viewer || viewer.isDestroyed() || viewer[CESIUM_CAMERA_CONTROLS_KEY]) {
|
|
1401
1415
|
return;
|
|
1402
1416
|
}
|
|
@@ -1422,11 +1436,13 @@ void main()
|
|
|
1422
1436
|
rotateEventTypes: controller.rotateEventTypes,
|
|
1423
1437
|
zoomEventTypes: controller.zoomEventTypes,
|
|
1424
1438
|
tiltEventTypes: controller.tiltEventTypes,
|
|
1439
|
+
translateEventTypes: controller.translateEventTypes,
|
|
1425
1440
|
enableCollisionDetection: controller.enableCollisionDetection,
|
|
1426
1441
|
backFaceAlpha: (_b = (_a = scene.globe) === null || _a === void 0 ? void 0 : _a.translucency) === null || _b === void 0 ? void 0 : _b.backFaceAlpha,
|
|
1427
1442
|
showSkirts: (_c = scene.globe) === null || _c === void 0 ? void 0 : _c.showSkirts
|
|
1428
1443
|
},
|
|
1429
1444
|
ours: false,
|
|
1445
|
+
cesiumScheme: null,
|
|
1430
1446
|
removals: []
|
|
1431
1447
|
};
|
|
1432
1448
|
viewer[CESIUM_CAMERA_CONTROLS_KEY] = state;
|
|
@@ -1442,6 +1458,9 @@ void main()
|
|
|
1442
1458
|
listen(window, "pointerup", (e) => onPointerUp(state, e));
|
|
1443
1459
|
listen(window, "pointercancel", (e) => onPointerUp(state, e));
|
|
1444
1460
|
listen(canvas, "wheel", (e) => onWheel(state, e), { passive: true });
|
|
1461
|
+
// Caught before the canvas sees it, so CesiumJS's controller and these controls both get the turned wheel.
|
|
1462
|
+
const wheelHost = (_d = canvas.parentElement) !== null && _d !== void 0 ? _d : window;
|
|
1463
|
+
listen(wheelHost, "wheel", (e) => mirrorWheel(state, e), { capture: true, passive: false });
|
|
1445
1464
|
state.removals.push(scene.preUpdate.addEventListener(() => {
|
|
1446
1465
|
syncController(state);
|
|
1447
1466
|
keepAboveGround(state);
|
|
@@ -1477,6 +1496,52 @@ void main()
|
|
|
1477
1496
|
return Boolean(viewer === null || viewer === void 0 ? void 0 : viewer[CESIUM_CAMERA_CONTROLS_KEY]);
|
|
1478
1497
|
}
|
|
1479
1498
|
CameraControls.IsAttached = IsAttached;
|
|
1499
|
+
/**
|
|
1500
|
+
* Picks which mouse buttons pan, orbit and zoom, here and for CesiumJS's controller above the hand-over height.
|
|
1501
|
+
*/
|
|
1502
|
+
function SetMouseScheme(viewer, scheme) {
|
|
1503
|
+
if (!viewer || viewer.isDestroyed()) {
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
viewer[MOUSE_KEY] = { ...viewer[MOUSE_KEY], scheme: knownScheme(scheme) };
|
|
1507
|
+
const state = viewer[CESIUM_CAMERA_CONTROLS_KEY];
|
|
1508
|
+
if (state && !state.ours) {
|
|
1509
|
+
applyCesiumGestures(state);
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
CameraControls.SetMouseScheme = SetMouseScheme;
|
|
1513
|
+
/**
|
|
1514
|
+
* Sets the scheme for every viewer without its own, such as the app user's preference; viewers follow next frame.
|
|
1515
|
+
*/
|
|
1516
|
+
function SetMouseSchemeDefault(scheme) {
|
|
1517
|
+
_mouseDefault.scheme = knownScheme(scheme);
|
|
1518
|
+
}
|
|
1519
|
+
CameraControls.SetMouseSchemeDefault = SetMouseSchemeDefault;
|
|
1520
|
+
function GetMouseScheme(viewer) {
|
|
1521
|
+
return mouseOf(viewer).scheme;
|
|
1522
|
+
}
|
|
1523
|
+
CameraControls.GetMouseScheme = GetMouseScheme;
|
|
1524
|
+
/**
|
|
1525
|
+
* Makes wheel forward zoom out instead of in, for these controls and CesiumJS's controller alike.
|
|
1526
|
+
*/
|
|
1527
|
+
function SetMouseWheelReversed(viewer, reversed) {
|
|
1528
|
+
if (!viewer || viewer.isDestroyed()) {
|
|
1529
|
+
return;
|
|
1530
|
+
}
|
|
1531
|
+
viewer[MOUSE_KEY] = { ...viewer[MOUSE_KEY], wheelReversed: Boolean(reversed) };
|
|
1532
|
+
}
|
|
1533
|
+
CameraControls.SetMouseWheelReversed = SetMouseWheelReversed;
|
|
1534
|
+
/**
|
|
1535
|
+
* Sets the wheel direction for every viewer without its own, such as the app user's preference.
|
|
1536
|
+
*/
|
|
1537
|
+
function SetMouseWheelReversedDefault(reversed) {
|
|
1538
|
+
_mouseDefault.wheelReversed = Boolean(reversed);
|
|
1539
|
+
}
|
|
1540
|
+
CameraControls.SetMouseWheelReversedDefault = SetMouseWheelReversedDefault;
|
|
1541
|
+
function GetMouseWheelReversed(viewer) {
|
|
1542
|
+
return mouseOf(viewer).wheelReversed;
|
|
1543
|
+
}
|
|
1544
|
+
CameraControls.GetMouseWheelReversed = GetMouseWheelReversed;
|
|
1480
1545
|
/**
|
|
1481
1546
|
* Marks a tileset as standing in for the globe (Google's photorealistic tiles), so the camera treats it as ground.
|
|
1482
1547
|
*/
|
|
@@ -1534,11 +1599,67 @@ void main()
|
|
|
1534
1599
|
}
|
|
1535
1600
|
CameraControls.SetModelSpace = SetModelSpace;
|
|
1536
1601
|
})(exports.CameraControls || (exports.CameraControls = {}));
|
|
1602
|
+
/*
|
|
1603
|
+
* The scheme and wheel direction a viewer uses: its own where set, else the app default.
|
|
1604
|
+
*/
|
|
1605
|
+
function mouseOf(viewer) {
|
|
1606
|
+
var _a, _b;
|
|
1607
|
+
const own = viewer === null || viewer === void 0 ? void 0 : viewer[MOUSE_KEY];
|
|
1608
|
+
return {
|
|
1609
|
+
scheme: (_a = own === null || own === void 0 ? void 0 : own.scheme) !== null && _a !== void 0 ? _a : _mouseDefault.scheme,
|
|
1610
|
+
wheelReversed: (_b = own === null || own === void 0 ? void 0 : own.wheelReversed) !== null && _b !== void 0 ? _b : _mouseDefault.wheelReversed
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
/*
|
|
1614
|
+
* A scheme this version knows, or Default for one saved by a newer app or mistyped.
|
|
1615
|
+
*/
|
|
1616
|
+
function knownScheme(scheme) {
|
|
1617
|
+
return Object.values(exports.ECameraMouseScheme).includes(scheme) ? scheme : exports.ECameraMouseScheme.Default;
|
|
1618
|
+
}
|
|
1537
1619
|
function restoreCesiumGestures(state) {
|
|
1538
1620
|
const controller = state.viewer.scene.screenSpaceCameraController;
|
|
1539
1621
|
controller.rotateEventTypes = state.saved.rotateEventTypes;
|
|
1540
1622
|
controller.zoomEventTypes = state.saved.zoomEventTypes;
|
|
1541
1623
|
controller.tiltEventTypes = state.saved.tiltEventTypes;
|
|
1624
|
+
if (state.saved.translateEventTypes !== undefined) {
|
|
1625
|
+
controller.translateEventTypes = state.saved.translateEventTypes;
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
/*
|
|
1629
|
+
* Gives CesiumJS's controller its own gestures under the mouse scheme, so the buttons do not swap at the hand-over.
|
|
1630
|
+
*/
|
|
1631
|
+
function applyCesiumGestures(state) {
|
|
1632
|
+
restoreCesiumGestures(state);
|
|
1633
|
+
const scheme = mouseOf(state.viewer).scheme;
|
|
1634
|
+
state.cesiumScheme = scheme;
|
|
1635
|
+
if (scheme === exports.ECameraMouseScheme.Default) {
|
|
1636
|
+
return;
|
|
1637
|
+
}
|
|
1638
|
+
const middle = Cesium.CameraEventType.MIDDLE_DRAG;
|
|
1639
|
+
const shiftMiddle = { eventType: middle, modifier: Cesium.KeyboardEventModifier.SHIFT };
|
|
1640
|
+
const tilt = asEventTypes(state.saved.tiltEventTypes);
|
|
1641
|
+
// A host that moved CesiumJS's middle drag elsewhere has its own mapping, which is left alone.
|
|
1642
|
+
if (!tilt.includes(middle)) {
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
// CesiumJS orbits with tilt and pans with rotate in 3D, or translate in 2D and Columbus view.
|
|
1646
|
+
const orbit = scheme === exports.ECameraMouseScheme.Autodesk ? shiftMiddle : middle;
|
|
1647
|
+
const pan = scheme === exports.ECameraMouseScheme.Autodesk ? middle : shiftMiddle;
|
|
1648
|
+
const controller = state.viewer.scene.screenSpaceCameraController;
|
|
1649
|
+
controller.tiltEventTypes = tilt.map((type) => (type === middle ? orbit : type));
|
|
1650
|
+
controller.rotateEventTypes = [...asEventTypes(state.saved.rotateEventTypes), pan];
|
|
1651
|
+
if (state.saved.translateEventTypes !== undefined) {
|
|
1652
|
+
controller.translateEventTypes = [...asEventTypes(state.saved.translateEventTypes), pan];
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
/*
|
|
1656
|
+
* CesiumJS takes one event type or a list of them; this always gives a list.
|
|
1657
|
+
*/
|
|
1658
|
+
function asEventTypes(types) {
|
|
1659
|
+
if (types == null) {
|
|
1660
|
+
return [];
|
|
1661
|
+
}
|
|
1662
|
+
return Array.isArray(types) ? types : [types];
|
|
1542
1663
|
}
|
|
1543
1664
|
/*
|
|
1544
1665
|
* Decides each frame who has the mouse: these controls near the ground, CesiumJS for planets, orthographic and tracking.
|
|
@@ -1550,6 +1671,9 @@ void main()
|
|
|
1550
1671
|
}
|
|
1551
1672
|
const ours = shouldControl(state);
|
|
1552
1673
|
if (ours === state.ours) {
|
|
1674
|
+
if (!ours && state.cesiumScheme !== mouseOf(viewer).scheme) {
|
|
1675
|
+
applyCesiumGestures(state);
|
|
1676
|
+
}
|
|
1553
1677
|
return;
|
|
1554
1678
|
}
|
|
1555
1679
|
state.ours = ours;
|
|
@@ -1560,7 +1684,7 @@ void main()
|
|
|
1560
1684
|
controller.tiltEventTypes = [Cesium.CameraEventType.PINCH];
|
|
1561
1685
|
}
|
|
1562
1686
|
else {
|
|
1563
|
-
|
|
1687
|
+
applyCesiumGestures(state);
|
|
1564
1688
|
}
|
|
1565
1689
|
}
|
|
1566
1690
|
function shouldControl(state) {
|
|
@@ -1974,9 +2098,18 @@ void main()
|
|
|
1974
2098
|
return Cesium.Cartesian3.dot(toPoint, camera.directionWC) > 0;
|
|
1975
2099
|
}
|
|
1976
2100
|
/*
|
|
1977
|
-
* Picks which gesture a button and its modifiers start
|
|
2101
|
+
* Picks which gesture a button and its modifiers start under the mouse scheme; Default matches CesiumJS's own mapping.
|
|
1978
2102
|
*/
|
|
1979
|
-
function dragKind(e) {
|
|
2103
|
+
function dragKind(e, scheme) {
|
|
2104
|
+
if (scheme === exports.ECameraMouseScheme.Autodesk && e.button === 1) {
|
|
2105
|
+
if (e.shiftKey && e.ctrlKey) {
|
|
2106
|
+
return EDrag.Zoom;
|
|
2107
|
+
}
|
|
2108
|
+
return e.shiftKey ? EDrag.Orbit : EDrag.Pan;
|
|
2109
|
+
}
|
|
2110
|
+
if (scheme === exports.ECameraMouseScheme.SketchUp && e.button === 1) {
|
|
2111
|
+
return e.shiftKey ? EDrag.Pan : EDrag.Orbit;
|
|
2112
|
+
}
|
|
1980
2113
|
if (e.shiftKey) {
|
|
1981
2114
|
// Shift drag looks around, which CesiumJS still handles.
|
|
1982
2115
|
return null;
|
|
@@ -2020,7 +2153,7 @@ void main()
|
|
|
2020
2153
|
return;
|
|
2021
2154
|
}
|
|
2022
2155
|
}
|
|
2023
|
-
const kind = dragKind(e);
|
|
2156
|
+
const kind = dragKind(e, mouseOf(viewer).scheme);
|
|
2024
2157
|
if (!kind || !allows(state, kind)) {
|
|
2025
2158
|
return;
|
|
2026
2159
|
}
|
|
@@ -2216,6 +2349,37 @@ void main()
|
|
|
2216
2349
|
state.zoomFrame = requestAnimationFrame(() => easeZoom(state));
|
|
2217
2350
|
}
|
|
2218
2351
|
}
|
|
2352
|
+
/*
|
|
2353
|
+
* Swaps a wheel event over the scene for one turned round, so wheel forward zooms out when the user asked for that.
|
|
2354
|
+
*/
|
|
2355
|
+
function mirrorWheel(state, e) {
|
|
2356
|
+
const viewer = state.viewer;
|
|
2357
|
+
const canvas = viewer.isDestroyed() ? null : viewer.scene.canvas;
|
|
2358
|
+
if (!canvas || e.target !== canvas || e[MIRRORED_WHEEL_KEY] || !mouseOf(viewer).wheelReversed) {
|
|
2359
|
+
return;
|
|
2360
|
+
}
|
|
2361
|
+
e.stopImmediatePropagation();
|
|
2362
|
+
e.preventDefault();
|
|
2363
|
+
const mirrored = new WheelEvent("wheel", {
|
|
2364
|
+
bubbles: true,
|
|
2365
|
+
cancelable: true,
|
|
2366
|
+
clientX: e.clientX,
|
|
2367
|
+
clientY: e.clientY,
|
|
2368
|
+
screenX: e.screenX,
|
|
2369
|
+
screenY: e.screenY,
|
|
2370
|
+
ctrlKey: e.ctrlKey,
|
|
2371
|
+
shiftKey: e.shiftKey,
|
|
2372
|
+
altKey: e.altKey,
|
|
2373
|
+
metaKey: e.metaKey,
|
|
2374
|
+
buttons: e.buttons,
|
|
2375
|
+
deltaMode: e.deltaMode,
|
|
2376
|
+
deltaX: e.deltaX,
|
|
2377
|
+
deltaY: -e.deltaY,
|
|
2378
|
+
deltaZ: e.deltaZ
|
|
2379
|
+
});
|
|
2380
|
+
mirrored[MIRRORED_WHEEL_KEY] = true;
|
|
2381
|
+
canvas.dispatchEvent(mirrored);
|
|
2382
|
+
}
|
|
2219
2383
|
/*
|
|
2220
2384
|
* Applies part of the outstanding wheel movement each frame, so a notch glides rather than jumps.
|
|
2221
2385
|
*/
|
|
@@ -62150,7 +62314,7 @@ void main() {
|
|
|
62150
62314
|
StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
|
|
62151
62315
|
})(exports.StyleUtils || (exports.StyleUtils = {}));
|
|
62152
62316
|
|
|
62153
|
-
const VERSION = "7.9.
|
|
62317
|
+
const VERSION = "7.9.5";
|
|
62154
62318
|
/**
|
|
62155
62319
|
* Updates the environment instance used by bruce-cesium to one specified.
|
|
62156
62320
|
* This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.
|