-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
184 lines (133 loc) · 6.83 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Quick Start - Leaflet</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="./images/favicon.ico" />
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
<script type="text/javascript" src="./script/leaflet.geometryutil.js"></script>
<script type="text/javascript" src="./script/leaflet-arrowheads.js"></script>
<script type="text/javascript" src="./script/leaflet.motion.js"></script>
<script type="text/javascript" src="./script/MovingMarker.js"></script>
<script type="text/javascript" src="./script/leaflet.motion.min.js"></script>
<script type="text/javascript" src="./script/autocomplete.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/>
<link rel="stylesheet" type="text/css" href="./css/layout.css"/>
</head>
<div>
<div class="menu">
<form autocomplete="off" action="">
<div class="autocomplete" style="width:250px;">
<input id="car_plate" type="text" name="car_plate" placeholder="車號" value="003-FS">
</div>
<input type="date" id="query_date" name="query_date" style="width:250px;">
<input type="submit">
</form>
<div id="description"><h5></h5></div>
</div>
<div class="content">
<div id="mapid" style="width: auto; height: 98vh;"></div>
</div>
</body>
<script>
// 取得日期
let params = new URLSearchParams(location.search);
let car_plate = params.get('car_plate') ? params.get('car_plate'): "005-FZ";
let query_date = params.get('query_date') ? params.get('query_date'): new Date().Format("yyyy-MM-dd");
document.getElementById('car_plate').value = car_plate;
document.getElementById('query_date').value = query_date;
// 取得車號
// 有JWT
// async function fetchAsync () {
// let data = await (await fetch("https://iottrek.owlting.com/api/login/", {
// method: 'POST',
// body: JSON.stringify({"USERNAME": "iot_dev", "PASSWORD": "123456"}),
// headers: new Headers({'Content-Type': 'application/json'})
// })).json();
// return data;
// };
// async function fetchJWTAlldevices (jwtoken) {
// return (await (await fetch("https://iottrek-staging.owlting.com/api/jwt/get/alldevices/", {
// method: 'POST',
// body: JSON.stringify({"filters": {}, "out_field": ["deviceid"]}),
// headers: new Headers({'Content-Type': 'application/json', 'Authorization': 'Bearer ' + jwtoken})
// })).json()).map(point_set => point_set[0]);
// };
// fetchAsync()
// .then(data => fetchJWTAlldevices(data.token))
// .then(data => autocomplete(document.getElementById("car_plate"), data))
// .catch(reason => console.log(reason.message))
// 無JWT
async function fetchAlldevices (jwtoken) {
return (await (await fetch("https://iottrek-staging.owlting.com/api/get/alldevices/", {
method: 'POST',
body: JSON.stringify({"filters": {}, "out_field": ["deviceid"]}),
headers: new Headers({'Content-Type': 'application/json', 'Authorization': 'Bearer ' + jwtoken})
})).json()).map(point_set => point_set[0]);
};
fetchAlldevices()
.then(data => autocomplete(document.getElementById("car_plate"), data))
.catch(reason => console.log(reason.message))
function createMap(PathPoints) {
var malibuPathPoints = PathPoints.map(point_set => [point_set[0], point_set[1]])
var speedPathPoints = PathPoints.map(point_set => [point_set[2] * 3])
var map = L.map('mapid').setView(malibuPathPoints[0], 10);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
}).addTo(map);
// 使用movie marker
var myline = L.polyline(malibuPathPoints).arrowheads({frequency: 'endonly', size: '12px', yawn: 40, fill: true});
myline.addTo(map);
var marker1 = L.Marker.movingMarker(malibuPathPoints, speedPathPoints).addTo(map);
L.polyline(malibuPathPoints).addTo(map);
marker1.once('click', function () {
marker1.start();
marker1.closePopup();
marker1.unbindPopup();
marker1.on('click', function() {
if (marker1.isRunning()) {
marker1.pause();
} else {
marker1.start();
}
});
setTimeout(function() {
marker1.bindPopup('<b>Click me to pause !</b>').openPopup();
}, 2000);
});
marker1.bindPopup('<b>Click me to start !</b>', {closeOnClick: false});
marker1.openPopup();
// 使用Antimate moving
// L.motion.polyline([malibuPathPoints], {
// //color: "red",
// }, {
// auto: true,
// duration: 5000,
// easing: L.Motion.Ease.easeInOutQuart
// }, {
// removeOnEnd: false,
// showMarker: true,
// }).addTo(map);
document.getElementById('description').innerHTML = "<h5>Painting done.</h5>";
}
async function fetchPTXLocation () {
return (await (await fetch("https://iottrek-staging.owlting.com/api/ptx/query/", {
method: 'POST',
body: JSON.stringify({"car_plate": car_plate, "query_date": query_date}),
headers: new Headers({'Content-Type': 'application/json'})
})).json());
};
function checkDataAvailability(data) {
if (data.output_data) {
createMap(data.output_data);
} else {
document.getElementById('description').innerHTML = "<h5>No data available.</h5>";
}
};
fetchPTXLocation()
.then(data => checkDataAvailability(data))
.catch(reason => console.log(reason.message));
</script>
</html>