diff --git a/code/boot.js b/code/boot.js index 531c5c60..5c735d9a 100644 --- a/code/boot.js +++ b/code/boot.js @@ -81,15 +81,6 @@ window.setupMap = function() { map.addLayer(linksLayer, true); addLayers['Links'] = linksLayer; - resonatorsLayers = []; - for(var i = 1; i <= 8; i++) { - resonatorsLayers[i] = L.layerGroup([]); - map.addLayer(resonatorsLayers[i]); - var t = 'Level ' + i + ' Portal resonators'; - addLayers[t] = resonatorsLayers[i]; - } - - map.addControl(new L.Control.Layers({ 'OSM Cloudmade Midnight': views[0], 'OSM Cloudmade Minimal': views[1], diff --git a/code/map_data.js b/code/map_data.js index f4c580fc..4bf24c50 100644 --- a/code/map_data.js +++ b/code/map_data.js @@ -143,19 +143,31 @@ window.cleanUp = function() { var minlvl = getMinPortalLevel(); for(var i = 0; i < portalsLayers.length; i++) { // i is also the portal level - portalsLayers[i].eachLayer(function(portal) { + portalsLayers[i].eachLayer(function(item) { // portal must be in bounds and have a high enough level. Also don’t // remove if it is selected. - var portalGuid = portal.options.guid; - if(portalGuid == window.selectedPortal || - (b.contains(portal.getLatLng()) && i >= minlvl)) return; + var itemGuid = item.options.guid; + switch(getTypeByGuid(itemGuid)){ - cnt[0]++; + case TYPE_PORTAL: + if(itemGuid == window.selectedPortal || + (b.contains(item.getLatLng()) && i >= minlvl)) return; + + cnt[0]++; - //remove attached resonators - for(var j = 0; j <= 7; j++) removeByGuid( portalResonatorGuid(portalGuid,j) ); + //remove attached resonators + for(var j = 0; j <= 7; j++) removeByGuid( portalResonatorGuid(itemGuid,j) ); - portalsLayers[i].removeLayer(portal); + portalsLayers[i].removeLayer(item); + break; + + case TYPE_RESONATOR: + // remove all resonator if zoom level become + // lower than RESONATOR_DISPLAY_ZOOM_LEVEL + if (map.getZoom() < RESONATOR_DISPLAY_ZOOM_LEVEL) + portalsLayers[i].removeLayer(item); + break; + } }); } linksLayer.eachLayer(function(link) { @@ -168,14 +180,6 @@ window.cleanUp = function() { cnt[2]++; fieldsLayer.removeLayer(field); }); - // remove all resonator if zoom level become - // lower than RESONATOR_DISPLAY_ZOOM_LEVEL - if (map.getZoom() < RESONATOR_DISPLAY_ZOOM_LEVEL){ - for(var i = 1; i < resonatorsLayers.length; i++){ - resonatorsLayers[i].clearLayers(); - } - console.log('removed all resonators'); - } console.log('removed out-of-bounds: '+cnt[0]+' portals, '+cnt[1]+' links, '+cnt[2]+' fields'); } @@ -199,7 +203,7 @@ window.removeByGuid = function(guid) { break; case TYPE_RESONATOR: if(!window.resonators[guid]) return; - resonatorsLayers[window.resonators[guid].options.pLevel].removeLayer(window.resonators[guid]); + portalsLayers[window.resonators[guid].options.pLevel].removeLayer(window.resonators[guid]); break; default: console.warn('unknown GUID type: ' + guid); @@ -319,7 +323,7 @@ window.renderResonator = function(ent) { r.on('remove', function() { delete window.resonators[this.options.guid]; }); r.on('add', function() { window.resonators[this.options.guid] = this; }); - r.addTo(resonatorsLayers[parseInt(portalLevel)]); + r.addTo(portalsLayers[parseInt(portalLevel)]); } } diff --git a/main.js b/main.js index 4b61babe..6e2a1262 100644 --- a/main.js +++ b/main.js @@ -159,7 +159,7 @@ window.selectedPortal = null; window.portalRangeIndicator = null; window.portalAccessIndicator = null; window.mapRunsUserAction = false; -var portalsLayers, linksLayer, fieldsLayer, resonatorsLayers; +var portalsLayers, linksLayer, fieldsLayer; // contain references to all entities shown on the map. These are // automatically kept in sync with the items on *sLayer, so never ever