BIMviewer

Форк
0
/
OrthoMode.js 
100 строк · 2.8 Кб
1
import {Controller} from "../Controller.js";
2

3
/** @private */
4
class OrthoMode extends Controller {
5

6
    constructor(parent, cfg) {
7

8
        super(parent, cfg);
9

10
        if (!cfg.buttonElement) {
11
            throw "Missing config: buttonElement";
12
        }
13

14
        this._buttonElement = cfg.buttonElement;
15

16
        this.on("enabled", (enabled) => {
17
            if (!enabled) {
18
                this._buttonElement.classList.add("disabled");
19
            } else {
20
                this._buttonElement.classList.remove("disabled");
21
            }
22
        });
23

24
        this._buttonElement.addEventListener("click", (event) => {
25
            if (this.getEnabled()) {
26
                this.setActive(!this.getActive(), () => {
27
                });
28
            }
29
            event.preventDefault();
30
        });
31

32
        this.bimViewer.on("reset", () => {
33
            this.setActive(false);
34
        });
35

36
        this.viewer.camera.on("projection", () => {
37
            const isOrtho = (this.viewer.camera.projection === "ortho");
38
            this._active = isOrtho;
39
            if (this._active) {
40
                this._buttonElement.classList.add("active");
41
            } else {
42
                this._buttonElement.classList.remove("active");
43
            }
44
        });
45

46
        this._active = false;
47
        this._buttonElement.classList.remove("active");
48
    }
49

50
    setActive(active, done) {
51
        if (this._active === active) {
52
            if (done) {
53
                done();
54
            }
55
            return;
56
        }
57
        this._active = active;
58
        if (active) {
59
            this._buttonElement.classList.add("active");
60
            if (done) {
61
                this._enterOrthoMode(() => {
62
                    this.fire("active", this._active);
63
                    done();
64
                });
65
            } else {
66
                this._enterOrthoMode();
67
                this.fire("active", this._active);
68
            }
69
        } else {
70
            this._buttonElement.classList.remove("active");
71
            if (done) {
72
                this._exitOrthoMode(() => {
73
                    this.fire("active", this._active);
74
                    done();
75
                });
76
            } else {
77
                this._exitOrthoMode();
78
                this.fire("active", this._active);
79
            }
80
        }
81
    }
82

83
    _enterOrthoMode(done) {
84
        if (done) {
85
            this.viewer.cameraFlight.flyTo({projection: "ortho", duration: 0.5}, done);
86
        } else {
87
            this.viewer.cameraFlight.jumpTo({projection: "ortho"});
88
        }
89
    }
90

91
    _exitOrthoMode(done) {
92
        if (done) {
93
            this.viewer.cameraFlight.flyTo({projection: "perspective", duration: 0.5}, done);
94
        } else {
95
            this.viewer.cameraFlight.jumpTo({projection: "perspective"});
96
        }
97
    }
98
}
99

100
export {OrthoMode};

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.