Skip to content

Commit

Permalink
feat(globeControls): add configuration parameters and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jailln authored and mgermerie committed Sep 13, 2022
1 parent 821e522 commit cdd865c
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions src/Controls/GlobeControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,30 @@ let previous;
* @param {GlobeView} view the view where the control will be used
* @param {CameraTransformOptions|Extent} placement the {@link CameraTransformOptions} to apply to view's camera
* or the extent it must display at initialisation, see {@link CameraTransformOptions} in {@link CameraUtils}.
* @param {object} options
* @param {number} [options.zoomFactor=2] The factor the scale is multiplied by when dollying (zooming) in or
* divided by when dollying out.
* @param {number} options.rotateSpeed Speed camera rotation in orbit and panoramic mode
* @param {number} options.minDistance Minimum distance between ground and camera
* @param {number} options.maxDistance Maximum distance between ground and camera
* @param {bool} options.handleCollision enable collision camera with ground
* @property {number} minDistance Minimum distance between ground and camera
* @property {number} maxDistance Maximum distance between ground and camera
* @property {number} zoomSpeed Speed zoom with mouse
* @property {number} rotateSpeed Speed camera rotation in orbit and panoramic mode
* @property {number} minDistanceCollision Minimum distance collision between ground and camera
* @property {boolean} enableDamping enable camera damping, if it's disabled the camera immediately when the mouse button is released.
* If it's enabled, the camera movement is decelerate.
* @param {object} [options] An object with one or more configuration properties. Any property of GlobeControls
* can be passed in this object.
* @property {number} zoomFactor The factor the scale is multiplied by when dollying (zooming) in or
* divided by when dollying out. Default is 2.
* @property {number} rotateSpeed Speed camera rotation in orbit and panoramic mode. Default is 0.25.
* @property {number} minDistance Minimum distance between ground and camera in meters (Perspective Camera only).
* Default is 250.
* @property {number} maxDistance Maximum distance between ground and camera in meters
* (Perspective Camera only). Default is ellipsoid radius * 8.
* @property {number} minZoom How far you can zoom in, in meters (Orthographic Camera only). Default is 0.
* @property {number} maxZoom How far you can zoom out, in meters (Orthographic Camera only). Default
* is Infinity.
* @property {number} keyPanSpeed Number of pixels moved per push on array key. Default is 7.
* @property {number} minPolarAngle Minimum vertical orbit angle (in degrees). Default is 0.5.
* @property {number} maxPolarAngle Maximum vertical orbit angle (in degrees). Default is 86.
* @property {number} minAzimuthAngle Minimum horizontal orbit angle (in degrees). If modified,
* should be in [-180,0]. Default is -Infinity.
* @property {number} maxAzimuthAngle Maximum horizontal orbit angle (in degrees). If modified,
* should be in [0,180]. Default is Infinity.
* @property {boolean} handleCollision Handle collision between camera and ground or not, i.e. whether
* you can zoom underground or not. Default is true.
* @property {boolean} enableDamping Enable damping or not (simulates the lag that a real camera
* operator introduces while operating a heavy physical camera). Default is true.
* @property {boolean} dampingMoveFactor the damping move factor. Default is 0.25.
*/
class GlobeControls extends THREE.EventDispatcher {
constructor(view, placement, options = {}) {
Expand All @@ -196,7 +206,7 @@ class GlobeControls extends THREE.EventDispatcher {
// These options actually enables dollying in and out; left as "zoom" for
// backwards compatibility
if (options.zoomSpeed) {
console.warn('Controls zoomSpeed parameter is deprecated. Use zoomInFactor and zoomOutFactor instead.');
console.warn('Controls zoomSpeed parameter is deprecated. Use zoomFactor instead.');
options.zoomFactor = options.zoomFactor || options.zoomSpeed;
}
this.zoomFactor = options.zoomFactor || 1.25;
Expand All @@ -206,25 +216,25 @@ class GlobeControls extends THREE.EventDispatcher {
this.maxDistance = options.maxDistance || ellipsoidSizes.x * 8.0;

// Limits to how far you can zoom in and out ( OrthographicCamera only )
this.minZoom = 0;
this.maxZoom = Infinity;
this.minZoom = options.minZoom || 0;
this.maxZoom = options.maxZoom || Infinity;

// Set to true to disable this control
this.rotateSpeed = options.rotateSpeed || 0.25;

// Set to true to disable this control
this.keyPanSpeed = 7.0; // pixels moved per arrow key push
this.keyPanSpeed = options.keyPanSpeed || 7.0; // pixels moved per arrow key push

// How far you can orbit vertically, upper and lower limits.
// Range is 0 to Math.PI radians.
// TODO Warning minPolarAngle = 0.01 -> it isn't possible to be perpendicular on Globe
this.minPolarAngle = THREE.MathUtils.degToRad(0.5); // radians
this.maxPolarAngle = THREE.MathUtils.degToRad(86); // radians
this.minPolarAngle = THREE.MathUtils.degToRad(options.minPolarAngle ?? 0.5);
this.maxPolarAngle = THREE.MathUtils.degToRad(options.minPolarAngle ?? 86);

// How far you can orbit horizontally, upper and lower limits.
// If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
this.minAzimuthAngle = -Infinity; // radians
this.maxAzimuthAngle = Infinity; // radians
this.minAzimuthAngle = options.minAzimuthAngle ? THREE.MathUtils.degToRad(options.minAzimuthAngle) : -Infinity; // radians
this.maxAzimuthAngle = options.maxAzimuthAngle ? THREE.MathUtils.degToRad(options.maxAzimuthAngle) : Infinity; // radians

// Set collision options
this.handleCollision = typeof (options.handleCollision) !== 'undefined' ? options.handleCollision : true;
Expand All @@ -243,7 +253,7 @@ class GlobeControls extends THREE.EventDispatcher {
});

// Enable Damping
this.enableDamping = true;
this.enableDamping = options.enableDamping !== false;
this.dampingMoveFactor = options.dampingMoveFactor != undefined ? options.dampingMoveFactor : dampingFactorDefault;

this.startEvent = {
Expand Down

0 comments on commit cdd865c

Please sign in to comment.