I would like to display a time series of my own tile overlays. The objective is to have an animation of this overlay where tile1 is not cleared until tile2 is drawn. The present scripts suffers from 'flashing', where for a few milliseconds, all of my tiles are cleared from the map. How do I eliminate this behavior?
library(shiny)
library(leaflet)
ui <- fluidPage(
fluidRow(
column(4, offset = 4,
sliderInput(
"sliderIn",
"Año",
2001,
2016,
value = 2001,
step = 1,
sep = "",
width = 600,
animate =
animationOptions(interval = 750, loop = T)
))
),
leafletOutput("map", width = "100%", height = "600px")
)
server <- function(input, output, session){
year <- reactive({
which(2001:2016 == input$sliderIn)
})
output$map <- renderLeaflet({
leaflet(options = leafletOptions(minZoom = 0, maxZoom = 16, zoomControl = F)) %>%
addTiles(urlTemplate = "https://mts1.google.com/vt/lyrs=s&hl=en&src=app&x={x}&y={y}&z={z}&s=G", attribution = 'Google') %>%
setView(lng = -84.8,
lat = 15.75,
zoom = 10) %>%
addTiles(urlTemplate = "https://storage.googleapis.com/honduras/forestLoss/year1/{z}/{x}/{y}.png",
layerId = 'ForestLoss',
options = tileOptions(minZoom = 9, maxZoom = 18, tms = TRUE))
})
observe({
leafletProxy(mapId = 'map') %>%
removeTiles('ForestLoss') %>%
addTiles(urlTemplate = paste0('https://storage.googleapis.com/honduras/forestLoss/year',year() ,'/{z}/{x}/{y}.png'),
layerId = 'ForestLoss',
options = tileOptions(minZoom = 9, maxZoom = 18, tms = TRUE))
})
}
shinyApp(ui, server)