-
Notifications
You must be signed in to change notification settings - Fork 141
/
adapter.js
77 lines (59 loc) · 1.47 KB
/
adapter.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
71
72
73
74
75
76
77
function setOrigin (origin) {
ORIGIN_X = origin.x;
ORIGIN_Y = origin.y;
}
function moveCam (offset) {
CAM_X = CENTER_X + offset.x;
CAM_Y = HEIGHT + offset.y;
Layers.render(true);
}
function setSize (size) {
WIDTH = size.width;
HEIGHT = size.height;
CENTER_X = WIDTH /2 <<0;
CENTER_Y = HEIGHT/2 <<0;
CAM_X = CENTER_X;
CAM_Y = HEIGHT;
Layers.setSize(WIDTH, HEIGHT);
MAX_HEIGHT = CAM_Z-50;
}
function setZoom (z) {
ZOOM = z;
MAP_SIZE = MAP_TILE_SIZE <<ZOOM;
const center = pixelToGeo(ORIGIN_X+CENTER_X, ORIGIN_Y+CENTER_Y);
const a = geoToPixel(center.latitude, 0);
const b = geoToPixel(center.latitude, 1);
PIXEL_PER_DEG = b.x-a.x;
Layers.setOpacity(Math.pow(0.95, ZOOM-MIN_ZOOM));
WALL_COLOR_STR = ''+ WALL_COLOR;
ALT_COLOR_STR = ''+ ALT_COLOR;
ROOF_COLOR_STR = ''+ ROOF_COLOR;
}
function onResize (e) {
setSize(e);
Layers.render();
Data.update();
}
function onMoveEnd (e) {
Layers.render();
Data.update(); // => fadeIn() => Layers.render()
}
function onZoomStart () {
IS_ZOOMING = true;
}
function onZoomEnd (e) {
IS_ZOOMING = false;
const factor = Math.pow(2, e.zoom-ZOOM);
setZoom(e.zoom);
// Layers.render(); // TODO: requestAnimationFrame() causes flickering because layers are already cleared
// show on high zoom levels only
if (ZOOM <= MIN_ZOOM) {
Layers.clear();
return;
}
Data.scale(factor);
Shadows.render();
Simplified.render();
Buildings.render();
Data.update(); // => fadeIn()
}