From c8e30dc35955396a00b7a6c222e5b6efbf0339f5 Mon Sep 17 00:00:00 2001 From: tim-salabim Date: Sun, 14 Feb 2021 17:22:25 +0100 Subject: [PATCH] trial bind layer on events #38 --- inst/htmlwidgets/lib/reactive/reactive.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/inst/htmlwidgets/lib/reactive/reactive.js b/inst/htmlwidgets/lib/reactive/reactive.js index 98434cc..60bfb62 100644 --- a/inst/htmlwidgets/lib/reactive/reactive.js +++ b/inst/htmlwidgets/lib/reactive/reactive.js @@ -83,12 +83,25 @@ LeafletWidget.methods.addReactiveLayer = function(x, var cur_by = e.layer.feature.properties[by]; var ids = getAllIndexes(nkeys, cur_by); - e.target.eachLayer(function (layer) { - if(layer.feature.properties[[by]] == cur_by) { - layer.setStyle(layer.defaultOptions.style(layer.feature)); + ids.forEach(function(i) { + if (map.hasLayer(bind_layer._layers[okeys[i]])) { + map.removeLayer(bind_layer._layers[okeys[i]]); } }); + e.target.eachLayer(function (layer) { + layer.setStyle(layer.defaultOptions.style(layer.feature)); + }); + + } + }); + + bind_layer.on(out, function (e) { + if (e.originalEvent.ctrlKey) { + // console.log(e.layer.feature.properties[by]); + var cur_by = e.layer.feature.properties[by]; + var ids = getAllIndexes(nkeys, cur_by); + ids.forEach(function(i) { if (map.hasLayer(bind_layer._layers[okeys[i]])) { map.removeLayer(bind_layer._layers[okeys[i]]);