Closed donvicario closed 5 months ago
Indeed this doesnt seem to work and the browser console throws this error:
this.searchControlOSM.removeFrom is not a function
I made a little shinyapp and tried to remove the elements with shinyjs
. That makes it possible to remove the addSearchOSM
control button, but the marker remains on the map.
The addReverseSearchOSM
control can also be removed with simple JavaScript but the Event handler remains active.
library(shiny)
library(shinyjs)
library(leaflet)
library(leaflet.extras)
ui <- fluidPage(
useShinyjs(),
leafletOutput("map")
, actionButton("clearOSM", "clearOSM")
, actionButton("removeSearchOSM", "removeSearchOSM - Not working")
, actionButton("clearReverseSearchOSM", "clearReverseSearchOSM")
, actionButton("removeReverseSearchOSM", "removeReverseSearchOSM")
)
server <- function(input, output, session) {
output$map <- renderLeaflet({
leaflet() %>%
addTiles() %>%
addSearchOSM() %>%
addReverseSearchOSM(group = "revosm")
})
observeEvent(input$clearOSM, {
runjs('$(".leaflet-control-search").remove()')
})
observeEvent(input$removeSearchOSM, {
leafletProxy("map") %>%
removeSearchOSM() ## NOT WORKING
})
observeEvent(input$clearReverseSearchOSM, {
leafletProxy("map") %>%
clearGroup("revosm")
})
observeEvent(input$removeReverseSearchOSM, {
## Event Handler is not removed!!!
runjs('$("#reverseSearchOSM").remove()')
leafletProxy("map") %>%
clearGroup("revosm")
})
}
shinyApp(ui, server)
addSearchOSM(options = searchOptions(hideMarkerOnCollapse = TRUE))
@ideamotor it doesn't work. I tried everything but in vain
I've found the solution. Please check #209
Hi Bhaskar,
I tried to use the addSearchOSM() feature in my leaflet map (html, not shiny) and it does what it's supposed to do. But after I have searched for a place, the search marker remains visible and cannot be removed. The same is with addReverseSearchOSM().
I have noticed the function removeSearchOSM(), but I do not know how to use it. Can you help me?
Thank you!