trafficonese / leaflet.extras

Extra functionality for leaflet R package.
https://trafficonese.github.io/leaflet.extras/
GNU General Public License v3.0
213 stars 74 forks source link

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

Closed dr-harper closed 5 months ago

dr-harper commented 5 years ago

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 commented 5 years ago

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