-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
64 lines (53 loc) · 1.93 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RouteSim</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin="" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
<style>
body {
margin: 0;
}
#map {
height: 100vh;
}
.gps-marker {
transition: transform 0.5s ease;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map("map").setView([-23.54757, -46.63480], 13);
L.tileLayer('https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>'
}).addTo(map)
var ws = new WebSocket("ws://127.0.0.1:8282/gps");
var gpsMap = new Map();
L.Icon.Default.prototype.options.className = "gps-marker";
ws.onmessage = function (evt) {
var geoJSON = JSON.parse(evt.data);
var latLng = L.GeoJSON.coordsToLatLng(geoJSON.geometry.coordinates);
var marker = gpsMap.get(geoJSON.id);
if (marker == undefined) {
marker = L.marker(latLng);
gpsMap.set(geoJSON.id, marker);
marker.addTo(map);
} else {
marker.setLatLng(latLng);
}
}
ws.onerror = function (evt) {
window.alert("Error connecting to " + evt.target.url);
}
</script>
</body>
</html>