-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.html
324 lines (222 loc) · 8.94 KB
/
map.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
<style>
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap");
:root {
--primary-light: rgb(245, 245, 245);
--primary-light-glass: rgba(245, 245, 245, 0.4);
--primary-dark: rgb(18, 19, 20);
--primary-dark-glass: rgb(18, 19, 20, 0.4);
--secondary-light: rgb(230, 230, 230);
--secondary-light-glas: rgb(230, 230, 230, 0.4);
--secondary-dark: rgb(28, 29, 30);
--secondary-dark-glass: rgb(28, 29, 30, 0.4);
}
* {
padding: 0;
margin: 0;
font-family: "Inter", sans-serif;
}
#map {
height: 100vh;
z-index: 1;
}
.info-flex{
z-index: 2;
/* background-color: transparent; */
color: black;
position: absolute;
right: 1.5em;
top : 1.5em;
background-color: var(--primary-light-glass);
color : var(--primary-dark);
backdrop-filter: blur(5px);
padding : 1em;
border: black solid 2px;
border-radius: 20px;
display: flex;
flex-direction: column;
gap : 1em;
color : black;
}
</style>
</head>
<body>
<div class = "info-flex">
</div>
<div id="map"></div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<script>
//leaf let js map set
var map = L.map('map').setView([-6.082, 145.392], 13);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 15,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
// Add a marker with custom icon
var redIcon = L.icon({
iconUrl: 'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});
var via = L.icon({
iconUrl: 'https://raw.githubusercontent.com/Four-Bits/Aerothon-6.0/main/assets/DotMarker.png?token=GHSAT0AAAAAACSDVPVCSK2LNSPOO42GNY6WZSQ4CJQ',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
});
// open-weather api
const API_KEY = '3df6836ada8bae1010a0706d2b45f0af';
function fetchWeatherData(latitude, longitude) {
const apiUrl = `https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=${API_KEY}`;
return fetch(apiUrl)
.then(response => response.json())
.then(data => data)
.catch(error => console.error('Error fetching weather data:', error));
}
// Check if take off is true/false
function canTakeOff(weatherData) {
const windSpeedThreshold = 20; // knots
const gustThreshold = 10; // knots above steady wind speed
const visibilityThreshold = 1500; // meters
const cloudCoverThreshold = 1000; // feet AGL
const temperatureThreshold = 40; // Celsius
const description = weatherData.weather[0].description;
const windSpeed = weatherData.wind.speed * 1.94384; // Convert m/s to knots
const gust = weatherData.wind.gust * 1.94384; // Convert m/s to knots
const visibility = weatherData.visibility;
const cloudCover = weatherData.clouds.all;
const temperature = weatherData.main.temp - 273.15; // Convert Kelvin to Celsius
// console.log(gust,windSpeed,gustThreshold)
const windss = windSpeed.toFixed(2)
return {
canTakeOff: windSpeed <= windSpeedThreshold &&
visibility >= visibilityThreshold &&
temperature < temperatureThreshold,
windss,
gust,
visibility,
cloudCover,
temperature,
description
};
}
//Main
// Start of json reading and api req
fetch('suggestions.json')
.then(response => response.json())
.then(data => {
function fetchCoordinates(airportName) {
const coordinates = data[airportName];
if (coordinates) {
return coordinates
} else {
return null;
}
}
const url = window.location.href;
// Log the full URL to the console
// console.log(`Full URL: ${url}`);
// Split the URL by '?'
const splitUrl = url.split('?');
// Log the split parts to the console
// console.log('URL Split by ?:', splitUrl);
const sdd = splitUrl[1].split('&')
const source_des = sdd[0].split('-')
const datas = sdd[1].split('=')
const routee = datas[1].split(',')
const airportName = source_des[0]
const destination = source_des[1]
const coordinates = data[airportName]
const dcoordinates = data[destination]
function findRoutes(segments, source, destination) {
const routes = [];
let route = [];
let capturing = false;
for (let i = 0; i < segments.length; i++) {
if (segments[i] === source && !capturing) {
capturing = true;
route = [source];
} else if (capturing) {
route.push(segments[i]);
if (segments[i] === destination) {
routes.push(route);
capturing = false;
}
}
}
return routes;
}
const routes = findRoutes(routee, airportName, destination);
var latlngs = []
routes.forEach(route => {
route.forEach(airport => {
let coord = data[airport]
latlngs.push([coord.latitude,coord.longitude])
});
});
console.log(latlngs)
const latitude = latlngs[0][0]
const longitude = latlngs[0][1]
fetchWeatherData(latitude, longitude)
.then(weatherData => {
const takeOffStatus = canTakeOff(weatherData);
console.log('Can take off:', takeOffStatus.canTakeOff);
console.log('Wind speed:', takeOffStatus.windss);
console.log('Gust:', takeOffStatus.gust);
console.log('Visibility:', takeOffStatus.visibility);
console.log('Cloud cover:', takeOffStatus.cloudCover);
console.log('Temperature:', takeOffStatus.temperature);
console.log('description:', takeOffStatus.description);
let infoFlex = document.querySelector(".info-flex");
let li = document.createElement('div');
li.textContent = 'Can take off : ' + takeOffStatus.canTakeOff;
infoFlex.appendChild(li)
let l2 = document.createElement('div');
l2.textContent = 'Wind speed : ' + takeOffStatus.windss
infoFlex.appendChild(l2)
// let l3 = document.createElement('div');
// l3.textContent = 'Gust : '+ takeOffStatus.gust
// infoFlex.appendChild(l3)
let l4 = document.createElement('div');
l4.textContent = 'Visibility : '+ takeOffStatus.visibility;
infoFlex.appendChild(l4)
let l5 = document.createElement('div');
l5.textContent = 'Cloud cover : ' + takeOffStatus.cloudCover
infoFlex.appendChild(l5)
let l6 = document.createElement('div');
l6.textContent = 'Temperature : '+ takeOffStatus.temperature;
infoFlex.appendChild(l6)
let l7 = document.createElement('div');
l7.textContent = 'description : '+ takeOffStatus.description;
infoFlex.appendChild(l7)
// document.write(takeOffStatus.visibility)
});
var polyline = L.polyline(latlngs, {color: '#d64d3e'}).addTo(map);
map.fitBounds(polyline.getBounds());
// console.log(`Coordinates for ${airportName}: Latitude=${coordinates.latitude}, Longitude=${coordinates.longitude}`);
L.marker([coordinates.latitude,coordinates.longitude ]).addTo(map)
.bindPopup(coordinates.airport_name)
.openPopup();
// for(i=1;i<routes.length-1;i++){
// L.marker([latlngs[i][0], latlngs[i][1]], { icon: via }).addTo(map)
// }
// L.marker([coordinates.latitude,coordinates.longitude ]).addTo(map);
L.marker([dcoordinates.latitude, dcoordinates.longitude], { icon: redIcon }).addTo(map)
.bindPopup(dcoordinates.airport_name)
.openPopup();
})
.catch(error => console.error('Error fetching data:', error));
</script>
</body>
</html>