Skip to content

Conversation

@timelyportfolio
Copy link
Contributor

#96

Questions:

  • R leaflet layerManager only supports full removal with the key combination of category and layerId. I used category as null but we could easily use something like draw or even the same as group. For layerId, I just used String(L.stamp(layer)). I would make pull to R leaflet for other removal methods, but I know that acceptance might be slow.
  • How might we assign a more knowable layerId to support removal of single layers? I know that a user could monitor the Leaflet.draw events in Shiny to keep a list, but is there an easier way.
  • How could this be used if we are editing existing features? In this case the above might be much easier, since a user should know what layerId was assigned.

Code to demonstrate:

#devtools::install_github("timelyportfolio/leaflet.extras@draw-layermgr")

library(leaflet)
library(leaflet.extras)

leaflet() %>%
  addDrawToolbar(editOptions=editToolbarOptions())

library(shiny)
ui <- tagList(
  leafletOutput("leaf"),
  actionButton("btnclear", "clear drawn")
)
server <- function(input, output, session) {
  output$leaf <- renderLeaflet({
    leaflet() %>%
      addDrawToolbar(editOptions=editToolbarOptions())
  })
  
  observeEvent(
    input$btnclear,
    {
      leafletProxy("leaf") %>%
       clearGroup("editableFeatureGroup")
    }
  )
}
shinyApp(ui,server)

@bhaskarvk
Copy link
Contributor

I need to review this but looks like a good starting point. I can get to this over the weekend.

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

Successfully merging this pull request may close these issues.

2 participants