From 9efe828ccb63a397d2682c345053b3d4bca86c22 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Sun, 26 Jan 2014 17:51:37 +0000 Subject: [PATCH] performance: portal names updates less often, as computing visibility gets expensive with lots of portals visible --- plugins/portal-names.user.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/plugins/portal-names.user.js b/plugins/portal-names.user.js index fdc68b7c..d6ba283c 100644 --- a/plugins/portal-names.user.js +++ b/plugins/portal-names.user.js @@ -2,7 +2,7 @@ // @id iitc-plugin-portal-names@zaso // @name IITC plugin: Portal Names // @category Layer -// @version 0.1.3.@@DATETIMEVERSION@@ +// @version 0.1.4.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @updateURL @@UPDATEURL@@ // @downloadURL @@DOWNLOADURL@@ @@ -42,14 +42,6 @@ window.plugin.portalNames.setupCSS = function() { ).appendTo("head"); } -window.plugin.portalNames.portalAdded = function(data) { - data.portal.on('add', function() { - window.plugin.portalNames.addLabel(this.options.guid, this.getLatLng()); - }); - data.portal.on('remove', function() { - window.plugin.portalNames.removeLabel(this.options.guid); - }); -} window.plugin.portalNames.removeLabel = function(guid) { var previousLayer = window.plugin.portalNames.labelLayers[guid]; @@ -81,6 +73,10 @@ window.plugin.portalNames.addLabel = function(guid, latLng) { } window.plugin.portalNames.updatePortalLabels = function() { + // as this is called every time layers are toggled, there's no point in doing it when the leyer is off + if (!map.hasLayer(window.plugin.portalNames.labelLayerGroup)) { + return; + } var portalPoints = {}; @@ -152,6 +148,18 @@ window.plugin.portalNames.updatePortalLabels = function() { } } +// ass calculating portal marker visibility can take some time when there's lots of portals shown, we'll do it on +// a short timer. this way it doesn't get repeated so much +window.plugin.portalNames.delayedUpdatePortalLabels = function() { + + if (window.plugin.portalNames.timer === undefined) { + window.plugin.portalNames.timer = setTimeout ( function() { + window.plugin.portalNames.timer = undefined; + window.plugin.portalNames.updatePortalLabels(); + }, 0.5*1000); + + } +} var setup = function() { @@ -160,9 +168,9 @@ var setup = function() { window.plugin.portalNames.labelLayerGroup = new L.LayerGroup(); window.addLayerGroup('Portal Names', window.plugin.portalNames.labelLayerGroup, true); - window.addHook('requestFinished', window.plugin.portalNames.updatePortalLabels); - window.addHook('mapDataRefreshEnd', window.plugin.portalNames.updatePortalLabels); - window.map.on('overlayadd overlayremove', window.plugin.portalNames.updatePortalLabels); + window.addHook('requestFinished', window.plugin.portalNames.delayedUpdatePortalLabels); + window.addHook('mapDataRefreshEnd', window.plugin.portalNames.delayedUpdatePortalLabels); + window.map.on('overlayadd overlayremove', window.plugin.portalNames.delayedUpdatePortalLabels); } // PLUGIN END //////////////////////////////////////////////////////////