From ae88e8276f88897e8d30037f22276f5ee303578c Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Wed, 28 Aug 2013 17:44:46 +0100 Subject: [PATCH] make max-links limit based on portal count - saves calculating when we wouldn't draw show a 'too many portals' error as a marker when not drawn --- plugins/max-links.user.js | 60 +++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/plugins/max-links.user.js b/plugins/max-links.user.js index 3e80b09e..880584ee 100644 --- a/plugins/max-links.user.js +++ b/plugins/max-links.user.js @@ -21,7 +21,8 @@ window.plugin.maxLinks = function() {}; // const values -window.plugin.maxLinks.MAX_DRAWN_LINKS = 400; +window.plugin.maxLinks.MAX_PORTALS_TO_LINK = 400; + window.plugin.maxLinks.STROKE_STYLE = { color: '#FF0000', opacity: 1, @@ -31,8 +32,8 @@ window.plugin.maxLinks.STROKE_STYLE = { smoothFactor: 10, }; window.plugin.maxLinks.layer = null; +window.plugin.maxLinks.errorMarker = null; -window.plugin.maxLinks._updating = false; window.plugin.maxLinks.Point = function(x,y) { this.x=x; @@ -42,14 +43,42 @@ window.plugin.maxLinks.Point.prototype.toString = function() { return this.x+","+this.y; } + +window.plugin.maxLinks.addErrorMarker = function() { + if (window.plugin.maxLinks.errorMarker == null) { + window.plugin.maxLinks.errorMarker = L.marker (window.map.getCenter(), { + icon: L.divIcon({ + className: 'max-links-error', + iconSize: [300,30], + html: 'Max Links: too many portals!' + }), + clickable: false + }); + + window.map.addLayer(window.plugin.maxLinks.errorMarker); + } + +} + +window.plugin.maxLinks.clearErrorMarker = function() { + if (window.plugin.maxLinks.errorMarker != null) { + window.map.removeLayer(window.plugin.maxLinks.errorMarker); + window.plugin.maxLinks.errorMarker = null; + } +} + + window.plugin.maxLinks.updateLayer = function() { - if (window.plugin.maxLinks._updating || - window.plugin.maxLinks.layer === null || - !window.map.hasLayer(window.plugin.maxLinks.layer)) + if (!window.map.hasLayer(window.plugin.maxLinks.layer)) return; - window.plugin.maxLinks._updating = true; + window.plugin.maxLinks.layer.clearLayers(); + if (Object.keys(window.portals).length > window.plugin.maxLinks.MAX_PORTALS_TO_LINK) { + window.plugin.maxLinks.addErrorMarker(); + return; + } + var locations = []; $.each(window.portals, function(guid, portal) { @@ -61,7 +90,6 @@ window.plugin.maxLinks.updateLayer = function() { var triangles = window.delaunay.triangulate(locations); var drawnLinkCount = 0; - window.plugin.maxLinks._renderLimitReached = false; var orderedPoints = function(a,b) { if(a.x window.plugin.maxLinks.MAX_DRAWN_LINKS ) { - window.plugin.maxLinks._renderLimitReached = true; - return false; //$.each break - } }); - window.plugin.maxLinks._updating = false; - window.renderUpdateStatus(); } window.plugin.maxLinks.setup = function() { @@ -121,12 +141,22 @@ window.plugin.maxLinks.setup = function() { window.plugin.maxLinks.updateLayer(); }); + window.addHook('mapDataRefreshStart', function(e) { + window.plugin.maxLinks.clearErrorMarker(); + }); + window.map.on('layeradd', function(e) { if (e.layer === window.plugin.maxLinks.layer) window.plugin.maxLinks.updateLayer(); }); window.map.on('zoomend moveend', window.plugin.maxLinks.updateLayer); window.addLayerGroup('Maximum Links', window.plugin.maxLinks.layer, false); + + $('head').append(''); + + } var setup = window.plugin.maxLinks.setup;