forked from MTSR/mapserver
persistent overlays per client
This commit is contained in:
parent
0368c398a9
commit
a2b042c98c
40
static/js/map/CustomOverlay.js
Normal file
40
static/js/map/CustomOverlay.js
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
var customOverlays = {};
|
||||
|
||||
try {
|
||||
customOverlays = JSON.parse(localStorage["mapserver-customOverlays"])
|
||||
} catch (e){}
|
||||
|
||||
function save(){
|
||||
localStorage["mapserver-customOverlays"] = JSON.stringify(customOverlays);
|
||||
}
|
||||
|
||||
export default function(map, overlays){
|
||||
|
||||
Object.keys(customOverlays)
|
||||
.filter(name => overlays[name])
|
||||
.forEach(name => {
|
||||
const layer = overlays[name];
|
||||
|
||||
if (customOverlays[name] && !map.hasLayer(layer)){
|
||||
//Add
|
||||
map.addLayer(layer);
|
||||
}
|
||||
|
||||
if (!customOverlays[name] && map.hasLayer(layer)){
|
||||
//Remove
|
||||
map.removeLayer(layer);
|
||||
}
|
||||
});
|
||||
|
||||
map.on('overlayadd', e => {
|
||||
customOverlays[e.name] = true;
|
||||
save();
|
||||
});
|
||||
|
||||
map.on('overlayremove', e => {
|
||||
customOverlays[e.name] = false;
|
||||
save();
|
||||
});
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ import CoordinatesDisplay from './CoordinatesDisplay.js';
|
||||
import WorldInfoDisplay from './WorldInfoDisplay.js';
|
||||
import SearchControl from './SearchControl.js';
|
||||
import Overlaysetup from './Overlaysetup.js';
|
||||
import CustomOverlay from './CustomOverlay.js';
|
||||
import layerManager from './LayerManager.js';
|
||||
import config from '../config.js';
|
||||
|
||||
@ -33,6 +34,7 @@ export default {
|
||||
|
||||
//All overlays
|
||||
Overlaysetup(cfg, map, overlays, wsChannel, layerManager);
|
||||
CustomOverlay(map, overlays);
|
||||
|
||||
new CoordinatesDisplay({ position: 'bottomleft' }).addTo(map);
|
||||
new WorldInfoDisplay(wsChannel, { position: 'bottomright' }).addTo(map);
|
||||
@ -54,8 +56,6 @@ export default {
|
||||
map.on('zoomend', updateHash);
|
||||
map.on('moveend', updateHash);
|
||||
map.on('baselayerchange', updateHash);
|
||||
|
||||
//TODO: overlay persistence (state, localstorage)
|
||||
},
|
||||
|
||||
onbeforeupdate(newVnode, oldVnode) {
|
||||
|
Loading…
Reference in New Issue
Block a user