簡體   English   中英

如何成功地將傳單地圖保存在 .png 圖像中?

[英]How to successfully save leaflet map in a .png image?

在地理坐標之外,我想在城市地圖上繪制簡單的普通點並將輸出保存為.png 我在Linux Ubuntu 22.04LTS上。 對於第一部分,我找到了一個非常簡潔明了的leaflet解決方案。

library(leaflet); library(htmlwidgets); library(webshot)

m <- leaflet() %>% 
  addTiles("https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png") %>%
  setView(-.12, 51.50, zoom=13)
m$x$options <- append(m$x$options, list("zoomControl" = FALSE))
m <- m %>%
  addCircleMarkers(c(-.11, -.12, -.13), c(51.48, 51.52, 51.50),
                   radius=1, color="red")
m

在此處輸入圖像描述

但是,第二部分,保存.png失敗。 我試過這個解決方案

saveWidget(m, "temp.html", selfcontained=TRUE)
webshot("temp.html", file="Rplot.png", cliprect="viewport")

但是 - 使用phantomjs 2.1.1 - 它給了我這些錯誤:

Auto configuration failed
139740646049728:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:185:filename(libproviders.so): libproviders.so: cannot open shared object file: No such file or directory
139740646049728:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
139740646049728:error:0E07506E:configuration file routines:MODULE_LOAD_DSO:error loading dso:conf_mod.c:285:module=providers, path=providers
139740646049728:error:0E076071:configuration file routines:MODULE_RUN:unknown module name:conf_mod.c:222:module=providers
Error in webshot("temp.html", file = "Rplot.png", cliprect = "viewport") : 
  webshot.js returned failure value: 1
In addition: Warning message:
In is.null(x) || is.na(x) : 'length(x) = 4 > 1' in coercion to 'logical(1)'

使用稍舊的phantomjs 1.9.8版本沒有錯誤,但圖像完全空白。 我使用這些資源在 Ubuntu 上安裝phantomjs1.9.82.1.1 我查看了這個答案,根據它你必須安裝開發版本,但我沒有發現它有用,因為我不知道phantomjs的開發版本。

我不一定需要交互式leaflet ,但我認為黑暗主題看起來很酷,並且對應於夜間犯罪的研究主題。 因此,如果它看起來相似(如果它不使用 Google),我對靜態解決方案持開放態度。

使用新包webshot2 ,它使用 Chrome 或 Chromium 無頭瀏覽器而不是phantomjs

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM