-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
265 lines (243 loc) · 10.2 KB
/
index.html
File metadata and controls
265 lines (243 loc) · 10.2 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
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map_canvas {
margin: 0;
padding: 0;
height: 100%;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry"></script>
<script src="https://cdn.rawgit.com/googlemaps/v3-utility-library/master/infobox/src/infobox.js"></script>
<script type="text/javascript">
let markers = [] // will be populated later by branches
let branches = [ // need array so branch index can batch markers index
{ id: 'fbje', latlng: [59.9425046, 10.8119712], name: 'Bjerke' },
{ id: 'fbjo', latlng: [59.8341743, 10.835163999999999], name: 'Bjørnholt' },
{ id: 'fbol', latlng: [59.8826369, 10.8441631], name: 'Bøler' },
{ id: 'fgam', latlng: [59.9141056, 10.775629], name: 'Tøyen (Gamle Oslo)' },
{ id: 'fhol', latlng: [59.835085, 10.794494], name: 'Holmlia' },
{ id: 'ffur', latlng: [59.9417006, 10.8974805,15], name: 'Furuset' },
{ id: 'fgry', latlng: [59.9208595, 10.7602126], name: 'Grünerløkka' },
{ id: 'flam', latlng: [59.8742779, 10.8113742], name: 'Lambertseter' },
{ id: 'fmaj', latlng: [59.930717, 10.716361], name: 'Majorstuen' },
{ id: 'fopp', latlng: [59.8940175, 10.841231299999999], name: 'Oppsal' },
{ id: 'fnor', latlng: [59.9512012, 10.873721999999999], name: 'Nordtvet' },
{ id: 'fnyd', latlng: [59.950564299999996, 10.762855499999999], name: 'Nydalen' },
{ id: 'frik', latlng: [59.9474592, 10.7122266,17], name: 'Riksen' },
{ id: 'froa', latlng: [59.946461400000004, 10.643595], name: 'Røa' },
{ id: 'from', latlng: [59.963487900000004, 10.8924909], name: 'Romsås' },
{ id: 'frmm', latlng: [59.967363600000006, 10.9144215], name: 'Rommen' },
{ id: 'fsme', latlng: [59.93254299999999, 10.6827946], name: 'Smestad' },
{ id: 'fsto', latlng: [59.962085699999996, 10.926027999999999], name: 'Stovner' },
{ id: 'ftor', latlng: [59.93798329999999, 10.768275], name: 'Torshov' },
{ id: 'hutl', latlng: [59.91663200000001, 10.746371000000002], name: 'Hovedbiblioteket' }
]
function initialize() {
// map global for testing
map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 12,
center: new google.maps.LatLng(59.91663200000001, 10.746371000000002),
mapTypeId: google.maps.MapTypeId.ROADMAP,
scrollwheel: false
})
// close any open infobox om map on click
// google.maps.event.addListener(map, "click", (e) => { infoWindow.close() })
createMarkers(map, branches)
// dummy event signals
/*
setInterval( () => {
const n = Math.floor((Math.random() * 18) + 0)
console.log(`selecting random row: ${n}`)
handleEvent(branches[n].id, "WHOA")
}, 10000)
*/
}
function createMarkers(map, branches) {
branches.forEach(b => {
let mark = new google.maps.Marker({
position: new google.maps.LatLng(b.latlng[0],b.latlng[1]),
map: map,
title: b.name,
html: `<h3>${b.id}</h3>` // unused
})
let infoWindow = new google.maps.InfoWindow({
content: "loading..."
})
markers.push(mark)
// remove this event
google.maps.event.addListener(mark, "click", (latLng) => {
console.log(mark)
let infoWindow = new google.maps.InfoWindow({
content: `<p>Du klikka på ${b.id}!</p>`
})
infoWindow.open(map, mark)
setTimeout( () => {
infoWindow.close()
}, 3000)
})
})
}
function drawArc(fromPos, toPos) {
let arcPts = []
//const fromPos = getMarkerByBranch(from).getPosition()
//const toPos = getMarkerByBranch(to).getPosition()
const distance = google.maps.geometry.spherical.computeDistanceBetween(fromPos, toPos)
let radius = distance * 1 // keep arc radius == distance for now
const heading = google.maps.geometry.spherical.computeHeading(fromPos, toPos)
const modHeading = heading + 90
let sagitta = computeSagitta(radius, (distance / 2))
let midPoint = google.maps.geometry.spherical.interpolate(fromPos, toPos, 0.5)
let center = google.maps.geometry.spherical.computeOffset(midPoint, (radius - sagitta), modHeading)
const Heading1 = google.maps.geometry.spherical.computeHeading(center, fromPos)
const Heading2 = google.maps.geometry.spherical.computeHeading(center, toPos)
var i = 0;
while ((Heading1 + i) <= Heading2 || (Heading2 + i) <= Heading1) {
if (radius < 0) {
arcPts.push(google.maps.geometry.spherical.computeOffset(center, radius, Heading1 - i));
}
else {
arcPts.push(google.maps.geometry.spherical.computeOffset(center, radius, Heading1 + i));
}
i++;
}
return arcPts
}
function computeSagitta(radius, length){
// radius is radius of circle. length is half between coords
return (radius - (Math.sqrt((radius * radius) - (length * length))))
}
function animateLine(dep, arr, message) {
const depMark = getMarkerByBranch(dep)
const arrMark = getMarkerByBranch(arr)
const fromPos = depMark.getPosition()
const toPos = arrMark.getPosition()
const coords = drawArc(fromPos, toPos)
let arrowSymbol = {
scale: 4,
strokeColor: '#393',
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW
}
let line = new google.maps.Polyline({
strokeOpacity: 0.8,
strokeWeight: 2,
strokeColor: '#f00',
path: coords,
icons: [{
icon: arrowSymbol,
offset: '100%'
}],
map: map
})
let count = 0
window.setInterval(function() {
count = (count + 1) % 200
let icons = line.get('icons')
icons[0].offset = (count / 2) + '%'
line.set('icons', icons)
}, 10)
depMark.setAnimation(google.maps.Animation.BOUNCE)
arrMark.setAnimation(google.maps.Animation.BOUNCE)
setTimeout( () => {
depMark.setAnimation(null)
arrMark.setAnimation(null)
line.setMap(null)
}, 3000)
}
function handleEvent(msgId, branch, tobranch, message) {
const mark = getMarkerByBranch(branch)
mark.setAnimation(google.maps.Animation.BOUNCE);
let infoWindow = new google.maps.InfoWindow({
content: `<p>${msgId}: ${message}</p>`
})
infoWindow.open(map, mark)
setTimeout( () => {
infoWindow.close()
mark.setAnimation(null);
}, 3000)
if (msgId == 'TRANSFER') {
animateLine(branch, tobranch, message)
}
}
function autoToBranch(id) {
const auto = {
autohb: 'hutl',
autobje: 'fbje',
autobjo: 'fbjo',
autoblr: 'fbol',
autofuru: 'ffur',
autogru: 'fgry',
autohol: 'fhol',
autolmb: 'flam',
automaj: 'fmaj',
autonor: 'fnor',
autonyd: 'fnyd',
autoopp: 'fopp',
autoromm: 'frmm',
autoroms: 'from',
autoroa: 'froa',
autosme: 'fsme',
autostv: 'fsto',
autotor: 'ftor',
autotoy: 'fgam'
}
return auto[id]
}
function getMarkerByBranch(id) {
const branch = autoToBranch(id) ? autoToBranch(id) : id
const idx = branches.findIndex(b => b.id === branch)
return markers[idx]
}
google.maps.event.addDomListener(window, 'load', initialize);
// websocket handler
document.addEventListener("DOMContentLoaded", () => {
const ws = new WebSocket("__WEBSOCKET__")
ws.onmessage = (e) => {
console.log(e.data)
const data = JSON.parse(e.data)
switch (data.table) {
case "issues":
switch (data.event) {
case "writerows":
handleEvent('CHECKOUT', data.fields.branchcode, null, `utlånt ex ${data.fields.itemnumber}`)
break
case "deleterows":
handleEvent('RETURN', data.fields.branchcode, null, `levert ex ${data.fields.itemnumber}`)
break
}
default:
break
case "reserves":
switch (data.event) {
case "writerows":
handleEvent('RESERVE', data.fields.branchcode, null, `res ${data.fields.reserve_id} på biblio ${data.fields.biblionumber}`)
break
case "updaterows":
if (data.fields.found === "T") {
handleEvent('RESERVEFOUND', data.fields.after.branchcode, null, `res ${data.fields.after.reserve_id} plukket ex ${data.fields.after.itemnumber} underveis`)
} else if (data.fields.found === "W") {
handleEvent('RESERVEREADY', data.fields.after.branchcode, null, `res ${data.fields.after.reserve_id} til avhenting med hentenummer ${data.fields.after.pickupnumber}`)
}
break
}
case "branchtransfers":
switch (data.event) {
case "writerows":
handleEvent('TRANSFER', data.fields.frombranch, data.fields.tobranch, `start branchtransfer ex ${data.fields.itemnumber} fra ${data.fields.frombranch} til ${data.fields.tobranch}`)
break
case "updaterows":
handleEvent('TRANSFER', data.fields.after.frombranch, data.fields.after.tobranch, `branchtransfer ankommet ex ${data.fields.after.itemnumber} fra ${data.fields.after.frombranch}`)
break
}
}
}
})
</script>
</head>
<body>
<div id="map_canvas"></div>
</body>
</html>