问题
With mapedit
it is possible to clear drawn features using the 'trash' icon built into the drawbar UI. It is also possible to clear features associated with the leaflet map using clearMarkers()
and leafletProxy()
, as laid out in this issue. However, leafletProxy does not clear any features drawn by the user. How do I programmatically clear these features? (e.g. after clicking an actionButton).
Here is a simple shiny app and more explanation:
library(mapedit)
library(mapview)
library(shiny)
ui <- fluidPage(
fluidRow(
editModUI("editor"),
actionButton('clear', "Clear features")
)
)
server <- function(input, output, session) {
edits <- callModule(editMod, "editor", mapview()@map)
observeEvent(input$clear, {
### some other things will happen here like uploading dropbox
# then I need to clear the output of edits()
print(edits())
##cannot do this
# edits()$drawn <- NULL
})
}
shinyApp(ui, server)
UPDATE: A somewhat hacky solution is to call the module again within the clear event. Is there a better solution?:
server <- function(input, output, session) {
edits <- callModule(editMod, "editor", mapview()@map)
observeEvent(input$clear, {
### some other things will happen here like uploading dropbox
edits <- callModule(editMod, "editor", mapview()@map)
})
}
来源:https://stackoverflow.com/questions/52503864/remove-mapedit-features-programmatically