How to set boundaries with leaflet and export to pdf with mapshot?

741 views Asked by At

I have been trying for the whole day now to create a map an export it to a pdf. The problem is that I don't really understand how to either set "width" and "height" or use "fitBounds". Also I would like to crop this "Leaflet" logo at the bottom right. I tried to do a random reproducable example where I would like to only crop the blue rectangle. Any ideas?



remove(list = ls())
library(leaflet)
library(sf)
library(mapview)


### create random sf polygon
pol = st_sfc(st_polygon(list(cbind(c(0,3,3,0,0),c(0,0,3,3,0)))))
h = st_sf(r = 5, pol)


### create "map"
df <- leaflet(width = 1000, height = 1000) %>%  
  #fitBounds(100, 100, 100, 100) %>% 
  addPolygons(data = h,
              color = "blue",
              weight = 1,
              opacity = 1,
              fillOpacity = 1) %>% 
  setMapWidgetStyle(style = list(background = "transparent"))

### show map and export
df
mapshot(df, file = "leaflet.pdf")


enter image description here

0

There are 0 answers