-
Notifications
You must be signed in to change notification settings - Fork 3
/
listeners.js
109 lines (96 loc) · 3.07 KB
/
listeners.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
import store from '../store'
import { configuration } from './configuration'
const lookup = {
counterclockwise: {
north: 'west',
south: 'east',
east: 'north',
west: 'south',
nadir: 'north'
},
clockwise: {
north: 'east',
south: 'west',
east: 'south',
west: 'north',
nadir: 'north'
}
}
async function shiftItemOrientation(direction) {
const newOrientation = direction === 1
? lookup.counterclockwise[store.state.viewports[0].orientation]
: lookup.clockwise[store.state.viewports[0].orientation]
store.dispatch('updateOrientation', newOrientation)
}
function shiftItemTime(viewportIndex, direction) {
document.dispatchEvent(new CustomEvent('imageshift', { detail: direction, bubbles: true }))
}
function keyDownHandler(event) {
const isShiftKeyPressed = event.shiftKey;
const isInputField = event.target.tagName === 'INPUT'
if (isShiftKeyPressed && !isInputField) {
event.preventDefault()
switch (event.key) {
case 'ArrowDown':
shiftItemTime(0, -1)
break
case 'ArrowUp':
shiftItemTime(0, 1)
break
case 'ArrowLeft':
shiftItemOrientation(-1)
break
case 'ArrowRight':
shiftItemOrientation(1)
break
default:
// Handle other keys if needed
break
}
}
}
function isDatafordelerDown() {
fetch(`https://services.datafordeler.dk/DHMTerraen/DHMKoter/1.0.0/GEOREST/HentKoter?geop=POINT(574763.99 6220953.04)&elevationmodel=dtm&username=${ configuration.API_DHM_TOKENA }&password=${ configuration.API_DHM_TOKENB }`)
.catch(function(error) {
const alertDialog = document.createElement('dialog')
alertDialog.id = 'datafordeler-down-dialog'
alertDialog.style = 'margin: auto auto; padding: var(--space) var(--space) var(--space-lg) var(--space-lg);'
alertDialog.innerHTML = `
<header style="margin-bottom: var(--space-sm);git">
<h3 tabindex="0">Skråfoto kan ikke benyttes i øjeblikket</h3>
<button aria-controls="datafordeler-down-dialog" class="ds-icon-icon-close secondary" title="Luk dialogboks">
</button>
</header>
<article>
<p>Skråfoto kan ikke benyttes, da Datafordeler service er utilgængelig. Prøv igen senere.</p>
</article>
`
document.body.append(alertDialog)
alertDialog.querySelector('button').addEventListener('click', (event) => {
alertDialog.close()
})
alertDialog.showModal()
})
setTimeout(function() {
isDatafordelerDown()
}, 60000)
}
function setupListeners() {
// Catch load errors and display to user
window.addEventListener('offline', function (ev) {
alert('Du er ikke længere online. Prøv igen senere.')
})
document.addEventListener('loaderror', function (ev) {
console.error('Network error: ', ev.details);
alert('Der var et problem med at hente data fra serveren.')
})
// Listen and react on shortkey use
document.addEventListener('keydown', keyDownHandler)
if (configuration.ENABLE_DATAFORDELER_PING) {
isDatafordelerDown()
}
}
export {
setupListeners,
shiftItemOrientation
}