-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpano_sampling_by_pano_size.js
135 lines (120 loc) · 4.11 KB
/
pano_sampling_by_pano_size.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
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
130
131
132
133
134
135
function chooseSamples(locsIterator) {
const progressIndicator = Object.assign(
document.createElement("span"),
{
// id: "pano-dimension-locs-progress"
}
);
document.getElementById("right-location").appendChild(progressIndicator);
// Map (dimension, uploder) => representativePano
const du2r = new Map();
let panoCounter = 0;
const total = locs.size;
/*
Use multiple tasks, since waiting for the server response is
the biggest time sink here
*/
const numParallelTasks = 4;
let tasksDoneCounter = 0;
for(let i = 0; i < numParallelTasks; i++) filterPanosTask();
async function filterPanosTask() {
while(true) {
const result = locsIterator.next();
if(result.done) break;
progressIndicator.textContent = `${++panoCounter}/${total}`;
const loc = result.value;
let panoRequest;
if(loc.panoId) {
if(loc.panoId.length != 22) {
panoRequest = {
pano: loc.panoId
};
}
else {
continue;
}
}
else {
panoRequest = {
location: {
lat: loc.lat,
lng: loc.lng
}
};
}
await svs.getPanorama(panoRequest).then(
(response) => {
const panoData = response.data;
const panoId = panoData.location.pano;
if(panoId.length > 22) {
const worldSize = panoData.tiles.worldSize;
const key = JSON.stringify({
width: worldSize.width,
height: worldSize.height,
contributor: panoData.location.profileUrl.slice(31)
});
if(!du2r.has(key)) {
du2r.set(key, panoId);
}
}
}
).catch(
(failureReason) => {
// console.warn(failureReason);
}
)
}
if(++tasksDoneCounter == numParallelTasks) filteringDone();
}
function filteringDone() {
viewingList = Array.from(du2r.entries()).map(
([key, panoId]) => {
const panoData = JSON.parse(key);
panoData.panoId = panoId;
return panoData;
}
).sort(
(a, b) => {
const widthDiff = a.width - b.width;
if(widthDiff != 0) return widthDiff;
return a.height - b.height;
}
);
const json = new Blob([JSON.stringify(viewingList)]);
browser.downloads.download({
url: URL.createObjectURL(json),
filename: "pano-size-contributor-samples.json"
});
interactiveSlideshow(viewingList);
}
}
function interactiveSlideshow(viewingList) {
let panoCounter = 0;
const total = viewingList.length;
const panoDimensionTextBox = document.getElementById("pano-size");
const nextButton = Object.assign(
document.createElement("button"),
{
textContent: "Next »"
}
);
nextButton.addEventListener(
"click",
(ev) => {
ev.target.disabled = true;
const loc = viewingList[panoCounter++];
pano.setPano(loc.panoId);
pano.setVisible(true);
progressIndicator.textContent = `${panoCounter}/${total}`;
if(loc.width == 2 * loc.height) {
panoDimensionTextBox.style.backgroundColor = null;
}
else {
panoDimensionTextBox.style.backgroundColor = "pink";
}
if(panoCounter < total) ev.target.disabled = false;
}
)
document.getElementById("right-location").appendChild(nextButton);
}
chooseSamples(locs.values());