remove array with portal details references that might have been leaking. Instead, store the details with the rendered portals so removal is handled automatically

This commit is contained in:
Stefan Breunig
2013-02-04 16:15:25 +01:00
parent f268f0cffc
commit 71bfeff678
4 changed files with 22 additions and 13 deletions

View File

@ -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 whats 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 isnt 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]; });

View File

@ -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;

View File

@ -40,7 +40,7 @@ window.renderUpdateStatus = function() {
if(mapRunsUserAction)
t += 'paused during interaction';
else if(isIdle())
t += 'Idle, not updating.';
t += '<span style="color:red">Idle, not updating.</span>';
else if(window.activeRequests.length > 0)
t += window.activeRequests.length + ' requests running.';
else

View File

@ -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