-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
281 lines (273 loc) · 14.9 KB
/
index.html
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Geogo</title>
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ==" crossorigin="" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ==" crossorigin=""></script>
<style>
.loader {
position: absolute;
top: 40%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3c9144;
border-right: 16px solid green;
border-bottom: 16px solid #608754;
border-left: 16px solid #326124;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
position: absolute;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -50px;
width: 100px;
height: 100px;
}
@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
html,
body {
height: 100%;
margin: 0;
text-align: center;
background-color: #191a1a;
}
#panoramamap {
height: 100%;
width: 100%;
margin: 0 auto;
}
#map {
width: 100%;
height: 100%;
display: inline-block;
display: none;
z-index: 1;
background-color: #191a1a;
}
.btn,
#btn {
padding: 20px;
border: 2px solid slategray;
cursor: pointer;
margin: 10px;
width: 80px;
font-size: 500;
border-radius: 89px;
position: absolute;
bottom: 0;
left: 0;
margin: 20px;
z-index: 22;
height: 80px;
font-family: arial;
font-size: 20px;
background-color: rgba(0, 0, 0, 0.411);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
text-shadow: 2px 2px 4px #000000;
color: white;
box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px, rgba(51, 51, 51, 0.377) 0px 0px 0px 3px;
transition: all .2s ease-in-out;
}
#btn {
margin-left: 130px;
}
.btn:hover,
#btn:hover {
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
background-color: rgba(0, 0, 0, 0.59);
transition: all .2s ease-in-out;
}
.leaflet-control-zoom {
z-index: 33 !important;
}
.leaflet-control-container {
display: none !important;
}
</style>
</head>
<body>
<div class="loader"></div>
<div id="panoramamap"></div>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAQS_xg1zCJD9I2OpnlFvTnuzeIc46eQOE&callback=generateRandomPoint&libraries=&v=weekly" async></script>
<div id="map"></div>
<button id="btn" style="right:0;left:unset;width:60px;height:60px" onclick="location.reload()">
<svg style="padding-bottom:10px" fill="white" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve"> <metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata> <g> <path d="M570,86V10L290,185l280,175V228.5c140,32,245,156.9,245,306.5c0,173.7-141.3,315-315,315S185,708.7,185,535c0-38.7-31.3-70-70-70s-70,31.3-70,70c0,250.9,204.1,455,455,455s455-204.1,455-455C955,308,787.6,119.8,570,86z" /></g></svg>
</button>
<button class="btn" id="check1" style="bottom:0;left:0;top:unset;margin:20px;margin-left:110px">
<svg fill="white" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 122.877 101.052" enable-background="new 0 0 122.877 101.052" xml:space="preserve"> <g> <path d="M4.43,63.63c-2.869-2.755-4.352-6.42-4.427-10.11c-0.074-3.689,1.261-7.412,4.015-10.281 c2.752-2.867,6.417-4.351,10.106-4.425c3.691-0.076,7.412,1.255,10.283,4.012l24.787,23.851L98.543,3.989l1.768,1.349l-1.77-1.355 c0.141-0.183,0.301-0.339,0.479-0.466c2.936-2.543,6.621-3.691,10.223-3.495V0.018l0.176,0.016c3.623,0.24,7.162,1.85,9.775,4.766 c2.658,2.965,3.863,6.731,3.662,10.412h0.004l-0.016,0.176c-0.236,3.558-1.791,7.035-4.609,9.632l-59.224,72.09l0.004,0.004 c-0.111,0.141-0.236,0.262-0.372,0.368c-2.773,2.435-6.275,3.629-9.757,3.569c-3.511-0.061-7.015-1.396-9.741-4.016L4.43,63.63 L4.43,63.63z" /> </g> </svg>
</button>
<button class="btn" id="mapBtn" style="bottom:0;left:0;top:unset;margin:20px;" onclick="if(location1){toggleMap();fixMap()}">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" fill="white" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 100.353 100.352" style="enable-background:new 0 0 100.353 100.352;" xml:space="preserve"> <g> <path d="M69.55,58.903c-0.005,0-0.011,0-0.016,0c-0.523-0.006-1.005-0.283-1.273-0.732L54.003,34.226 c-0.04-0.067-0.074-0.136-0.103-0.208c-1.778-2.919-2.716-6.264-2.716-9.693c0.018-10.311,8.414-18.689,18.72-18.689 c0.008,0,0.015,0,0.023,0c5.003,0.007,9.7,1.961,13.226,5.501c3.524,3.537,5.46,8.239,5.453,13.238l0,0 c0,3.378-0.934,6.705-2.704,9.642c-0.034,0.096-0.079,0.188-0.134,0.277L70.823,58.199C70.547,58.636,70.066,58.903,69.55,58.903z M56.719,32.923l12.862,21.601l13.476-21.555c0.034-0.092,0.077-0.182,0.13-0.267c1.582-2.527,2.418-5.407,2.418-8.328 c0-0.001,0-0.001,0-0.002c0.007-4.2-1.619-8.148-4.578-11.119c-2.96-2.971-6.904-4.611-11.104-4.618c-0.006,0-0.013,0-0.02,0 c-8.655,0-15.705,7.035-15.719,15.692c0,2.954,0.831,5.836,2.402,8.332C56.64,32.742,56.684,32.831,56.719,32.923z" /> <path d="M69.909,31.352c-0.005,0-0.01,0-0.016,0c-2.112,0-4.101-0.825-5.596-2.323c-1.497-1.5-2.319-3.492-2.315-5.611 c0.002-2.112,0.828-4.099,2.326-5.593c1.496-1.491,3.482-2.312,5.595-2.312c0.002,0,0.005,0,0.008,0 c4.365,0.005,7.914,3.563,7.91,7.932l0,0c-0.002,2.115-0.828,4.103-2.326,5.597C74,30.532,72.017,31.352,69.909,31.352z M69.902,18.513c-1.312,0-2.547,0.51-3.476,1.437c-0.93,0.927-1.443,2.161-1.444,3.473c-0.002,1.317,0.509,2.555,1.439,3.487 c0.928,0.93,2.163,1.442,3.475,1.442c0.003,0,0.006,0,0.01,0c1.312,0,2.543-0.509,3.471-1.434c0.93-0.927,1.443-2.162,1.444-3.475 c0.002-2.714-2.202-4.926-4.914-4.929C69.906,18.513,69.904,18.513,69.902,18.513z M76.321,23.444h0.01H76.321z" /> <path d="M94.399,80.181H4.541c-0.504,0-0.974-0.253-1.252-0.674c-0.277-0.42-0.325-0.952-0.127-1.416l16.345-38.242 c0.236-0.552,0.779-0.911,1.379-0.911h38.568c0.829,0,1.5,0.671,1.5,1.5s-0.671,1.5-1.5,1.5H21.876L6.813,77.18h85.313 L77.528,43.03c-0.326-0.762,0.028-1.643,0.79-1.969c0.759-0.325,1.643,0.027,1.969,0.79L95.778,78.09 c0.198,0.464,0.15,0.996-0.127,1.416C95.373,79.928,94.903,80.181,94.399,80.181z" /> <path d="M69.727,79.912c-0.752,0-1.401-0.564-1.488-1.33c-0.009-0.074-0.967-7.454-11.3-9.207c-0.961-0.163-2.494-0.312-4.27-0.483 c-9.779-0.946-18.699-2.174-20.419-6.747c-1.11-2.95,0.512-5.199,1.814-7.006c1.426-1.978,1.896-2.842,1.168-4.083 c-0.461-0.786-1.929-1.426-3.349-2.045c-2.78-1.212-6.588-2.872-6.608-7.422c-0.004-0.829,0.665-1.503,1.493-1.507 c0.002,0,0.005,0,0.007,0c0.826,0,1.496,0.667,1.5,1.493c0.011,2.42,1.824,3.385,4.808,4.686c1.86,0.811,3.783,1.649,4.738,3.278 c1.785,3.044-0.011,5.536-1.322,7.355c-1.23,1.706-1.958,2.821-1.44,4.195c1.205,3.203,12.481,4.293,17.9,4.818 c1.833,0.177,3.416,0.33,4.482,0.511c12.532,2.127,13.734,11.43,13.779,11.825c0.094,0.823-0.497,1.566-1.32,1.66 C69.842,79.909,69.784,79.912,69.727,79.912z" /> </g> </svg>
</button>
<script>
var location1;
var panorama;
var counter = 0;
var marker;
var map;
var userLoc;
var alreadyGuessed = false;
var country;
function generateRandomPoint() {
console.log('generating.... attempt ' + counter++);
var sv = new google.maps.StreetViewService();
sv.getPanoramaByLocation(
new google.maps.LatLng(Math.random() * 180 - 90, Math.random() * 360 - 180), 6123, processSVData
);
}
function processSVData(data, status) {
if (status == google.maps.StreetViewStatus.OK) {
location1 = data.location.latLng.toUrlValue(6).split(',').map(Number);
var [lat, lng] = location1;
location1 = { lat, lng };
panorama = new google.maps.StreetViewPanorama(
document.getElementById("panoramamap"), {
position: data.location.latLng,
pov: {
heading: 34,
pitch: 10,
},
disableDefaultUI: true,
}
);
panorama.setOptions({
showRoadLabels: false
});
document.querySelector('.loader').style.display = 'none';
init();
} else {
generateRandomPoint();
}
}
function init() {
fetch(`http://api.geonames.org/countryCodeJSON?lat=${location1['lat']}&lng=${location1['lng']}&username=geo3`)
.then(function (response) {
return response.json();
})
.then(function (data) {
country = data["countryName"];
})
.catch(function () {
console.log("Error. could not get country name");
});
map = L.map('map').setView([0, 0], 0);
map.options.minZoom = 1;
var Stadia_AlidadeSmooth = L.tileLayer('https://{s}.tile.jawg.io/jawg-dark/{z}/{x}/{y}{r}.png?access-token=XPIs2MtNY5E0YVXCb2eFXHkicbL7dlegsyz9juu2OM66dvDMRYstdW5T9ntc8u3V', {
noWrap: true,
}).addTo(map);
map.setMaxBounds([[-90, -180], [90, 180]]);
map.setZoom(1.5);
map.invalidateSize(true);
prompt(location1);
}
function prompt(loc) {
console.log('yes');
map.on('click', onMapClick);
}
function onMapClick(e) {
if (!alreadyGuessed) {
map.eachLayer((layer) => {
if (layer['_latlng'] != undefined)
layer.remove();
});
marker = L.marker(e.latlng).addTo(map);
userLoc = e.latlng;
}
}
function lineate(guess, loc) {
var polylinePoints = [guess, loc];
marker = L.marker(loc).addTo(map);
var polyline = L.polyline(polylinePoints, { color: 'blue', radius: 500 }).addTo(map);
}
function getDistance(from, to) {
return (from.distanceTo(to)).toFixed(0) / 1000; // in km
}
function fixMap() {
map.invalidateSize(true);
}
function toggleMap() {
if (document.querySelector('#map').style.display == 'none' || document.querySelector('#map').style.display == '') {
document.querySelector('#panoramamap').style.display = 'none';
document.querySelector('.btn').disabled = false;
document.querySelector("#check1").style.display = "block";
document.querySelector('#map').style.display = 'block';
console.log(document.querySelector('#map').style.display);
} else {
document.querySelector('#panoramamap').style.display = 'block';
document.querySelector('.btn').disabled = true;
document.querySelector("#check1").style.display = "none";
document.querySelector('#map').style.display = 'none';
console.log('no......');
}
}
document.querySelector('#panoramamap').onclick = () => {
location1 = panorama.position.toUrlValue(6).split(',').map(Number);
var [lat, lng] = location1;
location1 = { lat, lng };
};
document.querySelector(".btn").onclick = () => {
map.setView([0, 0], 0);
map.eachLayer((layer) => {
if (layer['_latlng'] != undefined)
layer.remove();
});
fetch(`http://api.geonames.org/countryCodeJSON?lat=${location1['lat']}&lng=${location1['lng']}&username=geo3`)
.then(function (response) {
return response.json();
})
.then(function (data) {
country = data["countryName"];
})
.catch(function () {
console.log("Error. could not get country name");
});
alreadyGuessed = true;
lineate(userLoc, location1);
alert(`you guessed ${Math.round(getDistance(userLoc, location1) / 1.609)} miles away. The correct country was ${(country == "undefined" || country == undefined) ? ("some tiny island or the ocean. (error code " + (Math.random() * (899 - 101) + 101) + " - " + country + ")") : country}`);
};
document.querySelector("#check1").style.display = "none";
function toggleMap(map) {
if (document.querySelector('#map').style.display == 'none' || document.querySelector('#map').style.display == '') {
document.querySelector('#panoramamap').style.display = 'none';
document.querySelector('.btn').disabled = false;
document.querySelector("#check1").style.display = "block";
document.querySelector('#map').style.display = 'block';
console.log(document.querySelector('#map').style.display);
} else {
document.querySelector('#panoramamap').style.display = 'block';
document.querySelector('.btn').disabled = true;
document.querySelector("#check1").style.display = "none";
document.querySelector('#map').style.display = 'none'
console.log('no......')
}
}
</script>
</body>
</html>