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

Uncaught TypeError: t.drawToolbar.removeFrom is not a function

Open dr-harper opened this issue 5 years ago • 1 comments

Fairly minor error, but there is an error in the Javascript console which appears to be caused by the removeDrawToolbar() function.

Here is a reproducible example:

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

lngs <- c(20, 23, 23)
lats <- c(21, 20, 24)

shinyApp(
  ui <- leafletOutput("map"), 
  
  server <- function(input, output, session){
    
    output$map <- renderLeaflet({
      leaflet() %>% 
        addTiles() %>% 
        addCircleMarkers(lng = lngs, lat = lats, layerId = 1:length(lats)) %>% 
        addDrawToolbar(targetGroup = "test", 
                       rectangleOptions = F, 
                       polylineOptions = F, 
                       markerOptions = F, 
                       editOptions = editToolbarOptions(selectedPathOptions = selectedPathOptions()), 
                       circleOptions = drawCircleOptions(shapeOptions = drawShapeOptions(clickable = T))) %>%
        removeDrawToolbar()
    })  # END RENDER LEAFLET 
    
    observeEvent(input$map_marker_click, {
      print(input$map_marker_click)
    })  
    
    observeEvent(input$map_draw_new_feature, {
      print(input$map_draw_new_feature)
    })
    
  })

If you open the app within Chrome and look at the developer console you can see the error:

image

I think this might be a case of just changing the call to the API function, as suggested in this SO post: https://stackoverflow.com/questions/39224307/leaflet-1-0-0-rc3-removefrom-method-causes-is-not-a-function-error

Hope that helps: doesn't seem to have major performance side effects but I don't know the inner-workings of leaflet that well!

dr-harper avatar Mar 01 '19 18:03 dr-harper

I notice this issue is partly mentioned in #148, so it potentially could be closed as a duplicate

dr-harper avatar Mar 05 '19 00:03 dr-harper