fix fragility toggle

mapControl was declared as a const instead of a var, which prevented switchMode() from working properly.

This fixes that by using var rather than const, and also moves the Controls and initial layer declarations above switchMode() so we don't have to rely on hoisting to use variables declared later.

Fixes #16
This commit is contained in:
Hugh Rundle 2021-01-23 18:11:42 +11:00
parent 8dd718a618
commit fafbf5e6b3

View file

@ -319,6 +319,24 @@ Promise.all([boundaries, branchesCsv, ikcCsv, mechanics, nslaBranches])
setGeneral()
}
// add control layers
var mapControl = L.control.layers(
baseMaps,
overlayMaps,
{ "collapsed" : false }
).addTo(map);
// scale
L.control.scale().addTo(map);
// info boxes
const infoBoxes = {
branches: L.control(),
fines: L.control(),
loanPeriod: L.control(),
serviceInfo: L.control({position: 'topleft'})
}
// switching mode between standard and fragile
function switchMode() {
if (sessionStorage.getItem('mapMode') === 'fragile') {
@ -340,24 +358,6 @@ Promise.all([boundaries, branchesCsv, ikcCsv, mechanics, nslaBranches])
modeButton.addEventListener('click', switchMode, false);
// add control layers
const mapControl = L.control.layers(
baseMaps,
overlayMaps,
{ "collapsed" : false }
).addTo(map);
// scale
L.control.scale().addTo(map);
// info boxes
const infoBoxes = {
branches: L.control(),
fines: L.control(),
loanPeriod: L.control(),
serviceInfo: L.control({position: 'topleft'})
}
function getFinesColor(f) {
return f == 'no' ? '#4dac26' :
f == 'yes' ? '#d01c8b' :