-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
130 lines (113 loc) · 4.38 KB
/
map.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
const TLEJS = require('tle.js');
const tlejs = new TLEJS();
mapboxgl.accessToken = 'pk.eyJ1IjoidGhlc25la3lzbmVrIiwiYSI6ImNqZHc2ZzExcDBpMDQycXM0Nm5nZGNlanMifQ.K9Mxb2Dkl_6cyspBwga1XA';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/thesnekysnek/cjy1l50bh0xg71coetzys6s16'
});
var socket = io();
var stations = []
var tle = []
var observations = []
var getJSON = function (url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function () {
var status = xhr.status;
if (status === 200) {
callback(null, xhr.response);
} else {
callback(status, xhr.response);
}
};
xhr.send();
};
map.on('load', function () {
// When a click event occurs on a feature in the places layer, open a popup at the
// location of the feature, with description HTML from its properties.
map.on('click', 'points', function (e) {
var coordinates = e.features[0].geometry.coordinates.slice();
var description = e.features[0].properties.description;
// Ensure that if the map is zoomed out such that multiple
// copies of the feature are visible, the popup appears
// over the copy being pointed to.
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
new mapboxgl.Popup()
.setLngLat(coordinates)
.setHTML(description)
.addTo(map);
});
// Change the cursor to a pointer when the mouse is over the places layer.
map.on('mouseenter', 'points', function () {
map.getCanvas().style.cursor = 'pointer';
});
// Change it back to a pointer when it leaves.
map.on('mouseleave', 'points', function () {
map.getCanvas().style.cursor = '';
});
//Stations
getJSON('stations.json', function (err, data) {
stations = data
var mapS = []
for (let i = 0; i < stations.length; i++) {
const s = stations[i];
mapS.push({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [s.lng, s.lat]
},
"properties": {
"color": "255,0,0",
"description": "<strong>" + s.name + "</strong>"
}
})
}
map.addLayer({
"id": "points",
"type": "symbol",
"type": "circle",
"paint": {
"circle-radius": 4,
"circle-color": "#007cbf"
},
"source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": mapS
}
}
});
});
//TLE
getJSON('tle.json', function (err, data) {
tle = data
});
//Observations
getJSON('observations.json', function (err, data) {
var sats = []
observations = data
for (let i = 0; i < data.length; i++) {
const o = data[i];
if(sats.includes(o.norad_cat_id)){
sats.push(o.norad_cat_id)
}
}
});
})
function showSats() {
var data = []
for (let i = 0; i < sats.length; i++) {
const s = sats[i];
var loc = tlejs.getLatLon(tle[sats[i]])
data.push({"type": "Point",
"coordinates": [
loc.lng,
loc.lat
]})
}
}