mapview icon indicating copy to clipboard operation
mapview copied to clipboard

writing mapview object to .png with mapshot won't render legend

Open grantfalvo opened this issue 3 years ago • 7 comments

Hello,

I'm producing a map with a baselayer and an overlaid rasterlayer. The legend for the rasterlayer shows up fine in Rstudio but won't render when I save the mapview object as a .png with mapshot.

Any ideas on how to fix this?

Thanks.

grantfalvo avatar Jul 18 '22 21:07 grantfalvo

Yes, see https://github.com/r-spatial/mapview/issues/423

tim-salabim avatar Jul 19 '22 06:07 tim-salabim

I see, thanks for the tip.

I tried that and it looks like I have to install Chrome now to use webshot2 instead of webshot (I use Safari). Any work-around that doesn't require using Chrome?

Thanks

grantfalvo avatar Jul 19 '22 17:07 grantfalvo

Not that I know of. This is a very weird issue. Does it work in safari if you use webshot directly?

tim-salabim avatar Jul 19 '22 17:07 tim-salabim

With Safari, I can use mapshot with the CRAN version of mapview, but it doesn't render the legend when saved as a .png. When I use other versions of mapview (i.e. GitHub r-spatial versions) then it looks like I have to install Chrome to save the image.

grantfalvo avatar Jul 19 '22 17:07 grantfalvo

What if you use htmlwidgets::saveWidget() first and then use webshot::webshot() on that html file?

tim-salabim avatar Jul 19 '22 18:07 tim-salabim

Thanks for the quick responses.

I did save the mapview object as a local .html (using mapshot() because saveWidget() gave an '$ operator not defined for this S4 class' error). Then I used webshot:webshot() on that local .html file and got the same .png file without a legend. I'll note that I am able to save the mapview object as a .png with the legend when I export it from the RStudio viewer pane by hand.

grantfalvo avatar Jul 19 '22 19:07 grantfalvo

Sorry my oversight. webshot() should work if you pass it the @map slot of the mapview object

tim-salabim avatar Jul 19 '22 19:07 tim-salabim