performance: portal names updates less often, as computing visibility gets expensive with lots of portals visible

This commit is contained in:
Jon Atkins 2014-01-26 17:51:37 +00:00
parent 170a370099
commit 9efe828ccb

View File

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