rstudio / leaflet

R Interface to Leaflet Maps
http://rstudio.github.io/leaflet/
Other
805 stars 509 forks source link

addProviderTiles work but Esri.OceanBasemap option suddenly does not work #841

Open NathanWhitmore opened 1 year ago

NathanWhitmore commented 1 year ago

Hi there. Unfortunately, the Esri.OceanBasemap tile option is no longer rendering via addProviderTiles (I've tried on my machine R version 4.2.0 and via Posit Cloud 4.2.2). Other tiles continue to render as expected. The code worked fine a few weeks ago.

This code now just renders a blank map:

library(leaflet)

leaflet() %>%
  addProviderTiles("Esri.OceanBasemap")

However, I can get the ocean basemap via the leaflet.esri package which suggests the issue may not be on the map server side.

library(leaflet)
library(leaflet.esri)

leaflet() %>%
  addEsriBasemapLayer(esriBasemapLayers$Oceans)

Any thoughts?

bbest commented 1 year ago

The Esri.OceanBasemap got retired:

and a new endpoint created (from Ocean_Basemap to Ocean/World_Ocean_Base), which seems to be updated in leaflet-providers on Feb 10, 2023:

This line could be edited:

https://github.com/rstudio/leaflet/blob/ffd4ac8e43c882a8d1280dfc2a971f952b0e1c96/docs/libs/leaflet-providers/leaflet-providers_1.9.0.js#L423

But better to update the whole file to latest with PR. I don't have time at the moment to do this.

bbest commented 1 year ago

After a bit more exploration, I discovered:

  1. The layer variant name changed from:
    • OLD: Ocean_Basemap
    • NEW: Ocean/World_Ocean_Base for surface + Ocean/World_Ocean_Reference for labels
  2. The file mentioned above leaflet-providers_1.9.0.js is only applicable to the documentation site for this R package. The htmlwidget dependency gets loaded into libs (or inline) upon rendering to html. The source for the leaflet-providers_{version}.js actually comes from the leaflet.providers R package, which can pull the latest leaflet-providers - npm via unpkg.com, eg https://unpkg.com/leaflet-providers@1.13.0/leaflet-providers.js. However, the npm package has not been updated for a year, so it doesn't reflect the latest fix for Esri.OceanBasemap at leaflet-extras/leaflet-providers: leaflet-providers.js#L472 .
  3. Until the latest leaflet-providers.js gets updated on npm, here's a reasonable workaround to manually set the proper variant while giving you the option of separately displaying Base imagery vs Reference labels and borders:
leaflet() |>
  # add base: blue bathymetry and light brown/green topography
  addProviderTiles(
    "Esri.OceanBasemap",
    options = providerTileOptions(
      variant = "Ocean/World_Ocean_Base")) |>
  # add reference: placename labels and borders
  addProviderTiles(
    "Esri.OceanBasemap",
    options = providerTileOptions(
      variant = "Ocean/World_Ocean_Reference"))

OLD: with some previously cached tiles showing up

image

NEW: with fully functional base and reference layers

image