Source: components/CameraLerpComponent.js

import { Utils } from '../common/Utils';
import { LerpComponent } from './LerpComponent';

const cFlyingActionName = '__flyingAction__';

/**
 * @class CameraLerpComponent
 * The camera lerp component.
 * @memberof THING
 * @extends THING.LerpComponent
 */
class CameraLerpComponent extends LerpComponent {

	/**
	 * The interpolation control of camera, you can change position, target or up-axis direction of camera in that way.
	 */
	constructor() {
		super();
	}

	flyTo(param = {}, trigger) {
		let control = this.object.control;
		if (control.enable && control.stateGroup) {
			let picker = this.app.picker;

			param = Utils.parseFlyParam(param);

			let onStart = Utils.parseValue(param['onStart'], param['start']);
			let onStop = Utils.parseValue(param['onStop'], param['stop']);
			let onResume = Utils.parseValue(param['onResume'], param['resume']);
			let onPause = Utils.parseValue(param['onPause'], param['pause']);
			let onComplete = Utils.parseValue(param['onComplete'], param['complete']);

			param['onStart'] = function () {
				// Deactive controller when start
				control.stateGroup.enable(false, cFlyingActionName, 10000);

				// Disable picker when start
				picker.stateGroup.enable(false, cFlyingActionName, 10000);

				if (onStart) {
					onStart();
				}
			}

			param['onStop'] = function () {
				control.stateGroup.enable(true, cFlyingActionName, 0);
				picker.stateGroup.enable(true, cFlyingActionName, 0);

				if (onStop) {
					onStop();
				}
			}

			param['onResume'] = function () {
				control.stateGroup.enable(false, cFlyingActionName, 10000);
				picker.stateGroup.enable(false, cFlyingActionName, 10000);

				if (onResume) {
					onResume();
				}
			}

			param['onPause'] = function () {
				control.stateGroup.enable(true, cFlyingActionName, 0);
				picker.stateGroup.enable(true, cFlyingActionName, 0);

				if (onPause) {
					onPause();
				}
			}

			param['onComplete'] = function () {
				control.stateGroup.enable(true, cFlyingActionName, 0);
				picker.stateGroup.enable(true, cFlyingActionName, 0);

				if (onComplete) {
					onComplete();
				}
			}

			// Stop camera damping
			const cameraController = this.object.control.getController();
			if (cameraController.stopDamping) {
				cameraController.stopDamping();
			}

			// Stop zooming
			this.object.control.stopZoom();

			super.flyTo(param, trigger);

			// Resume arguments
			param['onStart'] = onStart;
			param['onStop'] = onStop;
			param['onResume'] = onResume;
			param['onPause'] = onPause;
			param['onComplete'] = onComplete;
		}
		else {
			super.flyTo(param, trigger);
		}
	}

}

export { CameraLerpComponent }