Closed psolymos closed 2 years ago
The GeoTIFF approach is promising. Battling transparency and CORS, but here it is (using a test API here because GitHub pages has CORS headers):
library(shiny)
library(leaflet)
library(leafem)
## note Leaflet is having problem with CORS requests
shinyApp(
ui=fluidPage(
leafletOutput("map")
),
server=function(input, output) {
output$map <- renderLeaflet({
leaflet() %>%
addProviderTiles("Esri.WorldImagery") %>%
addGeotiff(
url = "https://peter.solymos.org/testapi/amro1k.tif",
project = FALSE,
opacity = 0.8,
colorOptions = colorOptions(
palette = hcl.colors(50, palette = "inferno"),
domain = c(0, 0.62),
na.color = "transparent"))
})
}
)
Note the mapping of the palette to the domain. This would really help in applying custom color scales and comparing among periods/scenarios.
Here is what I get: transparency is an issue with finding noDataValue in the JS code
Solution: write TIF using {stars}:
library(stars)
s <- st_as_stars(r)
write_stars(s, "filename.tif")
Update: color palettes were ranked based on 9 poll responses
"spectral" "rdylbu" "viridis" "bam"
Decision: use spectral (grDevices::hcl.colors(n, "spectral", rev = TRUE)
).
Explore if allowing multiple palettes in a TMS framework is feasible or not. (Alternative is to use COGs and define palette on the fly.)