-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
329 lines (255 loc) · 9.63 KB
/
Copy pathtest.js
File metadata and controls
329 lines (255 loc) · 9.63 KB
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
325
326
327
328
329
/**
* Aufgabe04 Geosoftware1
* @author {Philipp Mundinger}
*/
////////////////////////////////////////////
//Berechnung der Entfernungen
//////////////////////////////////////
/*
var distanzen = [];
*/
//Funktion zur Distanzberechnung www.movable-type.co.uk/scripts/latlong.html
/**
* @param {Laengengrad Standort} lon1
* @param {Breitengrad Standort} lat1
* @param {Laengengrad Bushaltestelle} lon2
* @param {Breitengrad Bushaltestelle} lat2
* @returns
*/
function distanzRechner(lon1, lat1, lon2, lat2) {
const R = 6371e3; // metres
const φ1 = lat1 * Math.PI / 180; // φ, λ in radians
const φ2 = lat2 * Math.PI / 180;
const Δφ = (lat2 - lat1) * Math.PI / 180;
const Δλ = (lon2 - lon1) * Math.PI / 180;
const a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
Math.cos(φ1) * Math.cos(φ2) *
Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const d = R * c / 1000; // in km
return d;
}
var y = document.getElementById("demo");
/**
* Standortabfrage des Browsers
*/
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
y.innerHTML = "Geolocation is not supported by this browser.";
}
}
/**
* Makiert den Aktuellen Standort auf der Karte und ruft weitere Funktionen auf
* @param {Die Aktuelle Position des Stanortes} position
*/
function showPosition(position) {
y.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
console.log(position)
var greenIcon = L.icon({
iconUrl: 'marker.png',
iconSize: [100, 100], // size of the icon
iconAnchor: [22, 94], // point of the icon which will correspond to marker's location
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
});
L.marker({ lon: position.coords.longitude, lat: position.coords.latitude }, { icon: greenIcon }).bindPopup('Aktuelle Position <br>' + 'Latitude' + position.coords.latitude + '<br>Longitude' + position.coords.longitude).addTo(map);
abstandZuMeinemStandort(geodaten, position.coords.latitude, position.coords.longitude) //Abstand zur Bushaltestelle
}
//Klasse für die Haltestellen
class Haltestellen {
/**
* @param {Array} Koordinaten der Bushaltestellen
* @param {int} entfernung - Die Entfernung meines Standorts zu den Haltestellen
* @param {String} name - Name der Bushaltestelle
* @param {Array} stationenNummer - gibt die AbfahrtsstationenNummer des Busses
* @param {Array} koordinaten - Koordinaten der Bushaltestellen
*/
constructor(entfernung, name, stationenNummer, koordinaten) {
this.entfernung = entfernung;
this.name = name;
this.stationenNummer = stationenNummer;
this.koordinaten = koordinaten;
}
abstand(lat1, lon1) {
neueOrte.forEach(item => {
distanzen.push(distanzRechner(lon1, lat1, item[0], item[1]));
})
console.log(distanzen)
return distanzen;
}
}
//GeoJson Haltestellen einladen
var geo;
var x = new XMLHttpRequest()
x.open("GET", "https://rest.busradar.conterra.de/prod/haltestellen", true)
x.send();
x.onreadystatechange = function () {
if (x.status == "200" && x.readyState == 4) {
geo = JSON.parse(x.responseText)
console.log(geo)
BusArray(geo)
}
}
var geodaten = [] //Koordinaten der Bushaltestellen
var nameBushalte = [] //Name der Bushaltestellen
var station = []; //Nummer der Bushaltestellen
var nextToYou = [] //Entfernung der Bushaltestellen
var Bushaltestellen = []; //Bushaltestellen Objekte
/**
* Nimmt sich die Informationen der Namen und Koordinaten aus dem geo Datensatz
* @param {*} geo
*/
function BusArray(geo) {
//Koordinaten der Bushaltestellen
geo.features.forEach(element => {
geodaten.push(element.geometry.coordinates)
});
console.log(geodaten)
//Namen für jede Bushaltestelle
geo.features.forEach(item => {
nameBushalte.push(item.properties.lbez)
})
console.log(nameBushalte)
//Nummer der Bushaltestellen
geo.features.forEach(element => {
station.push(element.properties.nr)
})
console.log(station)
//Marker auf der Karte setzen
var punkt = L.icon({
iconUrl: 'punkt.png',
iconSize: [10, 10], // size of the icon
iconAnchor: [22, 94], // point of the icon which will correspond to marker's location
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
});
var i = 0;
var j = 0;
var k = 0;
var KoNameNr = []
geodaten.forEach(element => {
KoNameNr.push(element)
})
}
var erstenZwei = []
/**
* Erzeugt Objekte der Klasse Bus und Sortiert diese Objekte
* @param {Nummer der Station} station
* @param {entfernung der Station} nachste
* @param {Name der BUshaltestelle} nameBushalte
*/
function erstelleObjekte(nextToYou) {
var bus //Bus Objekt
var k = 0;
var i = 0;
var j = 0;
var l = 0;
while (station.length != k) {
bus = new Haltestellen(
nextToYou[i],
nameBushalte[j],
station[k],
geodaten[l]
)
i++;
j++;
k++
l++
Bushaltestellen.push(bus)
}
//Sortieren Des Arrays
Bushaltestellen.sort(function (a, b) {
return a.entfernung > b.entfernung;
});
console.log(Bushaltestellen)
plotteBus(Bushaltestellen)
erstenZwei.push(Bushaltestellen[0].stationenNummer)
busfahrplan(erstenZwei)
}
//Entfernung der Bushaltestellen zu meinem Punkt
/**
*
* @param {Datensatz mit den Koordinaten der Bushaltestellen} geodaten
* @param {Laengengrad Standort} lon1
* @param {Breitengrad Standort} lat1
*/
function abstandZuMeinemStandort(geodaten, lon1, lat1) {
geodaten.forEach(item => {
nextToYou.push(distanzRechner(lon1, lat1, item[1], item[0]))
})
console.log(nextToYou)
erstelleObjekte(nextToYou)
}
function plotteBus(Bushaltestellen) {
//Marker auf der Karte setzen
var punkt = L.icon({
iconUrl: 'punkt.png',
iconSize: [10, 10], // size of the icon
iconAnchor: [22, 94], // point of the icon which will correspond to marker's location
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
});
Bushaltestellen.forEach(element => {
L.marker({ lon: element.koordinaten[0], lat: element.koordinaten[1] }, { icon: punkt }).bindPopup('Name: ' + element.name + '</br>Nummer: ' + element.stationenNummer + '</br>Entfernung:' + element.entfernung).addTo(map).addTo(overlay);
})
}
function busfahrplan(erstenZwei) {
var abfahrt;
var time = new XMLHttpRequest()
y.onreadystatechange = function () {
if (time.status == "200" && time.readyState == 4) {
console.log(time.responseText)
abfahrt = JSON.parse(time.responseText)
document.getElementById("Datenbereich").innerHTML = unixINTOdate(abfahrt[0].abfahrtszeit)
console.log(abfahrt)
}
else {
console.log("Fehler")
}
}
//AbfahrtsstationenNummer einladen
time.open("GET", "https://rest.busradar.conterra.de/prod/haltestellen/" + erstenZwei + "/abfahrten?sekunden=3000", true)
time.send();
function unixINTOdate(unix) {
let unix_timestamp = unix
// Create a new JavaScript Date object based on the timestamp
// multiplied by 1000 so that the argument is in milliseconds, not seconds.
var date = new Date(unix_timestamp * 1000);
// Hours part from the timestamp
var hours = date.getHours();
// Minutes part from the timestamp
var minutes = "0" + date.getMinutes();
// Seconds part from the timestamp
var seconds = "0" + date.getSeconds();
// Will display time in 10:30:23 format
var formattedTime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
console.log(formattedTime);
return formattedTime;
}
}
/*
//////////////////////////////////////////////////////////
Für die Aufgabe nicht benötigte Funktionen
function auswerten() {
var inGeoJs = JSON.parse(texteingabe.value)
//Coordnianten auslesen
leange = inGeoJs.geometry.coordinates;
//Entfernungen erneut mit neuem Stanort berechnen
//array für die neuen Distanzen
orte.features.forEach(element => {
neueOrte.push(element.geometry.coordinates)
});
neueOrte.forEach(item => {
neuedistanzen.push(distanzRechner(leange[0], leange[1], item[0], item[1]));
});
console.log(neuedistanzen)
console.log(neuedistanzen[12])
//Standort anzeigen
var greenIcon = L.icon({
iconUrl: 'ritter.png',
iconSize: [50, 50], // size of the icon
iconAnchor: [22, 94], // point of the icon which will correspond to marker's location
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
});
L.marker({ lon: leange[0], lat: leange[1] }, { icon: greenIcon }).bindPopup('GeoJSON Point').addTo(map);
*/