-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiframe-main.js
76 lines (71 loc) · 2.15 KB
/
iframe-main.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
"use strict";
console.log('dkdk')
const svg = document.getElementsByTagName('svg')[0];
const mapBorder = document.getElementsByClassName('mapborder')[0];
window.addEventListener("message",function(e){
console.log(`in iframe: ${e.data.join('|')}`);
let queryPoints = e.data;
let output = [];
for(let [latitude, longitude] of queryPoints){
let x = thetaToX(longitude);
let y = phiToY(latitude);
let element = document.elementFromPoint(x, y);
if(element === svg || element === mapBorder || element === null ||element === undefined||element === this.document.documentElement){
throw new Error(`The search somehow went out of bounds: the element found was ${element}`);
}
output.push([...element.classList]);
}
window.parent.postMessage(output);
console.log('here22')
});
function xToTheta(x){
if(x < 0 || x > 1100){
throw new RangeError(`The input x: ${x}, is outside of the svg x pos range of 0 to 1100.`);
}
if(x < 1069){
return(0.3272524367143436 * x - 169.855708194561);
}else{
return(0.3272524367143436 * x - 529.8328548476334);
}
}
function thetaToX(theta){
let x;
if(theta < -180 || theta > 180){
throw new RangeError(`The input theta: ${theta} is outside of the range of -180 to 180`)
}
if(theta > -169.855708194561){
x = (3.0557450084715274 * theta + 519.0357324759261);
}else{
x = (3.0557450084715274 * theta + 1619.034101524875);
}
if(x >=1100){
return 1099;
}
else if(x < 1){
return 1;
}
else{
return x;
}
}
function yToPhi(y){
if(y < 0 || y > 549.8){
throw new RangeError(`The input y:${y}, is outside of the svg y pos range of 0 to 549.8`);
}
return(y * -0.32712491274676575 + 89.95015451446541);
}
function phiToY(phi){
if(phi < -90 || phi > 90){
throw new RangeError(`The input phi: ${phi} is outside of the range of -90 to 90`)
}
let y = (phi * -3.056936237608173 + 274.9718869137237);
if(y >= 550){
return 549;
}
else if(y < 1){
return 1;
}
else{
return y;
}
}