Repository navigation
Expand file tree
/
Copy pathidle.js
More file actions
executable file
·129 lines (128 loc) · 4.87 KB
/
Copy pathidle.js
File metadata and controls
executable file
·129 lines (128 loc) · 4.87 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
function idle() {
let idle = null;
const tour = {
idling: false,
next: 0,
steps: config.tour || [ "standard", `${config.zoom}/${config.lat}/${config.lon}`, `wait ${config.idle}` ]
};
function nodeLocation(chostname) {
const n = nodes[chostname];
const loc = getRealLatLon(n && n.data);
if (loc.lat && loc.lon) {
return [ loc.lon, loc.lat ];
}
return null;
}
function tourStep() {
idle = null;
for (;;) {
const step = tour.steps[tour.next];
tour.next = (tour.next + 1) % tour.steps.length;
if (step.indexOf("wait") === 0) {
const wait = parseFloat(step.substring(4)) || 30;
idle = setTimeout(tourStep, wait * 1000);
break;
}
else if (step.indexOf("rotate") === 0) {
let rotTime = parseFloat(step.substring(6)) || 30;
const halfRotTime = 30;
function rot() {
if (idle) {
return;
}
else if (rotTime > 0) {
const time = Math.min(rotTime, halfRotTime);
rotTime -= time;
map.rotateTo((map.getBearing() + 179.9 / halfRotTime * time) % 360, { duration: time * 1000, easing: t => t });
map.once("moveend", rot);
}
else {
tourStep();
}
}
rot();
break;
}
else if (step.indexOf("open") === 0) {
const chostname = step.substring(4).trim().toUpperCase();
const lnglat = nodeLocation(chostname);
if (lnglat) {
openPopup();
showNodePopup(chostname, lnglat);
}
}
else if (step === "random") {
const names = Object.keys(nodes).filter(cname => nodeLocation(cname));
const chostname = names[Math.min(names.length - 1, Math.floor(Math.random() * names.length))];
const lnglat = nodeLocation(chostname);
openPopup();
map.flyTo({ center: lnglat, elevation: map.queryTerrainElevation(lnglat) || 0, speed: 1, zoom: 15, pitch: 60, bearing: 0 });
map.once("moveend", () => {
if (!idle) {
showNodePopup(chostname, lnglat);
tourStep();
}
});
break;
}
else if (nodeLocation(step.toUpperCase())) {
const chostname = step.toUpperCase();
const lnglat = nodeLocation(chostname);
openPopup();
map.flyTo({ center: lnglat, elevation: map.queryTerrainElevation(lnglat) || 0, speed: 1, zoom: 15, pitch: 60, bearing: 0 });
map.once("moveend", () => {
if (!idle) {
showNodePopup(chostname, lnglat);
tourStep();
}
});
break;
}
else if (mapStyles[step]) {
selectMap(step, true);
}
else {
const loc = step.split("/");
if (loc.length === 3) {
loc.push(0, 0);
}
if (loc.length == 5) {
openPopup();
map.flyTo({ center: [ parseFloat(loc[2]), parseFloat(loc[1]) ], speed: 1, zoom: parseFloat(loc[0]), pitch: parseFloat(loc[4]), bearing: parseFloat(loc[3]) });
map.once("moveend", () => {
if (!idle) {
tourStep();
}
});
break;
}
}
}
}
function notIdle() {
tour.next = 0;
clearTimeout(idle);
idle = setTimeout(function() {
tour.idling = true;
openPopup();
filterKey();
setMode("normal");
tourStep();
}, config.idle * 1000);
if (tour.idling) {
tour.idling = false;
openPopup();
selectMap("standard", false);
map.getContainer().style.pointerEvents = "none";
map.flyTo({ center: [ config.lon, config.lat ], speed: 1, zoom: config.zoom, pitch: 0, bearing: 0 });
map.once("moveend", () => {
map.getContainer().style.pointerEvents = "";
});
}
}
[ "mousemove", "mousedown", "touchstart", "click", "keypress", "scroll" ].forEach(function(name) {
document.addEventListener(name, notIdle);
});
screen.orientation.addEventListener("change", notIdle);
notIdle();
}