When we switch map style, re-add any data layers

This commit is contained in:
Jonny Barnes 2017-05-26 15:07:54 +01:00
parent 82baa9a929
commit f844fc2e5c

View file

@ -20,7 +20,23 @@ const addMapTypeOption = (map, menu, option, checked = false) => {
input.setAttribute('checked', 'checked'); input.setAttribute('checked', 'checked');
} }
input.addEventListener('click', function () { input.addEventListener('click', function () {
let source = map.getSource('points');
map.setStyle('mapbox://styles/mapbox/' + option + '-v9'); map.setStyle('mapbox://styles/mapbox/' + option + '-v9');
map.on('style.load', function () {
map.addLayer({
'id': 'points',
'type': 'symbol',
'source': {
'type': 'geojson',
'data': source._data
},
'layout': {
'icon-image': '{icon}-15',
'text-field': '{title}',
'text-offset': [0, 1]
}
});
});
}); });
let label = document.createElement('label'); let label = document.createElement('label');
label.setAttribute('for', option); label.setAttribute('for', option);