-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.js
70 lines (70 loc) · 3.26 KB
/
view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _View_w, _View_h, _View_wh_min, _View_scaleExponent, _View_scale;
class View {
constructor() {
this.x = 0;
this.y = 0;
_View_w.set(this, 1);
_View_h.set(this, 1);
_View_wh_min.set(this, 1);
_View_scaleExponent.set(this, 0);
_View_scale.set(this, 2 ** __classPrivateFieldGet(this, _View_scaleExponent, "f"));
}
get scale() {
return __classPrivateFieldGet(this, _View_scale, "f");
}
get scaleExponent() {
return __classPrivateFieldGet(this, _View_scaleExponent, "f");
}
set scaleExponent(n) {
__classPrivateFieldSet(this, _View_scaleExponent, n, "f");
__classPrivateFieldSet(this, _View_scale, 2 ** __classPrivateFieldGet(this, _View_scaleExponent, "f"), "f");
}
resize() {
__classPrivateFieldSet(this, _View_w, window.innerWidth, "f");
__classPrivateFieldSet(this, _View_h, window.innerHeight, "f");
__classPrivateFieldSet(this, _View_wh_min, Math.min(__classPrivateFieldGet(this, _View_w, "f"), __classPrivateFieldGet(this, _View_h, "f")), "f");
return [__classPrivateFieldGet(this, _View_w, "f"), __classPrivateFieldGet(this, _View_h, "f")];
}
get w() {
return __classPrivateFieldGet(this, _View_w, "f");
}
get h() {
return __classPrivateFieldGet(this, _View_h, "f");
}
get wh_min() {
return __classPrivateFieldGet(this, _View_wh_min, "f");
}
clone() {
const clone = new View();
clone.x = this.x;
clone.y = this.y;
clone.scaleExponent = __classPrivateFieldGet(this, _View_scaleExponent, "f");
return clone;
}
mapToScreen(x, y) {
return [
(x / 180 * this.wh_min - this.x) * this.scale + this.w / 2,
(y / 180 * this.wh_min - this.y) * this.scale + this.h / 2
];
}
screenToMap(x, y) {
return [
((x - this.w / 2) / this.scale + this.x) / this.wh_min * 180,
((y - this.h / 2) / this.scale + this.y) / this.wh_min * 180
];
}
}
_View_w = new WeakMap(), _View_h = new WeakMap(), _View_wh_min = new WeakMap(), _View_scaleExponent = new WeakMap(), _View_scale = new WeakMap();
;
export const view = new View();