Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding functionality to addReactiveFeatures #38

Open
sinclairmichael opened this issue Feb 10, 2021 · 12 comments
Open

Consider adding functionality to addReactiveFeatures #38

sinclairmichael opened this issue Feb 10, 2021 · 12 comments

Comments

@sinclairmichael
Copy link

sinclairmichael commented Feb 10, 2021

Consider an a update_style argument which allows labelling of points and also highlights those points which are selected in the base layer. When we have multiple points selected, displaying many point on the reactive layer, it is not clear which ones they are to deselect them.

@tim-salabim
Copy link
Member

tim-salabim commented Feb 13, 2021

Heads-up @sinclairmichael , argument updateStyle added to specify how the bindTo layer should be styled when clicked. E.g.

library(leaflet)
library(leafem)
library(sf)
library(geojsonsf)

fran = mapview::franconia
brew = st_join(mapview::breweries, fran)

leaflet() %>%
  addTiles() %>%
  addGeoJSON(sf_geojson(fran), group = "fran") %>%
  leafem:::addReactiveFeatures(
    brew
    , bindTo = "fran"
    , by = "NUTS_ID"
    , on = "click"
    , group = "brew"
    , style = list(color = "black", fillOpacity = 0.9)
    , updateStyle = list(
      fillColor = "magenta"
      , fillOpacity = 0.6
    )
  ) %>%
  addMouseCoordinates() %>%
  setView(lng = 10.75, lat = 49.75, zoom = 8)

@tim-salabim
Copy link
Member

Btw, I am also thinking that we probably should add a key-click combination to invoke this functionality to avoid ambiguity with standard click action (popup) of the bindTo layer.... What do you think?

@sinclairmichael
Copy link
Author

sinclairmichael commented Feb 13, 2021 via email

@tim-salabim
Copy link
Member

popups should now also work, e.g.

library(leaflet)
library(leafem)
library(sf)
library(geojsonsf)

fran = mapview::franconia
brew = st_join(mapview::breweries, fran)

options(viewer = NULL)

leaflet() %>%
  addTiles() %>%
  addGeoJSON(sf_geojson(fran), group = "fran") %>%
  leafem:::addReactiveFeatures(
    brew
    , bindTo = "fran"
    , by = "NUTS_ID"
    , on = "click"
    , group = "brew"
    , style = list(color = "black", fillOpacity = 0.9)
    , updateStyle = list(
      fillColor = "magenta"
      , fillOpacity = 0.6
    )
    , popup = leafpop::popupTable(brew)
  ) %>%
  addMouseCoordinates() %>%
  setView(lng = 10.75, lat = 49.75, zoom = 8)

What I meant earlier is that I think we should not simply bind the functionality to a mouse click, but require that the user also holds a specific key while clicking, e.g. Ctrl + click to show/hide the reactive layer.

@sinclairmichael
Copy link
Author

sinclairmichael commented Feb 14, 2021 via email

tim-salabim added a commit that referenced this issue Feb 14, 2021
@tim-salabim
Copy link
Member

Update, reactivity is now bound to pressing (and holding) Ctrl key, e.g.

library(leaflet)
library(leafem)
library(sf)
library(geojsonsf)

fran = mapview::franconia
brew = st_join(mapview::breweries, fran)

options(viewer = NULL)

leaflet() %>%
  addTiles() %>%
  addGeoJSON(sf_geojson(fran), group = "fran") %>%
  leafem:::addReactiveFeatures(
    brew
    , bindTo = "fran"
    , by = "NUTS_ID"
    , on = "mouseover"
    , group = "brew"
    , style = list(color = "black", fillOpacity = 0.9)
    , updateStyle = list(
      fillColor = "magenta"
      , fillOpacity = 0.6
    )
    , popup = leafpop::popupTable(brew)
  ) %>%
  addMouseCoordinates() %>%
  setView(lng = 10.75, lat = 49.75, zoom = 8)

Peek 2021-02-14 10-20

@tim-salabim
Copy link
Member

Update: style for the original layer is now properly reset when overlay layer is removed. This means we now have a nice experience for polygon - polygon overlays, e.g.

library(leaflet)
library(leafem)
library(sf)
library(geojsonsf)
library(mapview)
library(data.table)

frandt = data.table(franconia)

regions = st_as_sf(
  frandt[, .(geometry = st_union(geometry)), by = "district"]
)

leaflet() %>%
  addTiles() %>%
  addGeoJSON(sf_geojson(regions), group = "regions") %>%
  leafem:::addReactiveFeatures(
    franconia
    , bindTo = "regions"
    , by = "district"
    , on = "click"
    , group = "franconia"
    , style = list(color = "black", fillOpacity = 0.3)
    , updateStyle = list(
      opacity = 0
      , fillOpacity = 0
    )
    , popup = leafpop::popupTable(franconia)
  ) %>%
  addMouseCoordinates() %>%
  setView(lng = 10.75, lat = 49.75, zoom = 8)

Peek 2021-02-21 12-56

@sinclairmichael
Copy link
Author

sinclairmichael commented Feb 23, 2021 via email

@sinclairmichael
Copy link
Author

sinclairmichael commented Feb 25, 2021 via email

@tim-salabim
Copy link
Member

Did you re-install from github?

@sinclairmichael
Copy link
Author

sinclairmichael commented Feb 25, 2021 via email

@tim-salabim
Copy link
Member

rstudio/htmltools#97 maybe from this? Is your htmltools up to date?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants