-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
99 lines (92 loc) · 2.3 KB
/
app.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
const data = require('./data.json')
import GestureHandling from '@tilecloud/mbgl-gesture-handling'
const lut = {}
for (let k of Object.keys(data)) {
for (let iso3cd of data[k]) {
lut[iso3cd] = k
}
}
const labels = {
conflict: 'Sexual violence in conflict-affected settings',
'post-conflict': 'Sexual violence in post-conflict settings',
other: 'Other situations of concern'
}
const colors = {
conflict: [
'rgb',
255,
142,
0
],
'post-conflict': [
'rgb',
255,
0,
139
],
other: [
'rgb',
113,
1,
149
]
}
const overlay = document.getElementById('overlay')
const country = document.getElementById('country')
const description = document.getElementById('description')
fetch(
window.confirm('Are you using TabularMaps?')
? 'https://tabularmaps.github.io/8bit-tile/style.json'
: 'https://un-vector-tile-toolkit.github.io/tentatiles/style.json'
).then((response) => response.json()).then(style => {
for (let layer of style.layers) {
if (layer.id === 'bnda') {
layer.paint['fill-color'] = [
'match',
['get', 'iso3cd'],
data.conflict,
colors.conflict,
data['post-conflict'],
colors['post-conflict'],
data.other,
colors.other,
['rgb', 175, 226, 254]
]
}
}
const map = new mapboxgl.Map({
container: 'map',
maxZoom: 2,
style: style,
attributionControl: true,
hash: true,
renderWorldCopies: false
})
map.dragRotate.disable()
map.touchZoomRotate.disableRotation()
new GestureHandling({
backgroundColor: 'rgba(207, 207, 207, 0.8)',
textColor: '#000',
timeout: 2000
}).addTo(map)
map.on('mousemove', (e) => {
const f = map.queryRenderedFeatures(e.point)[0]
if (f) {
overlay.classList.remove('default', 'conflict', 'post-conflict', 'other')
const state = lut[f.properties.iso3cd]
if (state) {
const label = labels[state]
overlay.classList.add(state)
country.textContent = f.properties.maplab
description.textContent = label
console.log(`${f.properties.maplab}: ${label} ${overlay.classList}`)
} else {
overlay.classList.add('default')
country.textContent = ''
description.textContent = ''
}
}
})
map.on('load', () => {
})
})