1
import {Controller} from "../Controller.js";
4
class OrthoMode extends Controller {
6
constructor(parent, cfg) {
10
if (!cfg.buttonElement) {
11
throw "Missing config: buttonElement";
14
this._buttonElement = cfg.buttonElement;
16
this.on("enabled", (enabled) => {
18
this._buttonElement.classList.add("disabled");
20
this._buttonElement.classList.remove("disabled");
24
this._buttonElement.addEventListener("click", (event) => {
25
if (this.getEnabled()) {
26
this.setActive(!this.getActive(), () => {
29
event.preventDefault();
32
this.bimViewer.on("reset", () => {
33
this.setActive(false);
36
this.viewer.camera.on("projection", () => {
37
const isOrtho = (this.viewer.camera.projection === "ortho");
38
this._active = isOrtho;
40
this._buttonElement.classList.add("active");
42
this._buttonElement.classList.remove("active");
47
this._buttonElement.classList.remove("active");
50
setActive(active, done) {
51
if (this._active === active) {
57
this._active = active;
59
this._buttonElement.classList.add("active");
61
this._enterOrthoMode(() => {
62
this.fire("active", this._active);
66
this._enterOrthoMode();
67
this.fire("active", this._active);
70
this._buttonElement.classList.remove("active");
72
this._exitOrthoMode(() => {
73
this.fire("active", this._active);
77
this._exitOrthoMode();
78
this.fire("active", this._active);
83
_enterOrthoMode(done) {
85
this.viewer.cameraFlight.flyTo({projection: "ortho", duration: 0.5}, done);
87
this.viewer.cameraFlight.jumpTo({projection: "ortho"});
91
_exitOrthoMode(done) {
93
this.viewer.cameraFlight.flyTo({projection: "perspective", duration: 0.5}, done);
95
this.viewer.cameraFlight.jumpTo({projection: "perspective"});