leaflet图层切换记录
监听 baselayerchange事件。
使用localstorage 存储 当前使用图层。
baseName=window.localStorage.getItem(‘baseName’);
if(!baseName)
{
baseName=’模式1′;
window.localStorage.setItem(‘baseName’,baseName);
}
var baseLayers = {
“模式1”: Map1,
“模式2”: Map2
};
map = L.map(‘map’, {
editable: true,
zoomSnap:0.5,
worldCopyJump: true,
layers: [baseLayers[baseName]]
})
map.on(‘baselayerchange’,function(res){
window.localStorage.setItem(‘baseName’,res.name);
})
转载自:https://blog.csdn.net/aswx1125/article/details/85989963