From 71fc7c79fed3103c05a5ccf314a3748c592d9973 Mon Sep 17 00:00:00 2001 From: Lee McFadden Date: Sat, 15 Nov 2014 15:40:32 -0800 Subject: [PATCH] Updated to allow only drawn links of a certain color to be marked as 'crossing'. --- plugins/cross_link.user.js | 44 ++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/plugins/cross_link.user.js b/plugins/cross_link.user.js index 71b6e282c..5e08c1e32 100644 --- a/plugins/cross_link.user.js +++ b/plugins/cross_link.user.js @@ -21,6 +21,7 @@ window.plugin.crossLinks = function() {}; +window.plugin.crossLinks.currentMatchColor = '#a24ac3'; window.plugin.crossLinks.greatCircleArcIntersect = function(a0,a1,b0,b1) { // based on the formula at http://williams.best.vwh.net/avform.htm#Int @@ -189,12 +190,12 @@ window.plugin.crossLinks.testLink = function (link) { for (var i in plugin.drawTools.drawnItems._layers) { // leaflet don't support breaking out of the loop var layer = plugin.drawTools.drawnItems._layers[i]; - if (layer instanceof L.GeodesicPolygon) { + if (layer instanceof L.GeodesicPolygon && layer.options.color == window.plugin.crossLinks.currentMatchColor) { if (plugin.crossLinks.testPolyLine(layer, link,true)) { plugin.crossLinks.showLink(link); break; } - } else if (layer instanceof L.GeodesicPolyline) { + } else if (layer instanceof L.GeodesicPolyline && layer.options.color == window.plugin.crossLinks.currentMatchColor) { if (plugin.crossLinks.testPolyLine(layer, link)) { plugin.crossLinks.showLink(link); break; @@ -234,11 +235,11 @@ window.plugin.crossLinks.testAllLinksAgainstLayer = function (layer) { $.each(window.links, function(guid, link) { if (!plugin.crossLinks.linkLayerGuids[link.options.guid]) { - if (layer instanceof L.GeodesicPolygon) { + if (layer instanceof L.GeodesicPolygon && layer.options.color == window.plugin.crossLinks.currentMatchColor) { if (plugin.crossLinks.testPolyLine(layer, link,true)) { plugin.crossLinks.showLink(link); } - } else if (layer instanceof L.GeodesicPolyline) { + } else if (layer instanceof L.GeodesicPolyline && layer.options.color == window.plugin.crossLinks.currentMatchColor) { if (plugin.crossLinks.testPolyLine(layer, link)) { plugin.crossLinks.showLink(link); } @@ -283,6 +284,38 @@ window.plugin.crossLinks.createLayer = function() { } } +// Options +window.plugin.crossLinks.manualOpt = function() { + var html = '
' + + '' + + '
' + + ''; + dialog({ + html: html, + dialogClass: 'ui-dialog-crosslinksSet', + title: 'Cross Links Options' + }); + + $('#crosslinks_matchcolor').spectrum({ + flat: false, + showInput: false, + showButtons: false, + showPalette: true, + showSelectionPalette: false, + palette: [ ['#a24ac3','#514ac3','#4aa8c3','#51c34a'], + ['#c1c34a','#c38a4a','#c34a4a','#c34a6f'], + ['#000000','#666666','#bbbbbb','#ffffff'] + ], + change: function(color) { window.plugin.crossLinks.setMatchColor(color.toHexString()); }, + color: window.plugin.crossLinks.currentMatchColor, + }); +} + +window.plugin.crossLinks.setMatchColor = function(color) { + window.plugin.crossLinks.currentMatchColor = color; + window.plugin.crossLinks.checkAllLinks(); +} + var setup = function() { if (window.plugin.drawTools === undefined) { alert("'Cross-Links' requires 'draw-tools'"); @@ -292,6 +325,9 @@ var setup = function() { // this plugin also needs to create the draw-tools hook, in case it is initialised before draw-tools window.pluginCreateHook('pluginDrawTools'); + // Add options menu + $('#toolbox').append('Cross Links Opt'); + window.plugin.crossLinks.createLayer(); // events