Skip to content

Commit

Permalink
add updateStyle argument to addReactiveFeatures. #38
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-salabim committed Feb 13, 2021
1 parent bd12850 commit 7b7a51c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 5 additions & 2 deletions R/reactive.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ addReactiveFeatures = function(map,
on,
group,
layerId = NULL,
options,
style = NULL) {
options = NULL,
style = NULL,
updateStyle = NULL) {

if (!inherits(x, "geojson")) {
x = geojsonsf::sf_geojson(x)
Expand All @@ -27,7 +28,9 @@ addReactiveFeatures = function(map,
, on
, group
, layerId
, options
, style
, updateStyle
)

}
Expand Down
15 changes: 14 additions & 1 deletion inst/htmlwidgets/lib/reactive/reactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ LeafletWidget.methods.addReactiveLayer = function(x,
group,
layerId,
options,
style) {
style,
updateStyle) {

var map = this;
let out;
Expand Down Expand Up @@ -36,6 +37,12 @@ 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(updateStyle);
}
});

ids.forEach(function(i) {
if (!map.hasLayer(bind_layer._layers[okeys[i]])) {
map.addLayer(bind_layer._layers[okeys[i]]);
Expand All @@ -47,6 +54,12 @@ 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]]);
Expand Down

0 comments on commit 7b7a51c

Please sign in to comment.