Skip to content
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.

Commit

Permalink
Update handling of Ingress layers with IITC 0.33
Browse files Browse the repository at this point in the history
  • Loading branch information
AlfonsoML committed Jul 31, 2022
1 parent 6705472 commit 9a01cae
Showing 1 changed file with 71 additions and 19 deletions.
90 changes: 71 additions & 19 deletions s2check.user.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// ==UserScript==
// @id s2check@alfonsoml
// @name Pogo Tools
// @id s2check@alfonsoml
// @category Layer
// @namespace https://gitlab.com/AlfonsoML/pogo-s2/
// @downloadURL https://gitlab.com/AlfonsoML/pogo-s2/raw/master/s2check.user.js
// @homepageURL https://gitlab.com/AlfonsoML/pogo-s2/
// @supportURL https://twitter.com/PogoCells
// @version 0.99
// @version 0.100
// @description Pokemon Go tools over IITC. News on https://twitter.com/PogoCells
// @author Alfonso M.
// @match https://intel.ingress.com/*
Expand Down Expand Up @@ -1019,6 +1019,10 @@
chkThisIsPogo.addEventListener('change', e => {
settings.thisIsPogo = chkThisIsPogo.checked;
saveSettings();

// update status
storeIngressLayerDefaultStatus();

setThisIsPogo();
});

Expand Down Expand Up @@ -3489,7 +3493,7 @@
return;
}

const enabled = map._layers[layerId] != null;
const enabled = map._layers[layerId] != null || layerDefaultStatus[name];
if (enabled) {
// Don't remove base layer if it's used
if (isBase)
Expand All @@ -3509,34 +3513,75 @@
// delete from object
delete layers[layerId];
}
window.layerChooser._update();
removedLayers[name] = {
layer: leafletLayer,
enabled: enabled,
isBase: isBase
};
window.updateDisplayedLayerGroup(name, enabled);
window.layerChooser._update();
if (window.updateDisplayedLayerGroup)
window.updateDisplayedLayerGroup(name, enabled);
}
const removedLayers = {};
let portalsLayerGroup;
let layerDefaultStatus;

const IngressLayers = [
'Fields',
'Links',
'DEBUG Data Tiles',
'Artifacts',
//'Ornaments',
'Beacons',
'Frackers',

'Unclaimed/Placeholder Portals',
'Level 1 Portals',
'Level 2 Portals',
'Level 3 Portals',
'Level 4 Portals',
'Level 5 Portals',
'Level 6 Portals',
'Level 7 Portals',
'Level 8 Portals'
];

function storeIngressLayerDefaultStatus() {
layerDefaultStatus = {};

const layers = window.layerChooser._layers;
IngressLayers.forEach(name => {
const layerData = layers.find(l => l.name == name);
if (!layerData)
return;

const id = layerData.layer._leaflet_id;
layerDefaultStatus[name] = window.map._layers[id] != null;
});
localStorage[KEY_SETTINGS + 'layers'] = JSON.stringify(layerDefaultStatus);
}

function removeIngressLayers() {
// By default now IITC stores the visibility status automatically, so we must keep track on our own which Ingress layers are visible
// to restore them upon disabling This is Pogo if it was enabled on start.
if (!layerDefaultStatus) {
const tmp = localStorage[KEY_SETTINGS + 'layers'];
if (tmp) {
try {
layerDefaultStatus = JSON.parse(tmp);
} catch (e) { // eslint-disable-line no-empty
}
}
if (!layerDefaultStatus) {
storeIngressLayerDefaultStatus();
}
}
removeLayer('CartoDB Dark Matter');
removeLayer('CartoDB Positron');
removeLayer('Google Default Ingress Map');

removeLayer('Fields');
removeLayer('Links');
removeLayer('DEBUG Data Tiles');
removeLayer('Artifacts');
//removeLayer('Ornaments');
removeLayer('Beacons');
removeLayer('Frackers');
IngressLayers.forEach(removeLayer);

removeLayer('Unclaimed/Placeholder Portals');
for (let i = 1; i <= 8; i++) {
removeLayer('Level ' + i + ' Portals');
}
//removeLayer('Resistance');
//removeLayer('Enlightened');
mergePortalLayers();
Expand Down Expand Up @@ -3578,7 +3623,8 @@
delete layers[layerId];
}
window.layerChooser._update();
window.updateDisplayedLayerGroup(name, enabled);
if (window.updateDisplayedLayerGroup)
window.updateDisplayedLayerGroup(name, enabled);

if (typeof portalsLayerGroup.off != 'undefined')
portalsLayerGroup.off();
Expand All @@ -3595,8 +3641,14 @@
const info = removedLayers[name];
if (info.isBase)
window.layerChooser.addBaseLayer(info.layer, name);
else
window.addLayerGroup(name, info.layer, info.enabled);
else {
if (window.layerChooser.addOverlay) {
window.layerChooser.addOverlay(info.layer, name, {enabled: info.enabled, 'default': info.enabled});
window.layerChooser.showLayer(info.layer, info.enabled);
} else {
window.addLayerGroup(name, info.layer, info.enabled);
}
}
});
}

Expand Down

0 comments on commit 9a01cae

Please sign in to comment.