Resonators deletion of zoom level move
Change: Move resonators deletion to 'zoomend' event of map. Some clean up of code.
This commit is contained in:
17
code/boot.js
17
code/boot.js
@ -93,7 +93,22 @@ window.setupMap = function() {
|
||||
map.attributionControl.setPrefix('');
|
||||
// listen for changes and store them in cookies
|
||||
map.on('moveend', window.storeMapPosition);
|
||||
map.on('zoomend', window.storeMapPosition);
|
||||
map.on('zoomend', function() {
|
||||
window.storeMapPosition;
|
||||
|
||||
// remove all resonators if zoom out to < RESONATOR_DISPLAY_ZOOM_LEVEL
|
||||
if (isResonatorsShow()) return;
|
||||
for(var i = 1; i < portalsLayers.length; i++) {
|
||||
portalsLayers[i].eachLayer(function(item) {
|
||||
var itemGuid = item.options.guid;
|
||||
// check if 'item' is a resonator
|
||||
if(!window.resonators[itemGuid]) return;
|
||||
portalsLayers[i].removeLayer(item);
|
||||
});
|
||||
}
|
||||
|
||||
console.log('Remove all resonators');
|
||||
});
|
||||
$("[name='leaflet-base-layers']").change(function () {
|
||||
writeCookie('ingress.intelmap.type', $(this).parent().index());
|
||||
});
|
||||
|
@ -144,27 +144,15 @@ window.cleanUp = function() {
|
||||
for(var i = 0; i < portalsLayers.length; i++) {
|
||||
// i is also the portal level
|
||||
portalsLayers[i].eachLayer(function(item) {
|
||||
var itemGuid = item.options.guid;
|
||||
// check if 'item' is a portal
|
||||
if(!window.portals[itemGuid]) return;
|
||||
// portal must be in bounds and have a high enough level. Also don’t
|
||||
// remove if it is selected.
|
||||
var itemGuid = item.options.guid;
|
||||
switch(getTypeByGuid(itemGuid)) {
|
||||
|
||||
case TYPE_PORTAL:
|
||||
if(itemGuid == window.selectedPortal ||
|
||||
(b.contains(item.getLatLng()) && i >= minlvl)) return;
|
||||
|
||||
cnt[0]++;
|
||||
|
||||
portalsLayers[i].removeLayer(item);
|
||||
break;
|
||||
|
||||
case TYPE_RESONATOR:
|
||||
// remove all resonators if zoom level become
|
||||
// lower than RESONATOR_DISPLAY_ZOOM_LEVEL
|
||||
if (map.getZoom() < RESONATOR_DISPLAY_ZOOM_LEVEL)
|
||||
for(var j = 0; j <= 7; j++) portalsLayers[j].removeLayer(item);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
linksLayer.eachLayer(function(link) {
|
||||
@ -253,10 +241,14 @@ window.renderPortal = function(ent) {
|
||||
guid: ent[0]});
|
||||
|
||||
p.on('remove', function() {
|
||||
// remove attached resonators
|
||||
var portalGuid = this.options.guid
|
||||
|
||||
// remove attached resonators, skip if
|
||||
// all resonators have already removed by zooming
|
||||
if (isResonatorsShow()) {
|
||||
for(var i = 0; i <= 7; i++)
|
||||
removeByGuid(portalResonatorGuid(portalGuid,i));
|
||||
}
|
||||
delete window.portals[portalGuid];
|
||||
});
|
||||
p.on('add', function() {
|
||||
@ -283,7 +275,7 @@ window.renderResonators = function(ent) {
|
||||
var portalLevel = getPortalLevel(ent[2]);
|
||||
if(portalLevel < getMinPortalLevel() && ent[0] != selectedPortal) return;
|
||||
|
||||
if(map.getZoom() < RESONATOR_DISPLAY_ZOOM_LEVEL) return;
|
||||
if(!isResonatorsShow()) return;
|
||||
|
||||
for(var i=0; i < ent[2].resonatorArray.resonators.length; i++) {
|
||||
var rdata = ent[2].resonatorArray.resonators[i];
|
||||
@ -331,6 +323,10 @@ window.portalResonatorGuid = function(portalGuid, slot){
|
||||
return portalGuid.slice(0,32) + '.r' + slot;
|
||||
}
|
||||
|
||||
window.isResonatorsShow = function(){
|
||||
return map.getZoom() >= RESONATOR_DISPLAY_ZOOM_LEVEL;
|
||||
}
|
||||
|
||||
window.portalResetColor = function(portal) {
|
||||
portal.setStyle({color: portal.options.fillColor});
|
||||
}
|
||||
|
Reference in New Issue
Block a user