-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlayers.ts
More file actions
74 lines (65 loc) · 2.91 KB
/
layers.ts
File metadata and controls
74 lines (65 loc) · 2.91 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
import * as Config from './config'
import * as toml from '@iarna/toml'
import * as L from "leaflet"
export function setupLayers(mapVar: L.Map, layerController: L.Control.Layers, southWest: L.LatLngExpression, northEast: L.LatLngExpression, htmllegend: any) {
fetch(Config.layersPath+"layers.toml").then((response => {
if (response.ok) {
return response.blob()
}
}))
.then((result) => {
result.text().then(response => {
try {
var parsed = toml.parse(response)
const layers = new Map(Object.entries(parsed))
//console.log(pois)
for (let entry of Array.from(layers.entries())) {
let key = entry[0]
let value = entry[1]
//console.log(key+" "+value)
const entm = new Map(Object.entries(layers.get(key)))
const ent = Array.from(entm.entries())
//console.log(ent)
const name = <string>ent[0][1]
const zindex = <number>ent[1][1]
const image = <string>ent[2][1]
const isBase = <boolean>ent[3][1]
const legend = <string>ent[4][1]
var layer = L.imageOverlay(
"./assets/layers/" + image,
L.latLngBounds( southWest, northEast),
{
zIndex: zindex,
}
)
if(!isBase) {
layerController.addOverlay(layer, name)
} else {
layerController.addBaseLayer(layer, name)
}
if(legend.length) {
fetch(legend).then((response => {
if (response.ok) {
return response.blob()
}
}))
.then((result) => {
result.text().then(response => {
htmllegend.addLegend({
name: name,
layer: layer,
elements: [{
html: response
}]
})
})
})
}
}
} catch (error) {
console.error("Parsing error on line " + error.line + ", column " + error.column + ": " + error.message)
}
}
)
})
}