-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
86 lines (80 loc) · 2.32 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
const data = require('./entries.json')
const colors = {
text: ['rgb', 255, 255, 255],
active: ['rgb', 91, 146, 229],
inactive: ['rgb', 175, 226, 254]
}
const versionString = n => {
const s = n.toString()
return `${s.charAt(0)}.${s.charAt(1)}`
}
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'],
Object.keys(data),
colors.active,
colors.inactive
]
}
if (layer.id === 'text') {
layer.paint['text-color'] = [
'match',
['get', 'iso3cd'],
Object.keys(data),
colors.text,
colors.inactive
]
}
}
const map = new mapboxgl.Map({
container: 'map',
maxZoom: 2,
style: style,
attributionControl: true,
hash: true
})
map.on('mousemove', (e) => {
const f = map.queryRenderedFeatures(e.point)[0]
if (!f) return
overlay.classList.remove('inactive', 'active')
const iso3cd = f.properties.iso3cd
if (data[iso3cd]) {
overlay.classList.add('active')
country.textContent = f.properties.maplab
if (data[iso3cd]) {
description.textContent =
'Click to download Global Map archive data version ' +
data[iso3cd].versions
.map(v => versionString(v))
.join(' and ')
} else {
description.textContent = ''
}
} else {
overlay.classList.add('inactive')
}
})
map.on('click', (e) => {
const f = map.queryRenderedFeatures(e.point)[0]
if (!f) return
const r = data[f.properties.iso3cd]
for (let version of r.versions) {
const url = 'https://github.com/globalmaps/gm'
+ r.iso2cd + version + '/archive/master.zip'
window.confirm('Woudl you like to download Global Map archive data for ' +
`${f.properties.maplab} (version ${versionString(version)})?`)
? window.open(url)
: null
}
})
})