@geoblocks/cesium-compass
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -43,3 +43,4 @@ // Original code from TerriaJS | ||
orbitCursorAngle: {type: Number}, | ||
orbitCursorOpacity: {type: Number} | ||
orbitCursorOpacity: {type: Number}, | ||
resetDuration: {type: Number}, | ||
}; | ||
@@ -96,4 +97,19 @@ } | ||
super(); | ||
/** | ||
* @type {import('cesium/Source/Scene/Scene').default} | ||
*/ | ||
this.scene; | ||
/** | ||
* @type {import('cesium/Source/Core/Clock').default} | ||
*/ | ||
this.clock = undefined; | ||
this.ready = false; | ||
this.resetDuration = 100; | ||
this.rotateClick = undefined; | ||
this.unlistenFromPostRender = null; | ||
@@ -132,3 +148,3 @@ this.unlistenFromClockTick = null; | ||
transform: `rotate(-${this.orbitCursorAngle}rad)`, | ||
opacity: this.orbitCursorOpacity | ||
opacity: `${this.orbitCursorOpacity}` | ||
}; | ||
@@ -191,2 +207,4 @@ } | ||
this.rotateClick = true; | ||
document.addEventListener('pointermove', this.handleRotatePointerMoveFunction, false); | ||
@@ -213,2 +231,4 @@ document.addEventListener('pointerup', this.handleRotatePointerUpFunction, false); | ||
camera.lookAtTransform(oldTransform); | ||
this.rotateClick = false; | ||
} | ||
@@ -219,4 +239,32 @@ | ||
document.removeEventListener('pointerup', this.handleRotatePointerUpFunction, false); | ||
if (this.rotateClick) { | ||
this.resetToNorth(); | ||
} | ||
} | ||
resetToNorth() { | ||
const camera = this.scene.camera; | ||
const oldTransform = Matrix4.clone(camera.transform, oldTransformScratch); | ||
camera.lookAtTransform(this.context.frame); | ||
const angle = CesiumMath.PI_OVER_TWO + Math.atan2(camera.position.y, camera.position.x); | ||
let prevProgress = 0; | ||
const start = performance.now(); | ||
const step = () => { | ||
const elapsed = performance.now() - start; | ||
const progress = CesiumMath.clamp(elapsed / this.resetDuration, 0, 1); | ||
camera.rotateLeft((progress - prevProgress) * angle); | ||
prevProgress = progress; | ||
if (progress < 1) { | ||
window.requestAnimationFrame(step); | ||
} else { | ||
camera.lookAtTransform(oldTransform); | ||
} | ||
}; | ||
window.requestAnimationFrame(step); | ||
} | ||
orbit(cursorVector) { | ||
@@ -223,0 +271,0 @@ this.context.orbitIsLook = !this.context.viewCenter; |
{ | ||
"name": "@geoblocks/cesium-compass", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"license": "BSD-3-Clause", | ||
@@ -18,3 +18,3 @@ "repository": "github:geoblocks/cesium-helpers", | ||
}, | ||
"gitHead": "6475f9a8585dd4c70cbc686829521001411e6b30" | ||
"gitHead": "3464442900a12200cdfe7d8f929566e07e6e66c4" | ||
} |
@@ -21,6 +21,7 @@ # compass widget for Cesium | ||
| Name | Type | Description | ||
| -------------- | ---------------- | ----------- | ||
| `scene` | `Cesium.Scene` | A [Cesium Scene instance](https://cesium.com/docs/cesiumjs-ref-doc/Scene.html) | ||
| `clock` | `Cesium.Clock` | A [Cesium Clock instance](https://cesium.com/docs/cesiumjs-ref-doc/Clock.html) | ||
| Name | Type | Default | Description | ||
| --------------- | ---------------- | ------- | ----------- | ||
| `scene` | `Cesium.Scene` | | A [Cesium Scene instance](https://cesium.com/docs/cesiumjs-ref-doc/Scene.html) | ||
| `clock` | `Cesium.Clock` | | A [Cesium Clock instance](https://cesium.com/docs/cesiumjs-ref-doc/Clock.html) | ||
| `resetDuration` | `number` | `100` | The duration of the reset to north animation in milliseconds. | ||
@@ -27,0 +28,0 @@ ### CSS Custom Properties |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19525
298
33