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

查看:84
本文介绍了从本地目录(即不是从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?

代码看起来像这样:

library(leaflet)

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天全站免登陆