leaflet.extras icon indicating copy to clipboard operation
leaflet.extras copied to clipboard

`map_shape_click` not emitted when clicking on drawn shapes (v1, v0.2)

Open cmcaine opened this issue 6 years ago • 2 comments

map_shape_click is not triggered in latest leaflet.extras for drawn shapes.

Tested in v1, v0.2

reprex:

library(leaflet)
library(leaflet.extras)
library(shiny)

ui <- fluidPage(
  leafletOutput('map'),
  verbatimTextOutput('summary')
)

server <- function(input, output, session) {
  output$summary <- renderPrint({
    event <- input$map_shape_click
    print(event)
  })
  
  output$map <- renderLeaflet({
    leaflet() %>%
      addTiles() %>% 
      setView(10, 10, 4) %>% 
      addDrawToolbar(
        targetGroup = 'draw')
  })
}
shinyApp(ui, server)

Old bug with the same issue: https://github.com/rstudio/leaflet/issues/250

@byzheng perhaps you can explain how you solved this?

cmcaine avatar Apr 06 '18 14:04 cmcaine

Maybe methods.mouseHandler just needs to be called for each drawn feature?

https://github.com/rstudio/leaflet/blob/8b20549eeca9b7b66019f098a380422377666bc6/javascript/src/methods.js#L17

cmcaine avatar Apr 06 '18 14:04 cmcaine

Yep: I just need to call this for each shape. Probably adding to the map.on call here

PR incoming.

cmcaine avatar Apr 06 '18 16:04 cmcaine