From d0b3da0183855dd3853e07a6ebdc7bdcd3ca0a3a Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Fri, 4 Jul 2014 19:40:03 +0100 Subject: [PATCH] plugin cross_links: change reliance on Leaflet.Draw internals, instead use the new draw-tools hook for monitoring add/edit/delete/import also fixes cross_links not updating after an import/clear --- plugins/cross_link.user.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/cross_link.user.js b/plugins/cross_link.user.js index 86625235..c7fb1ee9 100644 --- a/plugins/cross_link.user.js +++ b/plugins/cross_link.user.js @@ -284,12 +284,21 @@ var setup = function() { return; } + // this plugin also needs to create the draw-tools hook, in case it is initialised before draw-tools + window.pluginCreateHook('pluginDrawTools'); + window.plugin.crossLinks.createLayer(); // events - map.on('draw:created', function(e) { window.plugin.crossLinks.testAllLinksAgainstLayer(e.layer);}); - map.on('draw:deleted', function(e) {window.plugin.crossLinks.checkAllLinks(); }); - map.on('draw:edited', function(e) {window.plugin.crossLinks.checkAllLinks();}); + window.addHook('pluginDrawTools',function(e) { + if (e.event == 'layerCreated') { + // we can just test the new layer in this case + window.plugin.crossLinks.testAllLinksAgainstLayer(e.layer); + } else { + // all other event types - assume anything could have been modified and re-check all links + window.plugin.crossLinks.checkAllLinks(); + } + }); window.addHook('linkAdded', window.plugin.crossLinks.onLinkAdded); window.addHook('mapDataRefreshEnd', window.plugin.crossLinks.onMapDataRefreshEnd);