// ==UserScript== // @id max-links@boombuler // @name IITC plugin: Max Links // @category Layer // @version 0.4.3.@@DATETIMEVERSION@@ // @updateURL @@UPDATEURL@@ // @downloadURL @@DOWNLOADURL@@ // @description [@@BUILDNAME@@-@@BUILDDATE@@] Calculate how to link the portals to create a reasonably tidy set of links/fields. Enable from the layer chooser. (Max Links is a poor name, but remains for historical reasons.) // @include https://*.ingress.com/intel* // @include http://*.ingress.com/intel* // @match https://*.ingress.com/intel* // @match http://*.ingress.com/intel* // @include https://*.ingress.com/mission/* // @include http://*.ingress.com/mission/* // @match https://*.ingress.com/mission/* // @match http://*.ingress.com/mission/* // @grant none // ==/UserScript== @@PLUGINSTART@@ // PLUGIN START //////////////////////////////////////////////////////// // use own namespace for plugin window.plugin.maxLinks = function() {}; // const values window.plugin.maxLinks.MAX_PORTALS_TO_LINK = 200; // zoom level used for projecting points between latLng and pixel coordinates. may affect precision of triangulation window.plugin.maxLinks.PROJECT_ZOOM = 16; window.plugin.maxLinks.STROKE_STYLE = { color: '#FF0000', opacity: 1, weight: 1.5, clickable: false, dashArray: [6,4], smoothFactor: 10, }; window.plugin.maxLinks.layer = null; window.plugin.maxLinks.errorMarker = null; 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: 'Tidy 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.map.hasLayer(window.plugin.maxLinks.layer)) return; window.plugin.maxLinks.layer.clearLayers(); var locations = []; var bounds = map.getBounds(); $.each(window.portals, function(guid, portal) { var ll = portal.getLatLng(); if (bounds.contains(ll)) { var p = map.project (portal.getLatLng(), window.plugin.maxLinks.PROJECT_ZOOM); locations.push(p); if (locations.length > window.plugin.maxLinks.MAX_PORTALS_TO_LINK) return false; //$.each break } }); if (locations.length > window.plugin.maxLinks.MAX_PORTALS_TO_LINK) { window.plugin.maxLinks.addErrorMarker(); return; } var triangles = window.delaunay.triangulate(locations); var drawnLinkCount = 0; var orderedPoints = function(a,b) { if(a.x'+ '.max-links-error { color: #F88; font-size: 20px; font-weight: bold; text-align: center; text-shadow: -1px -1px #000, 1px -1px #000, -1px 1px #000, 1px 1px #000; background-color: rgba(0,0,0,0.6); border-radius: 5px; }'+ ''); } var setup = window.plugin.maxLinks.setup; // PLUGIN END ////////////////////////////////////////////////////////// @@PLUGINEND@@