Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image quality ia poor after saving #499

Open
Agucha1986 opened this issue Jan 21, 2025 · 4 comments
Open

Image quality ia poor after saving #499

Agucha1986 opened this issue Jan 21, 2025 · 4 comments

Comments

@Agucha1986
Copy link

Hi, I am using Leaflet to plot raster data, and everything looks good until I save the maps as PNG or any other format.

I use ESRI as the provider.

This is the code I used to save my maps as images.

saveWidget(m, file = "path.html")
mapshot(m, file = "path.png",
remove_controls = c("zoomControl"), vwidth = 700, vheight = 500)

Is that an issue with the package or is there a way to maintain/increase the resolution/quality of the image while saving the map?

Thank,
A

@tim-salabim
Copy link
Member

Hi, not sure how to help. Do you have a reproducible example?

@Agucha1986
Copy link
Author

Agucha1986 commented Jan 29, 2025 via email

@tim-salabim
Copy link
Member

There's nothing attached. I think you need to upload it here, rather than attaching things to the reply email.

@Agucha1986
Copy link
Author

Apologies,

I thought it would go through.
Unfortunately, I can't upload the HTML file, which is a good-quality image. You will see when you produce one.

Image

Here is the code I used:

LGA boundaries

NSWLGA <- st_read("path/LGA_2024_AUST_GDA2020.shp") %>% st_transform(7844)
Sydney_LGA1 <- NSWLGA %>% filter(LGA_NAME24 %in% c("Sydney"))
Sydney_LGA <- Sydney_LGA1 %>% st_transform(7844)
S_LGA <- as(Sydney_LGA, 'Spatial')
S_LGA2 <- sf::st_transform(Sydney_LGA, "+proj=longlat +datum=WGS84")

#Suburbs
NSWLGAs <- st_read("path/SAL_2021_AUST_GDA2020.shp")
Sydney_sub <- NSWLGAs %>% filter(SAL_NAME21 %in% c("Alexandria", "Annandale (NSW)", "Barangaroo", "Beaconsfield (NSW)", "Camperdown (NSW)",
"Centennial Park (NSW)", "Chippendale", "Darlinghurst", "Darlington (Sydney - NSW)", "Dawes Point",
"Elizabeth Bay", "Erskineville", "Eveleigh", "Forest Lodge", "Glebe (NSW)",
"Haymarket", "Millers Point", "Moore Park", "Newtown (NSW)", "Paddington (NSW)",
"Potts Point", "Pyrmont", "Redfern", "Rosebery (NSW)", "Rushcutters Bay",
"St Peters (NSW)", "Surry Hills", "Sydney", "The Rocks (Sydney - NSW)", "Ultimo",
"Waterloo (NSW)", "Woolloomooloo", "Zetland"))

S_sub2 <- st_intersection(Sydney_sub, Sydney_LGA1)
S_sub3 <- S_sub2
S_sub3 <- as(S_sub3, "Spatial")

#map
m <- leaflet(data = S_sub3,options = leafletOptions(zoomControl = FALSE,attributionControl=FALSE)) %>%
setView(lng = 151.206832, lat = -33.885704, zoom = 13) %>%
addProviderTiles(providers$Esri.WorldImagery) %>%
addPolygons(data = S_sub3,
color = "yellow",
fill = NA,
opacity = 1,
weight = 1.5,label = ~SAL_NAME21) %>%
addPolygons(data = S_LGA,
color = "white",
fill = NA,
opacity = 1,
weight = 2)

m # Print the map
saveWidget(m, file = "path/suburbs.html")
mapshot(m, file = "path/suburbs.png",remove_controls = c("zoomControl"), vwidth = 550, vheight = 550)

Thanks,

Aga

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants