From 19990b940bb50ec39311f6ff5735fbf22c13f60e Mon Sep 17 00:00:00 2001 From: Dave Frame Date: Fri, 22 Feb 2013 14:34:25 -0700 Subject: [PATCH] small fixes: hooking the data response handler instead of the map update so we only calcuate with complete data. scrubbing the portal list for out of view portals to avoid counting out of bounds portals --- plugins/compute-ap-stats.user.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/compute-ap-stats.user.js b/plugins/compute-ap-stats.user.js index edc0857d..0af36254 100644 --- a/plugins/compute-ap-stats.user.js +++ b/plugins/compute-ap-stats.user.js @@ -28,8 +28,12 @@ window.plugin.compAPStats.setupCallback = function() { // do an initial calc for sidebar sizing purposes window.plugin.compAPStats.onPositionMove(); - // make the value update on map position changes - map.on('moveend zoomend', window.plugin.compAPStats.onPositionMove); + // make the value update when the map data updates + var handleDataResponseOrig = window.handleDataResponse; + window.handleDataResponse = function(data, textStatus, jqXHR) { + handleDataResponseOrig(data, textStatus, jqXHR); + window.plugin.compAPStats.onPositionMove(); + } } window.plugin.compAPStats.onPositionMove = function() { @@ -48,10 +52,15 @@ window.plugin.compAPStats.compAPStats = function() { var allEnlEdges = []; var allEnlFields = []; + var displayBounds = map.getBounds(); + // Grab every portal in the viewable area and compute individual AP stats $.each(window.portals, function(ind, portal) { var d = portal.options.details; + // eliminate offscreen portals (selected, and in padding) + if(!displayBounds.contains(portal.getLatLng())) return true; + var portalStats = getAttackApGain(d); var portalSum = portalStats.resoAp + portalStats.captureAp;