diff --git a/code/boot.js b/code/boot.js index 5c735d9a..531c5c60 100644 --- a/code/boot.js +++ b/code/boot.js @@ -81,6 +81,15 @@ 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 6d12e7a7..f4c580fc 100644 --- a/code/map_data.js +++ b/code/map_data.js @@ -146,9 +146,15 @@ window.cleanUp = function() { portalsLayers[i].eachLayer(function(portal) { // portal must be in bounds and have a high enough level. Also don’t // remove if it is selected. - if(portal.options.guid == window.selectedPortal || + var portalGuid = portal.options.guid; + if(portalGuid == window.selectedPortal || (b.contains(portal.getLatLng()) && i >= minlvl)) return; + cnt[0]++; + + //remove attached resonators + for(var j = 0; j <= 7; j++) removeByGuid( portalResonatorGuid(portalGuid,j) ); + portalsLayers[i].removeLayer(portal); }); } @@ -162,6 +168,14 @@ 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'); } @@ -183,6 +197,10 @@ window.removeByGuid = function(guid) { if(!window.fields[guid]) return; fieldsLayer.removeLayer(window.fields[guid]); break; + case TYPE_RESONATOR: + if(!window.resonators[guid]) return; + resonatorsLayers[window.resonators[guid].options.pLevel].removeLayer(window.resonators[guid]); + break; default: console.warn('unknown GUID type: ' + guid); //window.debug.printStackTrace(); @@ -244,10 +262,73 @@ window.renderPortal = function(ent) { window.renderPortalDetails(ent[0]); window.map.setView(latlng, 17); }); + + window.renderResonator(ent); + // portalLevel contains a float, need to round down p.addTo(portalsLayers[parseInt(portalLevel)]); } +window.renderResonator = function(ent) { + + var portalLevel = getPortalLevel(ent[2]); + if(portalLevel < getMinPortalLevel() && ent[0] != selectedPortal) return; + + if(map.getZoom() < RESONATOR_DISPLAY_ZOOM_LEVEL) return; + + for(var i=0; i