从本地目录(即不是来自 git 存储库)在 R 传单中渲染自定义图块 [英] Render custom tiles in R leaflet from local directory (i.e. not from a git repository)

查看:20
本文介绍了从本地目录(即不是来自 git 存储库)在 R 传单中渲染自定义图块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Qgis 中的 Qtiles 插件从一个非常大的栅格中创建了一些图块.我已将它们保存到计算机上的本地目录中,现在想使用 R 将它们呈现在传单地图中.

I have created some tiles out of a very large raster using the Qtiles plugin in Qgis. I have saved them to a local directory on my computer, and now want to render them in a leaflet map using R.

addTiles 函数传递一个 URL,但似乎不适用于本地文件路径.在另一篇文章中(如何要在 Leaflet for R 中渲染使用 gdal2tiles 创建的自定义地图图块?),Lauren 建议在闪亮目录中使用 www 文件夹.首先,我不是 100% 确定这是什么意思,其次我不知道该解决方案是否适用于我正在尝试做的事情;我要做的就是在传单地图对象中渲染这些图块并将其保存为本地 html.有可能做我正在尝试的事情吗?

The addTiles function passes a URL, but doesn't seem to work with a local filepath. In a different post (How to render custom map tiles created with gdal2tiles in Leaflet for R?), Lauren recommends using a www folder inside the shiny directory. Firstly, I'm not 100% sure what is meant by that, and secondly I don't know if that solution is applicable to what I'm trying to do; all I want to do is render these tiles in a leaflet map object and save it locally as html. Is it possible to do what I am attempting?

代码如下所示:

库(传单)

map <-leaflet()

map <- addProviderTiles(map, "CartoDB.Positron")

map <- addTiles(map, "C:/mapTiles/level100Tiles/{z}/{x}/{y}.png")

我不知道是否有针对此特定目的的不同传单功能?或者它只是没有完成?

Is there a different leaflet function for this specific purpose that I am not aware of? Or is it just not something that's done?

谢谢:)

推荐答案

在服务器中添加一个 ResourcePath 就可以了,不需要任何地方的 www 文件夹.来源.

Add a ResourcePath inside server and it'll work, no need for the www folder anywhere. Source.

server <- function(input, output, session) {
    addResourcePath("mytiles", "C:/Users/.../mapTiles")
    output$map <- renderLeaflet({
      leaflet() %>% 
        addTiles(urlTemplate = "/mytiles/{z}/{x}/{y}.png")
    })

这篇关于从本地目录(即不是来自 git 存储库)在 R 传单中渲染自定义图块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆