0

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

sportzpikachu
  • 831
  • 5
  • 18
titeuf
  • 133
  • 1
  • 10
  • Sorry, but I don't quite get what's your goal. What is mapshot, and what language is your code written in? –  Dec 07 '20 at 12:34
  • it's wtitten in R. mapshot just exports the pdf... – titeuf Dec 08 '20 at 10:22
  • 3
    Are you trying to produce a static map with set bounds? Leaflet is designed more for interactive maps you embed in a webpage, where you can zoom and pan. You can also create maps with basic plot functions, such as plot and ggplot, that would let you control your extents more closely. The width and height parameters set the size of the map itself, not the extents. – Brian Fisher Dec 08 '20 at 19:02
  • Well you can remove the Leaflet logo by setting the options `leaflet(options = leafletOptions(attributionControl=FALSE))`. Also, remove the `setMapWidgetStyle()` and your code works for me. – Mxblsdl Dec 10 '20 at 23:37

0 Answers0