-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
159 lines (133 loc) · 4.68 KB
/
script.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//Loader
const overlay = document.querySelector(".overlay")
window?.addEventListener("load", function () {
overlay.style.display = "none"
});
// APIs
const api_url_id = 'https://api.wheretheiss.at/v1/satellites/25544'
const api_url_name = 'http://api.open-notify.org/astros.json'
// Config map
const mymap = L.map('mapBg').setView([0, 0], 2)
//const tileUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
//const tileUrl = 'http://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png'
const tileUrl = 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png'
const ISSIcon = L.icon({
iconUrl: "imagens/ISS.svg",
iconSize: [62, 40],
// iconAnchor: [25, 36],
});
const marker = L.marker([0, 0], {icon: ISSIcon}).addTo(mymap)
const circle = L.circle({lat: 0, lng: 0}, {
color: '#00ffff',
fillColor:'#00ffff',
fillOpacity: 0,
weight: 2,
radius: 800000,
opacity: 0.5,
}).addTo(mymap)
// Copyright
const attribution = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
const tiles = L.tileLayer(tileUrl, { attribution })
mymap.zoomControl.remove()
tiles.addTo(mymap)
option();
// GET API [Wheretheiss]
let center = true
async function getISS() {
const response = await fetch(api_url_id)
const data = await response.json()
const {
name,
altitude,
latitude,
longitude,
velocity,
visibility,
timestamp
} = data
marker.setLatLng([latitude, longitude])
circle.setLatLng([latitude, longitude])
if(center){
if(window.innerWidth > 1500){
mymap.setView([latitude, longitude], 3)
center = false
}else if(window.innerWidth > 1000){
mymap.setView([latitude, longitude + 40], 3)
center = false
}else if(window.innerWidth > 550){
mymap.setView([latitude, longitude], 3)
center = false
document.getElementById('tele').checked = true
tele()
} else{
mymap.setView([latitude, longitude], 2)
center = false
document.getElementById('live1').style.visibility="visible"
document.getElementById('live2').style.visibility="visible"
}
}
var time = new Date(timestamp * 1000)
var target_date = new Date("january 01, 2031").getTime();
var dias, horas, minutos, segundos;
var current_date = new Date().getTime();
var segundos_f = (target_date - current_date) / 1000;
dias = parseInt(segundos_f / 86400);
segundos_f = segundos_f % 86400;
horas = parseInt(segundos_f / 3600);
segundos_f = segundos_f % 3600;
minutos = parseInt(segundos_f / 60);
segundos = parseInt(segundos_f % 60);
document.getElementById('name').textContent = name
document.getElementById('latitude').textContent = latitude + "°"
document.getElementById('longitude').textContent = longitude + "°"
document.getElementById('altitude').textContent = altitude.toFixed(2) + " km"
document.getElementById('velocidade').textContent = velocity.toFixed(2) + " km/h"
document.getElementById('timestamp').textContent =
time.getUTCDate() + "/" +
(time.getUTCMonth() + 1) + "/" +
time.getUTCFullYear() + " " +
time.getUTCHours() + ":" +
time.getUTCMinutes() + ":" +
time.getUTCSeconds() + " UTC"
document.getElementById('Tdesorbita').textContent = "T- " + dias + " D | " + horas + ":" + minutos + ":" + segundos
visib(visibility);
aligh();
}
getISS()
setInterval(getISS, 2000)
function visib(visibility){
if(visibility === "daylight"){
document.getElementById('visibility').textContent = "Dia"
}else{
document.getElementById('visibility').textContent = "Noite"
}
}
function live(){
if(document.getElementById('ibm').checked){
option();
}else{
document.getElementById('live1').style.visibility="hidden"
document.getElementById('live2').style.visibility="hidden"
}
}
function option(){
if(document.getElementById('optionLive').checked){
document.getElementById('live1').style.visibility="visible"
document.getElementById('live2').style.visibility="hidden"
}else{
document.getElementById('live1').style.visibility="hidden"
document.getElementById('live2').style.visibility="visible"
}
}
function aligh(){
if(document.getElementById('checkbox').checked){
center = true
}
}
function tele(){
if(document.getElementById('tele').checked){
document.getElementById('info').style.visibility="visible"
}else{
document.getElementById('info').style.visibility="hidden"
}
}