Merge pull request #214 from Xelio/patch-layer-control-status
Add function to store layer control status (overlay only) in cookie for using in next session.
This commit is contained in:
commit
a1b76f78bb
21
code/boot.js
21
code/boot.js
@ -83,6 +83,26 @@ window.setupLayerChooserSelectOne = function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup the function to record the on/off status of overlay layerGroups
|
||||||
|
window.setupLayerChooserStatusRecorder = function() {
|
||||||
|
// Record already added layerGroups
|
||||||
|
$.each(window.layerChooser._layers, function(ind, chooserEntry) {
|
||||||
|
if(!chooserEntry.overlay) return true;
|
||||||
|
var display = window.map.hasLayer(chooserEntry.layer);
|
||||||
|
window.updateDisplayedLayerGroup(chooserEntry.name, display);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Record layerGroups change
|
||||||
|
window.map.on('layeradd layerremove', function(e) {
|
||||||
|
var id = L.stamp(e.layer);
|
||||||
|
var layerGroup = this._layers[id];
|
||||||
|
if (layerGroup && layerGroup.overlay) {
|
||||||
|
var display = (e.type === 'layeradd');
|
||||||
|
window.updateDisplayedLayerGroup(layerGroup.name, display);
|
||||||
|
}
|
||||||
|
}, window.layerChooser);
|
||||||
|
}
|
||||||
|
|
||||||
window.setupStyles = function() {
|
window.setupStyles = function() {
|
||||||
$('head').append('<style>' +
|
$('head').append('<style>' +
|
||||||
[ '#largepreview.enl img { border:2px solid '+COLORS[TEAM_ENL]+'; } ',
|
[ '#largepreview.enl img { border:2px solid '+COLORS[TEAM_ENL]+'; } ',
|
||||||
@ -370,6 +390,7 @@ function boot() {
|
|||||||
window.chat.setup();
|
window.chat.setup();
|
||||||
window.setupQRLoadLib();
|
window.setupQRLoadLib();
|
||||||
window.setupLayerChooserSelectOne();
|
window.setupLayerChooserSelectOne();
|
||||||
|
window.setupLayerChooserStatusRecorder();
|
||||||
window.setupBackButton();
|
window.setupBackButton();
|
||||||
// read here ONCE, so the URL is only evaluated one time after the
|
// read here ONCE, so the URL is only evaluated one time after the
|
||||||
// necessary data has been loaded.
|
// necessary data has been loaded.
|
||||||
|
@ -347,3 +347,25 @@ window.convertTextToTableMagic = function(text) {
|
|||||||
window.calcTriArea = function(p) {
|
window.calcTriArea = function(p) {
|
||||||
return Math.abs((p[0].lat*(p[1].lng-p[2].lng)+p[1].lat*(p[2].lng-p[0].lng)+p[2].lat*(p[0].lng-p[1].lng))/2);
|
return Math.abs((p[0].lat*(p[1].lng-p[2].lng)+p[1].lat*(p[2].lng-p[0].lng)+p[2].lat*(p[0].lng-p[1].lng))/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update layerGroups display status to window.overlayStatus and cookie 'ingress.intelmap.layergroupdisplayed'
|
||||||
|
window.updateDisplayedLayerGroup = function(name, display) {
|
||||||
|
overlayStatus[name] = display;
|
||||||
|
writeCookie('ingress.intelmap.layergroupdisplayed', JSON.stringify(overlayStatus));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read layerGroup status from window.overlayStatus if it was added to map,
|
||||||
|
// read from cookie if it has not added to map yet.
|
||||||
|
// return true if both overlayStatus and cookie didn't have the record
|
||||||
|
window.isLayerGroupDisplayed = function(name) {
|
||||||
|
if(typeof(overlayStatus[name]) !== 'undefined') return overlayStatus[name];
|
||||||
|
|
||||||
|
var layersJSON = readCookie('ingress.intelmap.layergroupdisplayed');
|
||||||
|
if(!layersJSON) return true;
|
||||||
|
|
||||||
|
var layers = JSON.parse(layersJSON);
|
||||||
|
// keep latest overlayStatus
|
||||||
|
overlayStatus = $.extend(layers, overlayStatus);
|
||||||
|
if(typeof(overlayStatus[name]) === 'undefined') return true;
|
||||||
|
return overlayStatus[name];
|
||||||
|
}
|
||||||
|
4
main.js
4
main.js
@ -232,6 +232,10 @@ window.links = {};
|
|||||||
window.fields = {};
|
window.fields = {};
|
||||||
window.resonators = {};
|
window.resonators = {};
|
||||||
|
|
||||||
|
// contain current status(on/off) of overlay layerGroups.
|
||||||
|
// But you should use isLayerGroupDisplayed(name) to check the status
|
||||||
|
window.overlayStatus = {};
|
||||||
|
|
||||||
// plugin framework. Plugins may load earlier than iitc, so don’t
|
// plugin framework. Plugins may load earlier than iitc, so don’t
|
||||||
// overwrite data
|
// overwrite data
|
||||||
if(typeof window.plugin !== 'function') window.plugin = function() {};
|
if(typeof window.plugin !== 'function') window.plugin = function() {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user