MilesMcBain / slippymath

R functions for dealing with slippy map tile servers.
Other
65 stars 4 forks source link

ploting with tmap show three images ? #11

Closed djouallah closed 5 years ago

djouallah commented 5 years ago

I copied the code from your example

library(sf)
library(slippymath)
library(purrr)
library(curl)
library(glue)
library(raster)
library(rgdal)
library(tmap)

uluru_bbox <-     c(xmin = 143.5,
                    xmax = 143.6,
                    ymin = -34.8,
                    ymax = -34.7)

tile_grid <- bbox_to_tile_grid(uluru_bbox, max_tiles = 15)

mapbox_query_string <-
  paste0("https://api.mapbox.com/v4/mapbox.satellite/{zoom}/{x}/{y}.jpg90",
         "?access_token='I past here my long mapbox token'",
         Sys.getenv("MAPBOX_API_KEY"))

images <-
  pmap(tile_grid$tiles,
       function(x, y, zoom){
         outfile <- glue("{x}_{y}.jpg")
         curl_download(url = glue(mapbox_query_string),
                       destfile = outfile) 
         outfile 
       },
       zoom = tile_grid$zoom)

background <- compose_tile_grid(tile_grid, images)

tm_shape(background)+
  tm_raster()

here is the result image

djouallah commented 5 years ago

sorry, I did not read the full documentation