diff --git a/plugins/max-links.user.js b/plugins/max-links.user.js index 5184a20c..eddda059 100644 --- a/plugins/max-links.user.js +++ b/plugins/max-links.user.js @@ -2,7 +2,7 @@ // @id max-links@boombuler // @name IITC plugin: Max Links // @category Layer -// @version 0.3.1.@@DATETIMEVERSION@@ +// @version 0.4.0.@@DATETIMEVERSION@@ // @updateURL @@UPDATEURL@@ // @downloadURL @@DOWNLOADURL@@ // @description [@@BUILDNAME@@-@@BUILDDATE@@] Calculates how to link the portals to create the maximum number of fields. Enable from the layer chooser. @@ -30,15 +30,24 @@ window.plugin.maxLinks.MAX_DRAWN_LINKS_INCREASED_LIMIT = 1000; window.plugin.maxLinks.STROKE_STYLE = { color: '#FF0000', opacity: 1, - weight:2, + weight: 2, clickable: false, - smoothFactor: 10 + dashArray: [8,6], + smoothFactor: 10, }; window.plugin.maxLinks.layer = null; window.plugin.maxLinks._updating = false; window.plugin.maxLinks._renderLimitReached = false; +window.plugin.maxLinks.Point = function(x,y) { + this.x=x; + this.y=y; +} +window.plugin.maxLinks.Point.prototype.toString = function() { + return this.x+","+this.y; +} + window.plugin.maxLinks.updateLayer = function() { if (window.plugin.maxLinks._updating || window.plugin.maxLinks.layer === null || @@ -48,36 +57,62 @@ window.plugin.maxLinks.updateLayer = function() { window.plugin.maxLinks.layer.clearLayers(); var locations = []; - var minX = 0; - var minY = 0; $.each(window.portals, function(guid, portal) { var loc = portal.options.details.locationE6; - var nloc = { x: loc.lngE6, y: loc.latE6 }; - if (nloc.x < minX) - minX = nloc.x; - if (nloc.y < minY) - minY = nloc.y; + var nloc = new window.plugin.maxLinks.Point(loc.latE6/1E6, loc.lngE6/1E6); locations.push(nloc); }); - $.each(locations, function(idx, nloc) { - nloc.x += Math.abs(minX); - nloc.y += Math.abs(minY); - }); - var triangles = window.delaunay.triangulate(locations); - var drawnLinks = 0; + + var drawnLinkCount = 0; window.plugin.maxLinks._renderLimitReached = false; - var renderlimit = window.USE_INCREASED_RENDER_LIMIT ? + var renderLimit = window.USE_INCREASED_RENDER_LIMIT ? window.plugin.maxLinks.MAX_DRAWN_LINKS_INCREASED_LIMIT : window.plugin.maxLinks.MAX_DRAWN_LINKS; + + var orderedPoints = function(a,b) { + if(a.x renderLimit ) { window.plugin.maxLinks._renderLimitReached = true; + return false; //$.each break } }); window.plugin.maxLinks._updating = false; @@ -89,17 +124,6 @@ window.plugin.maxLinks.setup = function() { @@INCLUDERAW:external/delaunay.js@@ try { console.log('done loading delaunay JS'); } catch(e) {} - window.delaunay.Triangle.prototype.draw = function(layer, divX, divY) { - var drawLine = function(src, dest) { - var poly = L.polyline([[(src.y + divY)/1E6, (src.x + divX)/1E6], [(dest.y + divY)/1E6, (dest.x + divX)/1E6]], window.plugin.maxLinks.STROKE_STYLE); - poly.addTo(layer); - }; - - drawLine(this.a, this.b); - drawLine(this.b, this.c); - drawLine(this.c, this.a); - } - window.plugin.maxLinks.layer = L.layerGroup([]); window.addHook('checkRenderLimit', function(e) { @@ -108,9 +132,8 @@ window.plugin.maxLinks.setup = function() { e.reached = true; }); - window.addHook('portalDataLoaded', function(e) { - if (window.map.hasLayer(window.plugin.maxLinks.layer)) - window.plugin.maxLinks.updateLayer(); + window.addHook('requestFinished', function(e) { + window.plugin.maxLinks.updateLayer(); }); window.map.on('layeradd', function(e) {