From c34d7ee3a267ada2b66374498a201cb95c93addb Mon Sep 17 00:00:00 2001 From: Xelio Date: Sun, 10 Feb 2013 13:25:39 +0800 Subject: [PATCH 01/27] Resonator on map Change: Add "RESONATOR_DISPLAY_ZOOM_LEVEL" to control minimum zoom level resonator will display Add layerGroup "resonatorsLayers" to draw resonators on it. Add "window.resonators" to store references to resonators on map Resonator will have guid of portal with ".11" or ".12" replaced with ".r0"~".r7" Add function "window.renderResontor" to draw resonators (use sorgo's code [sorgo](https://github.com/sorgo)) "window.renderPortal" will call "window.renderResontor" before add portal to portalsLayers Change "window.removeByGuid" to handle resonators Change "window.cleanUp" to handle resonators cleanup --- code/boot.js | 9 +++++ code/map_data.js | 83 +++++++++++++++++++++++++++++++++++++++++++++- code/utils_misc.js | 12 +++++++ main.js | 8 +++-- 4 files changed, 109 insertions(+), 3 deletions(-) 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 Date: Sun, 10 Feb 2013 16:06:13 +0800 Subject: [PATCH 02/27] Move resonator layer back to layerGroup "portalsLayers", to make it work with portal level filter. And modify cleanup code to work with this change. --- code/boot.js | 9 --------- code/map_data.js | 40 ++++++++++++++++++++++------------------ main.js | 2 +- 3 files changed, 23 insertions(+), 28 deletions(-) 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 From 444bcce988bb8723a447cdaaf9e2b17035090112 Mon Sep 17 00:00:00 2001 From: Xelio Date: Sun, 10 Feb 2013 20:58:15 +0800 Subject: [PATCH 03/27] Code cleanup and minor change Change: Code cleanup Loop over all portalsLayers when delete resonator --- code/map_data.js | 39 +++++++++++++++++---------------------- main.js | 5 +++++ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/code/map_data.js b/code/map_data.js index 4bf24c50..6c47155e 100644 --- a/code/map_data.js +++ b/code/map_data.js @@ -147,25 +147,25 @@ window.cleanUp = function() { // 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)){ + switch(getTypeByGuid(itemGuid)) { case TYPE_PORTAL: if(itemGuid == window.selectedPortal || - (b.contains(item.getLatLng()) && i >= minlvl)) return; + (b.contains(item.getLatLng()) && i >= minlvl)) return; cnt[0]++; //remove attached resonators - for(var j = 0; j <= 7; j++) removeByGuid( portalResonatorGuid(itemGuid,j) ); + for(var j = 0; j <= 7; j++) removeByGuid(portalResonatorGuid(itemGuid,j)); portalsLayers[i].removeLayer(item); break; case TYPE_RESONATOR: - // remove all resonator if zoom level become + // remove all resonators if zoom level become // lower than RESONATOR_DISPLAY_ZOOM_LEVEL if (map.getZoom() < RESONATOR_DISPLAY_ZOOM_LEVEL) - portalsLayers[i].removeLayer(item); + for(var j = 0; j <= 7; j++) portalsLayers[j].removeLayer(item); break; } }); @@ -203,7 +203,9 @@ window.removeByGuid = function(guid) { break; case TYPE_RESONATOR: if(!window.resonators[guid]) return; - portalsLayers[window.resonators[guid].options.pLevel].removeLayer(window.resonators[guid]); + var r = window.resonators[guid] + for(var i = 1; i < portalsLayers.length; i++) + portalsLayers[i].removeLayer(r); break; default: console.warn('unknown GUID type: ' + guid); @@ -267,41 +269,35 @@ window.renderPortal = function(ent) { window.map.setView(latlng, 17); }); - window.renderResonator(ent); + window.renderResonators(ent); // portalLevel contains a float, need to round down p.addTo(portalsLayers[parseInt(portalLevel)]); } -window.renderResonator = function(ent) { +window.renderResonators = 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 Date: Sun, 10 Feb 2013 14:08:35 +0100 Subject: [PATCH 04/27] fix 'report issue' for places with single or double quotes in their names. Fixes #68 --- code/portal_detail_display.js | 2 +- code/portal_detail_display_tools.js | 8 -------- code/utils_misc.js | 7 +++++++ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/code/portal_detail_display.js b/code/portal_detail_display.js index 0a7fd8a5..30a24f83 100644 --- a/code/portal_detail_display.js +++ b/code/portal_detail_display.js @@ -70,7 +70,7 @@ window.renderPortalDetails = function(guid) { + '
'+getResonatorDetails(d)+'
' + '
' + '' - + '' + + '' + '
' ); } diff --git a/code/portal_detail_display_tools.js b/code/portal_detail_display_tools.js index 71e38332..21fe3b91 100644 --- a/code/portal_detail_display_tools.js +++ b/code/portal_detail_display_tools.js @@ -78,14 +78,6 @@ window.getAvgResoDistText = function(d) { return '⌀ res dist: ' + avgDist + ' m'; } -window.getReportIssueInfoText = function(d) { - return ('Your Nick: '+PLAYER.nickname+' ' - + 'Portal: '+d.portalV2.descriptiveText.TITLE+' ' - + 'Location: '+d.portalV2.descriptiveText.ADDRESS - +' (lat '+(d.locationE6.latE6/1E6)+'; lng '+(d.locationE6.lngE6/1E6)+')' - ).replace(/['"]/, ''); -} - window.getResonatorDetails = function(d) { console.log('rendering reso details'); var resoDetails = ''; diff --git a/code/utils_misc.js b/code/utils_misc.js index 02a202b8..4959c40a 100644 --- a/code/utils_misc.js +++ b/code/utils_misc.js @@ -93,6 +93,13 @@ window.rangeLinkClick = function() { window.reportPortalIssue = function(info) { var t = 'Redirecting you to a Google Help Page. Once there, click on “Contact Us” in the upper right corner.\n\nThe text box contains all necessary information. Press CTRL+C to copy it.'; + var d = window.portals[window.selectedPortal].options.details; + + var info = 'Your Nick: ' + PLAYER.nickname + ' ' + + 'Portal: ' + d.portalV2.descriptiveText.TITLE + ' ' + + 'Location: ' + d.portalV2.descriptiveText.ADDRESS + +' (lat ' + (d.locationE6.latE6/1E6) + '; lng ' + (d.locationE6.lngE6/1E6) + ')'; + //codename, approx addr, portalname if(prompt(t, info) !== null) location.href = 'https://support.google.com/ingress?hl=en'; From f781c6ebd4fbe4c47684cac2b84a06aa87873825 Mon Sep 17 00:00:00 2001 From: Xelio Date: Sun, 10 Feb 2013 21:14:54 +0800 Subject: [PATCH 05/27] Resonators deletion of portal move Move Resonators deletion to 'remove' event of portal --- code/map_data.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/code/map_data.js b/code/map_data.js index 6c47155e..fd353a0a 100644 --- a/code/map_data.js +++ b/code/map_data.js @@ -155,9 +155,6 @@ window.cleanUp = function() { cnt[0]++; - //remove attached resonators - for(var j = 0; j <= 7; j++) removeByGuid(portalResonatorGuid(itemGuid,j)); - portalsLayers[i].removeLayer(item); break; @@ -255,7 +252,13 @@ window.renderPortal = function(ent) { details: ent[2], guid: ent[0]}); - p.on('remove', function() { delete window.portals[this.options.guid]; }); + p.on('remove', function() { + // remove attached resonators + var portalGuid = this.options.guid + for(var i = 0; i <= 7; i++) + removeByGuid(portalResonatorGuid(portalGuid,i)); + delete window.portals[portalGuid]; + }); p.on('add', function() { window.portals[this.options.guid] = this; // handles the case where a selected portal gets removed from the @@ -289,11 +292,11 @@ window.renderResonators = function(ent) { if (window.resonators[portalResonatorGuid(ent[0],i)]) continue; - // offsets in meters + // offset in meters var dn = rdata.distanceToPortal*SLOT_TO_LAT[rdata.slot]; var de = rdata.distanceToPortal*SLOT_TO_LNG[rdata.slot]; - // Coordinate offsets in radians + // Coordinate offset in radians var dLat = dn/EARTH_RADIUS; var dLon = de/(EARTH_RADIUS*Math.cos(Math.PI/180*(ent[2].locationE6.latE6/1E6))); From f102ef593d3e1a70093ed4faaf648b758ef1b589 Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Sun, 10 Feb 2013 14:58:37 +0100 Subject: [PATCH 06/27] rename expand here as well --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index 1d188f08..e4eaa2c8 100644 --- a/main.js +++ b/main.js @@ -50,7 +50,7 @@ document.getElementsByTagName('head')[0].innerHTML = '' document.getElementsByTagName('body')[0].innerHTML = '' + '
Loading, please wait
' + '' + ''; diff --git a/style.css b/style.css index 19a0afc6..00185a17 100644 --- a/style.css +++ b/style.css @@ -519,6 +519,10 @@ aside:nth-child(odd) span { font-size:90%; } +#toolbox > a { + padding: 5px; +} + #spacer { /* cheap hack to prevent sidebar content being overlayed by the map * status box */