如何在 Leaflet for R 中渲染使用 gdal2tiles 创建的自定义地图图块? [英] How to render custom map tiles created with gdal2tiles in Leaflet for R?

查看:31
本文介绍了如何在 Leaflet for R 中渲染使用 gdal2tiles 创建的自定义地图图块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

当我单击 leaflet.html 文件 时,图块会在我的浏览器中呈现,如下所示:

显然,瓷砖处于正常工作状态.问题是我不知道如何在 Leaflet for R 中渲染这些图块. 我尝试按照 本教程,但是当我更改代码以适应示例时,什么都没有呈现.我还探索了 this StackOverflow question 的答案,但所有答案似乎已经过时了好几年.

这是我用来尝试以任何方式渲染图块的 R 代码:

库(传单)传单() %>%setView(0, 0, 缩放 = 1) %>%addTiles(urlTemplate = "http://my-username.github.io/tiles/{z}/{x}/{y}.png",options = tileOptions(minZoom = 1, maxZoom = 2, tms = TRUE)) %>%addCircles(lat = 0, lng = 0, radius = 100) #只是看看是否有任何东西在渲染

这段代码渲染了我画的圆圈,但没有别的.

有没有办法直接从我的本地机器渲染这些图块?如果没有,我如何托管这些图块,以便它们可以在 Leaflet for R 中呈现?看起来这应该很简单,但我想不通!

解决方案

想通了.您必须在 Shiny 目录中使用www"文件夹.所以在这个问题中,我只有文件夹Tiles"和其中列出的所有平铺文件夹(0 - 7).相反,将 Tiles 文件夹移动到 www 目录中(在我的示例中,它们被进一步移动到名为map"的文件夹中).

所以代替上面的结构 Tiles >x,必须是www >地图>瓷砖 >x

leaflet() %>%addTiles(urlTemplate = "地图/Tiles/{z}/{x}/{y}.png",选项 = tileOptions(tms = T, minZoom = 5, maxZoom = 9))

I'm working with the ESA's landcover raster layer and ultimately want to display that data for the globe in a Leaflet Shiny app. Rendering such a massive file is impossible, so I've decided to create map tiles to display the data.

Creating the tiles was simple--I used the gdal2tiles tool in QGIS. Here's a quick look of the output, which is in a local directory on my computer:

When I click the leaflet.html file, the tiles are rendered in my browser, like so:

Obviously the tiles are in working order. The problem is that I don't know how to render these tiles in Leaflet for R. I tried following this tutorial, but nothing is rendered when I altered my code to fit the example. I also explored answers from this StackOverflow question, but all of the answers seem several years out of date.

Here's the R code that I'm using to try to get the tiles to render in any way:

library(leaflet)

leaflet() %>% 
  setView(0, 0, zoom = 1) %>% 
  addTiles(urlTemplate = "http://my-username.github.io/tiles/{z}/{x}/{y}.png", 
           options = tileOptions(minZoom = 1, maxZoom = 2, tms = TRUE)) %>% 
  addCircles(lat = 0, lng = 0, radius = 100) #just to see if anything is rendering

This code renders the circle I've drawn, but nothing else.

Is there a way to render these tiles directly from my local machine? If not, how do I host these tiles so that they can be rendered in Leaflet for R? It seems like this should be pretty straightforward, but I can't figure it out!

解决方案

Figured it out. You have to use a "www" folder inside your Shiny directory. So in the question, I just had the folder "Tiles" and all of the tiled folders listed inside of it (0 - 7). Instead, move the Tiles folder inside a www directory (in my example, they are further moved into a folder called "map").

So instead of the above structure Tiles > x, it needs to be www > map > Tiles > x

leaflet() %>%
    addTiles(urlTemplate = "map/Tiles/{z}/{x}/{y}.png",
             option = tileOptions(tms = T, minZoom = 5, maxZoom = 9))

这篇关于如何在 Leaflet for R 中渲染使用 gdal2tiles 创建的自定义地图图块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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