From 71bfeff6784bedc8de25bbfd69424d366a559711 Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Mon, 4 Feb 2013 16:15:25 +0100 Subject: [PATCH] remove array with portal details references that might have been leaking. Instead, store the details with the rendered portals so removal is handled automatically --- code/map_data.js | 30 ++++++++++++++++++++---------- code/portal_detail_display.js | 2 +- code/request_handling.js | 2 +- main.js | 1 - 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/code/map_data.js b/code/map_data.js index 94bb7d50..748ee4d4 100644 --- a/code/map_data.js +++ b/code/map_data.js @@ -55,11 +55,13 @@ window.requestData = function() { window.handleDataResponse = function(data, textStatus, jqXHR) { // remove from active ajax queries list if(!data || !data.result) { + window.failedRequestCount++; console.warn(data); return; } var portalUpdateAvailable = false; + var portalInUrlAvailable = false; var m = data.result.map; // defer rendering of portals because there is no z-index in SVG. // this means that what’s rendered last ends up on top. While the @@ -79,15 +81,16 @@ window.handleDataResponse = function(data, textStatus, jqXHR) { if(ent[2].turret !== undefined) { if(selectedPortal == ent[0]) portalUpdateAvailable = true; + if(urlPortal && ent[0] == urlPortal) portalInUrlAvailable = true; + + var latlng = [ent[2].locationE6.latE6/1E6, ent[2].locationE6.lngE6/1E6]; + if(!window.getPaddedBounds().contains(latlng) + && selectedPortal != ent[0] + && urlPortal != ent[0] + ) return; + + - portalsDetail[ent[0]] = ent[2]; - // immediately render portal details if selected by URL. - // is also used internally to select a portal that may not have - // been loaded yet. See utils_misc#zoomToAndShowPortal. - if(urlPortal && ent[0] == urlPortal && !selectedPortal) { - urlPortal = null; // only pre-select it once - window.renderPortalDetails(ent[0]); - } ppp.push(ent); // delay portal render } else if(ent[2].edge !== undefined) renderLink(ent); @@ -99,9 +102,13 @@ window.handleDataResponse = function(data, textStatus, jqXHR) { }); $.each(ppp, function(ind, portal) { renderPortal(portal); }); - if(portals[selectedPortal]) portals[selectedPortal].bringToFront(); + if(portalInUrlAvailable) { + renderPortalDetails(urlPortal); + urlPortal = null; // select it only once + } + if(portalUpdateAvailable) renderPortalDetails(selectedPortal); resolvePlayerNames(); } @@ -172,7 +179,9 @@ window.renderPortal = function(ent) { return; var latlng = [ent[2].locationE6.latE6/1E6, ent[2].locationE6.lngE6/1E6]; - if(!getPaddedBounds().contains(latlng)) return; + // needs to be checked before, so the portal isn’t added to the + // details list and other places + //if(!getPaddedBounds().contains(latlng)) return; // hide low level portals on low zooms var portalLevel = getPortalLevel(ent[2]); @@ -199,6 +208,7 @@ window.renderPortal = function(ent) { fillOpacity: 0.5, clickable: true, level: portalLevel, + details: ent[2], guid: ent[0]}); p.on('remove', function() { delete window.portals[this.options.guid]; }); diff --git a/code/portal_detail_display.js b/code/portal_detail_display.js index 842d3733..fdcd4572 100644 --- a/code/portal_detail_display.js +++ b/code/portal_detail_display.js @@ -4,7 +4,7 @@ // methods that highlight the portal in the map view. window.renderPortalDetails = function(guid) { - var d = portalsDetail[guid]; + var d = window.portals[guid].options.details; if(!d) { unselectOldPortal(); urlPortal = guid; diff --git a/code/request_handling.js b/code/request_handling.js index f5d84aa1..26b228f1 100644 --- a/code/request_handling.js +++ b/code/request_handling.js @@ -40,7 +40,7 @@ window.renderUpdateStatus = function() { if(mapRunsUserAction) t += 'paused during interaction'; else if(isIdle()) - t += 'Idle, not updating.'; + t += 'Idle, not updating.'; else if(window.activeRequests.length > 0) t += window.activeRequests.length + ' requests running.'; else diff --git a/main.js b/main.js index c70d21b0..298e6270 100644 --- a/main.js +++ b/main.js @@ -145,7 +145,6 @@ window.portalRangeIndicator = null; window.portalAccessIndicator = null; window.mapRunsUserAction = false; var portalsLayer, linksLayer, fieldsLayer; -var portalsDetail = {}; // contain references to all entities shown on the map. These are // automatically kept in sync with the items on *sLayer, so never ever