3

I am using Leaflet R package for rendering Leaflet map. I want to render my map with Canvas instead of SVG. For this to achieve I need to set preferCanvas flag to true in Leaflet Options. But I am not able to do so in Leaflet for R (map still renders in SVG). Here is the working demo of Canvas map with JavaScript.

Server.R:

    output$map <- renderLeaflet({
      leaflet(
        options = leafletOptions(preferCanvas = TRUE)
      ) %>%
        setMaxBounds(lng1 = -180, lng2 = +180, lat1 = -90, lat2 = +90)
    })

    observe({
      if(!is.null(input$map_bounds)){
        if(input$map_zoom<3){
          boundsBuff<- input$map_bounds
          leafletProxy("map") %>%
            setView(lng=(boundsBuff$north + boundsBuff$south)/2,
                    lat=(boundsBuff$east + boundsBuff$west)/2,
                    zoom = 3
            )
        }
     })

UI.R:

leafletOutput("map", width = "100%", height = "100%")

As per this Leaflet documentation, it seems I am doing it correctly but still it's not working, What I am doing wrong here?

Saurabh Palatkar
  • 3,242
  • 9
  • 48
  • 107

1 Answers1

0

I think it is bug in Leaflet, which has now been resolved (see CHANGELOG version 1.3.2 (2018-07-17) ) "Respect the preferCanvas option in all panes (#6019 by mjumbewu)"

Docs from R's Leaflet package August 27, 2018 refers to Leaflet v. 1.3.1

Francesco
  • 47
  • 1
  • 7