Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local downloaded tiles #194

Open
virux84 opened this issue Oct 12, 2015 · 9 comments
Open

local downloaded tiles #194

virux84 opened this issue Oct 12, 2015 · 9 comments

Comments

@virux84
Copy link

virux84 commented Oct 12, 2015

Hi,
I'm trying to develop a R app that use the leaflet package but with local downloaded tiles.

Using this code:

tilesDir <- 'file:///c:/MapQuest/{z}/{x}/{y}.png'
leaflet() %>% addTiles(urlTemplate =tilesDir)

But it not shows anything.
How Can I use local tiles?
Thank you

@jcheng5
Copy link
Member

jcheng5 commented Oct 12, 2015

Are you creating a Shiny app? Or a stand-alone HTML file?

@virux84
Copy link
Author

virux84 commented Oct 13, 2015

I tried with both of them, with no succes
Il 12/ott/2015 11:23 PM, "Joe Cheng" notifications@github.com ha scritto:

Are you creating a Shiny app? Or a stand-alone HTML file?


Reply to this email directly or view it on GitHub
#194 (comment).

@gherardovarando
Copy link

I successfully use local tiles (they are not download but created by me, the structure is something like: "map/tiles/{z}/{x}/{y}.png" ) inside a Shiny app.
I just use:
m <- leaflet()
m <- addTiles(m,urlTemplate = "map/tiles/{z}/{x}/{y}.png")

and the directory map/ is inside www/
I was not able to use it outside a Shiny app.

@virux84
Copy link
Author

virux84 commented Oct 13, 2015

Please could you explain me step by step how to set up my shiny app?
Also the complete path file?
Thank you very much
Il 13/ott/2015 02:56 PM, "Gherardo Varando" notifications@github.com ha
scritto:

I successfully use local tiles (they are not download but created by me,
the structure is something like: "map/tiles/{z}/{x}/{y}.png" ) inside a
Shiny app.
I just use:

m <- leaflet()
m <- addTiles(m,urlTemplate = "map/tiles/{z}/{x}/{y}.png")

and the directory map/ is inside www/
I was not able to use it outside a Shiny app.


Reply to this email directly or view it on GitHub
#194 (comment).

@gherardovarando
Copy link

I wrote a simple app to show it
https://github.com/gherardovarando/examples
I created a map from a wikipedia image (https://en.wikipedia.org/wiki/History_of_Boston#/media/File:Boston_area_colonial_map.jpg)

The map is a bit distorted because the method I use to produce the map directory is supposed to work with square images, so it fit the initial image to a square.

Example on shinyapps: https://gherardo.shinyapps.io/exampleLocalTiles

@virux84
Copy link
Author

virux84 commented Oct 13, 2015

thank you very much.
It works great
:-)

@cabanana
Copy link

Has someone an idea why it's not working outside a shiny app?

@gherardovarando
Copy link

the problem I think is that, if you are not in a shiny app there is no server able to answer the request of map's tiles. I succeed using local tiles in this way:

  1. go to the directory where you have the tiles and start for example an HTTP server with python's SimpleHttpServer :
    in a terminal: python -m SimpleHTTPServer 8000

  2. in R:
    tilesUrl <- "http://localhost:8000/tiles/{z}/{x}/{y}.png"
    leaflet() %>% addTiles(urlTemplate = tilesUrl, option=list(continuousWorld=TRUE, tileSize="256",minZoom="0",maxZoom="5") )

obviously the tilesUrl depends on the structure of your local tiles.

In the terminal you can actually see the server answering the tiles requests.

@dimin-axa
Copy link

@gherardovarando Thanks for the example app, it was exactly what I wanted to do
However the leaflet appears grey as soon as I subset your tiles by mines (which are extracted from a raster)
But it works when I host them on an external server: any idea why it fails in local?

[edit] Nevermind, it works perfectly. I just forget to set the "tms" option to TRUE within the addTiles:
addTiles(urlTemplate = "tiles_test/{z}/{x}/{y}.png", option = tileOptions(tms = TRUE))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants