When we switch map style, re-add any data layers
This commit is contained in:
parent
82baa9a929
commit
f844fc2e5c
1 changed files with 16 additions and 0 deletions
16
resources/assets/es6/mapbox-utils.js
vendored
16
resources/assets/es6/mapbox-utils.js
vendored
|
@ -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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue