leaflet
leaflet copied to clipboard
input$map_click fires when clicking on Circle shape
When clicking on a shape both a map_shape_click
and a map_click
event are fired. I.e. the click is not consumed by the map_shape_click
.
I would expect the click event to be consumed by the map_shape_click
. If there is no observer for this event then it might be beneficial to fire a map_click
event instead.
My use case was being able to add circles to the map by clicking on it and removing circles by clicking on them. While clicking on the circles to remove them works, the click also triggering on the map also meant a new circle was automatically created in the same spot. I circumvented this by comparing the positions, but that is not a clean solution.
Reprex:
library(shiny)
library(leaflet)
ui <- fluidPage(
leafletOutput("map")
)
server <- function(input, output) {
output$map <- renderLeaflet({
leaflet() %>% addTiles() %>% addCircles(lat=37.233333, lng=-115.808333, label="clickMe")
})
observeEvent(input$map_shape_click, {
print("Shape click")
})
observeEvent(input$map_click, {
print("Map click")
})
}
shinyApp(ui = ui, server = server)
#>
#> Listening on http://127.0.0.1:6301
Created on 2021-11-02 by the reprex package (v2.0.0)