@geoblocks/cesium-sphere-camera 0.0.1 → 0.1.0
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/README.md +26 -0
- package/dist/cesium-sphere-camera.d.ts +22 -0
- package/dist/cesium-sphere-camera.d.ts.map +1 -0
- package/dist/cesium-sphere-camera.js +110 -0
- package/dist/cesium-sphere-camera.js.map +1 -0
- package/package.json +25 -5
- package/{cesium-sphere-camera.js → src/cesium-sphere-camera.js} +15 -12
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Cesium Sphere Camera
|
|
2
|
+
|
|
3
|
+
This package provides a helper for managing a camera in a CesiumJS application that orbits around a sphere.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i --save cesium-sphere-camera
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Demo
|
|
12
|
+
|
|
13
|
+
[Demo](https://geoblocks.github.io/cesium-helpers/cesium-sphere-camera.html)
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
import {Viewer} from '@cesium/engine';
|
|
19
|
+
import CesiumSphereCamera from 'cesium-sphere-camera';
|
|
20
|
+
|
|
21
|
+
const viewer = new Viewer(...);
|
|
22
|
+
const sphereMode = new CesiumSphereCamera(viewer);
|
|
23
|
+
|
|
24
|
+
// ...
|
|
25
|
+
sphereMode.active = true;
|
|
26
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export default class CesiumSphereCamera {
|
|
2
|
+
viewer: import("@cesium/engine").CesiumWidget;
|
|
3
|
+
dragging_: boolean;
|
|
4
|
+
active_: boolean;
|
|
5
|
+
handleDownEvent_: () => void;
|
|
6
|
+
handleMoveEvent_: (movement: import('@cesium/engine').ScreenSpaceEventHandler.MotionEvent) => void;
|
|
7
|
+
handleUpEvent_: () => void;
|
|
8
|
+
/**
|
|
9
|
+
* @param {import('@cesium/engine').CesiumWidget} viewer
|
|
10
|
+
*/
|
|
11
|
+
constructor(viewer: import('@cesium/engine').CesiumWidget);
|
|
12
|
+
get active(): boolean;
|
|
13
|
+
set active(active: boolean);
|
|
14
|
+
handleDownEvent(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Code from look3D function in ScreenSpaceCameraController
|
|
17
|
+
* @param {import('@cesium/engine').ScreenSpaceEventHandler.MotionEvent} movement
|
|
18
|
+
*/
|
|
19
|
+
handleMoveEvent(movement: import('@cesium/engine').ScreenSpaceEventHandler.MotionEvent): void;
|
|
20
|
+
handleUpEvent(): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=cesium-sphere-camera.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cesium-sphere-camera.d.ts","sourceRoot":"","sources":["../src/cesium-sphere-camera.js"],"names":[],"mappings":"AAkBA,MAAM,CAAC,OAAO,OAAO,kBAAkB;IAK9B,MAAM;IACN,SAAS;IACT,OAAO;IAEP,gBAAgB;IAChB,gBAAgB,aA+BZ,OAAO,gBAAgB,EAAE,uBAAuB,CAAC,WAAW;IA9BhE,cAAc;IAVrB;;OAEG;IACH,YAAY,MAAM,EAFP,OAAO,gBAAgB,EAAE,YAElB,EAQjB;IAED,IAAI,MAAM,YAET;IAED,IAAI,MAAM,CAAC,MAAM,SAAA,EAehB;IAED,eAAe,SAEd;IAED;;;OAGG;IACH,eAAe,CAAC,QAAQ,EAFb,OAAO,gBAAgB,EAAE,uBAAuB,CAAC,WAEpC,QA6EvB;IAED,aAAa,SAEZ;CACF"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Math as CesiumMath, Cartesian3, Cartesian2, Ray, } from "@cesium/core";
|
|
2
|
+
import { ScreenSpaceEventType, } from "@cesium/engine";
|
|
3
|
+
const look3DStartPos = new Cartesian2();
|
|
4
|
+
const look3DEndPos = new Cartesian2();
|
|
5
|
+
const look3DStartRay = new Ray();
|
|
6
|
+
const look3DEndRay = new Ray();
|
|
7
|
+
const look3DNegativeRot = new Cartesian3();
|
|
8
|
+
const look3DTan = new Cartesian3();
|
|
9
|
+
const rotationAxisScratch = new Cartesian3();
|
|
10
|
+
export default class CesiumSphereCamera {
|
|
11
|
+
/**
|
|
12
|
+
* @param {import('@cesium/engine').CesiumWidget} viewer
|
|
13
|
+
*/
|
|
14
|
+
constructor(viewer) {
|
|
15
|
+
this.viewer = viewer;
|
|
16
|
+
this.dragging_ = false;
|
|
17
|
+
this.active_ = false;
|
|
18
|
+
this.handleDownEvent_ = this.handleDownEvent.bind(this);
|
|
19
|
+
this.handleMoveEvent_ = this.handleMoveEvent.bind(this);
|
|
20
|
+
this.handleUpEvent_ = this.handleUpEvent.bind(this);
|
|
21
|
+
}
|
|
22
|
+
get active() {
|
|
23
|
+
return this.active_;
|
|
24
|
+
}
|
|
25
|
+
set active(active) {
|
|
26
|
+
if (active === this.active_) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
this.active_ = active;
|
|
30
|
+
this.viewer.scene.screenSpaceCameraController.enableInputs = !active;
|
|
31
|
+
if (active) {
|
|
32
|
+
this.viewer.screenSpaceEventHandler.setInputAction(this.handleDownEvent_, ScreenSpaceEventType.LEFT_DOWN);
|
|
33
|
+
this.viewer.screenSpaceEventHandler.setInputAction(this.handleMoveEvent_, ScreenSpaceEventType.MOUSE_MOVE);
|
|
34
|
+
this.viewer.screenSpaceEventHandler.setInputAction(this.handleUpEvent_, ScreenSpaceEventType.LEFT_UP);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
this.viewer.screenSpaceEventHandler.removeInputAction(ScreenSpaceEventType.LEFT_DOWN);
|
|
38
|
+
this.viewer.screenSpaceEventHandler.removeInputAction(ScreenSpaceEventType.MOUSE_MOVE);
|
|
39
|
+
this.viewer.screenSpaceEventHandler.removeInputAction(ScreenSpaceEventType.LEFT_UP);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
handleDownEvent() {
|
|
43
|
+
this.dragging_ = true;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Code from look3D function in ScreenSpaceCameraController
|
|
47
|
+
* @param {import('@cesium/engine').ScreenSpaceEventHandler.MotionEvent} movement
|
|
48
|
+
*/
|
|
49
|
+
handleMoveEvent(movement) {
|
|
50
|
+
if (!this.dragging_) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const camera = this.viewer.scene.camera;
|
|
54
|
+
// x axis
|
|
55
|
+
let angle = 0.0;
|
|
56
|
+
look3DStartPos.x = movement.startPosition.x;
|
|
57
|
+
look3DStartPos.y = 0.0;
|
|
58
|
+
look3DEndPos.x = movement.endPosition.x;
|
|
59
|
+
look3DEndPos.y = 0.0;
|
|
60
|
+
camera.getPickRay(look3DStartPos, look3DStartRay);
|
|
61
|
+
camera.getPickRay(look3DEndPos, look3DEndRay);
|
|
62
|
+
let dot = Cartesian3.dot(look3DStartRay.direction, look3DEndRay.direction);
|
|
63
|
+
if (dot < 1.0) {
|
|
64
|
+
// dot is in [0, 1]
|
|
65
|
+
angle = Math.acos(dot);
|
|
66
|
+
}
|
|
67
|
+
angle = movement.startPosition.x > movement.endPosition.x ? -angle : angle;
|
|
68
|
+
const rotationAxis = this.viewer.scene.globe.ellipsoid.geodeticSurfaceNormal(camera.position, rotationAxisScratch);
|
|
69
|
+
camera.look(rotationAxis, -angle);
|
|
70
|
+
// y axis
|
|
71
|
+
look3DStartPos.x = 0.0;
|
|
72
|
+
look3DStartPos.y = movement.startPosition.y;
|
|
73
|
+
look3DEndPos.x = 0.0;
|
|
74
|
+
look3DEndPos.y = movement.endPosition.y;
|
|
75
|
+
camera.getPickRay(look3DStartPos, look3DStartRay);
|
|
76
|
+
camera.getPickRay(look3DEndPos, look3DEndRay);
|
|
77
|
+
angle = 0.0;
|
|
78
|
+
dot = Cartesian3.dot(look3DStartRay.direction, look3DEndRay.direction);
|
|
79
|
+
if (dot < 1.0) {
|
|
80
|
+
// dot is in [0, 1]
|
|
81
|
+
angle = Math.acos(dot);
|
|
82
|
+
}
|
|
83
|
+
angle = movement.startPosition.y > movement.endPosition.y ? -angle : angle;
|
|
84
|
+
const direction = camera.direction;
|
|
85
|
+
const negativeRotationAxis = Cartesian3.negate(rotationAxis, look3DNegativeRot);
|
|
86
|
+
const northParallel = Cartesian3.equalsEpsilon(direction, rotationAxis, CesiumMath.EPSILON2);
|
|
87
|
+
const southParallel = Cartesian3.equalsEpsilon(direction, negativeRotationAxis, CesiumMath.EPSILON2);
|
|
88
|
+
if (!northParallel && !southParallel) {
|
|
89
|
+
dot = Cartesian3.dot(direction, rotationAxis);
|
|
90
|
+
let angleToAxis = CesiumMath.acosClamped(dot);
|
|
91
|
+
if (angle > 0 && angle > angleToAxis) {
|
|
92
|
+
angle = angleToAxis - CesiumMath.EPSILON4;
|
|
93
|
+
}
|
|
94
|
+
dot = Cartesian3.dot(direction, negativeRotationAxis);
|
|
95
|
+
angleToAxis = CesiumMath.acosClamped(dot);
|
|
96
|
+
if (angle < 0 && -angle > angleToAxis) {
|
|
97
|
+
angle = -angleToAxis + CesiumMath.EPSILON4;
|
|
98
|
+
}
|
|
99
|
+
const tangent = Cartesian3.cross(rotationAxis, direction, look3DTan);
|
|
100
|
+
camera.look(tangent, angle);
|
|
101
|
+
}
|
|
102
|
+
else if ((northParallel && angle < 0) || (southParallel && angle > 0)) {
|
|
103
|
+
camera.look(camera.right, -angle);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
handleUpEvent() {
|
|
107
|
+
this.dragging_ = false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=cesium-sphere-camera.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cesium-sphere-camera.js","sourceRoot":"","sources":["../src/cesium-sphere-camera.js"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,IAAI,UAAU,EAClB,UAAU,EACV,UAAU,EAC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AC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC9B,CAAC;aAAM,IAAI,CAAC,aAAa,IAAI,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,aAAa,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;YACxE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,aAAa;QACX,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geoblocks/cesium-sphere-camera",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "https://github.com/geoblocks/cesium-helpers/",
|
|
8
9
|
"directory": "packages/cesium-sphere-camera"
|
|
9
10
|
},
|
|
10
|
-
"main": "cesium-sphere-camera.js",
|
|
11
|
-
"module": "cesium-sphere-camera.js",
|
|
11
|
+
"main": "dist/cesium-sphere-camera.js",
|
|
12
|
+
"module": "dist/cesium-sphere-camera.js",
|
|
13
|
+
"types": "dist/cesium-sphere-camera.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"source": "./src/cesium-sphere-camera.js",
|
|
17
|
+
"types": "./dist/cesium-sphere-camera.d.ts",
|
|
18
|
+
"default": "./dist/cesium-sphere-camera.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"src",
|
|
25
|
+
"!src/**/*.test.js"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p .",
|
|
29
|
+
"prepack": "npm run build"
|
|
30
|
+
},
|
|
12
31
|
"publishConfig": {
|
|
13
32
|
"access": "public"
|
|
14
33
|
},
|
|
15
34
|
"peerDependencies": {
|
|
16
|
-
"cesium": "1.
|
|
35
|
+
"@cesium/core": ">=0.1.0",
|
|
36
|
+
"@cesium/engine": ">=10"
|
|
17
37
|
},
|
|
18
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "a6d8fdfe6b9ad266fd8a4593c38efd24e9a5546b"
|
|
19
39
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ScreenSpaceEventType,
|
|
3
2
|
Math as CesiumMath,
|
|
4
3
|
Cartesian3,
|
|
5
4
|
Cartesian2,
|
|
6
5
|
Ray,
|
|
7
|
-
} from "cesium";
|
|
6
|
+
} from "@cesium/core";
|
|
7
|
+
import {
|
|
8
|
+
ScreenSpaceEventType,
|
|
9
|
+
} from "@cesium/engine";
|
|
8
10
|
|
|
9
11
|
const look3DStartPos = new Cartesian2();
|
|
10
12
|
const look3DEndPos = new Cartesian2();
|
|
@@ -12,10 +14,11 @@ const look3DStartRay = new Ray();
|
|
|
12
14
|
const look3DEndRay = new Ray();
|
|
13
15
|
const look3DNegativeRot = new Cartesian3();
|
|
14
16
|
const look3DTan = new Cartesian3();
|
|
17
|
+
const rotationAxisScratch = new Cartesian3();
|
|
15
18
|
|
|
16
19
|
export default class CesiumSphereCamera {
|
|
17
20
|
/**
|
|
18
|
-
* @param {import('cesium').
|
|
21
|
+
* @param {import('@cesium/engine').CesiumWidget} viewer
|
|
19
22
|
*/
|
|
20
23
|
constructor(viewer) {
|
|
21
24
|
this.viewer = viewer;
|
|
@@ -54,13 +57,13 @@ export default class CesiumSphereCamera {
|
|
|
54
57
|
|
|
55
58
|
/**
|
|
56
59
|
* Code from look3D function in ScreenSpaceCameraController
|
|
57
|
-
* @param {import('cesium').ScreenSpaceEventHandler.MotionEvent} movement
|
|
60
|
+
* @param {import('@cesium/engine').ScreenSpaceEventHandler.MotionEvent} movement
|
|
58
61
|
*/
|
|
59
62
|
handleMoveEvent(movement) {
|
|
60
63
|
if (!this.dragging_) {
|
|
61
64
|
return;
|
|
62
65
|
}
|
|
63
|
-
const camera = this.viewer.camera;
|
|
66
|
+
const camera = this.viewer.scene.camera;
|
|
64
67
|
|
|
65
68
|
// x axis
|
|
66
69
|
|
|
@@ -70,17 +73,17 @@ export default class CesiumSphereCamera {
|
|
|
70
73
|
look3DEndPos.x = movement.endPosition.x;
|
|
71
74
|
look3DEndPos.y = 0.0;
|
|
72
75
|
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
camera.getPickRay(look3DStartPos, look3DStartRay);
|
|
77
|
+
camera.getPickRay(look3DEndPos, look3DEndRay);
|
|
75
78
|
|
|
76
|
-
let dot = Cartesian3.dot(
|
|
79
|
+
let dot = Cartesian3.dot(look3DStartRay.direction, look3DEndRay.direction);
|
|
77
80
|
if (dot < 1.0) {
|
|
78
81
|
// dot is in [0, 1]
|
|
79
82
|
angle = Math.acos(dot);
|
|
80
83
|
}
|
|
81
84
|
angle = movement.startPosition.x > movement.endPosition.x ? -angle : angle;
|
|
82
85
|
const rotationAxis =
|
|
83
|
-
this.viewer.scene.globe.ellipsoid.geodeticSurfaceNormal(camera.position);
|
|
86
|
+
this.viewer.scene.globe.ellipsoid.geodeticSurfaceNormal(camera.position, rotationAxisScratch);
|
|
84
87
|
camera.look(rotationAxis, -angle);
|
|
85
88
|
|
|
86
89
|
// y axis
|
|
@@ -90,11 +93,11 @@ export default class CesiumSphereCamera {
|
|
|
90
93
|
look3DEndPos.x = 0.0;
|
|
91
94
|
look3DEndPos.y = movement.endPosition.y;
|
|
92
95
|
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
camera.getPickRay(look3DStartPos, look3DStartRay);
|
|
97
|
+
camera.getPickRay(look3DEndPos, look3DEndRay);
|
|
95
98
|
angle = 0.0;
|
|
96
99
|
|
|
97
|
-
dot = Cartesian3.dot(
|
|
100
|
+
dot = Cartesian3.dot(look3DStartRay.direction, look3DEndRay.direction);
|
|
98
101
|
if (dot < 1.0) {
|
|
99
102
|
// dot is in [0, 1]
|
|
100
103
|
angle = Math.acos(dot);
|