rstudio / leaflet

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

feat: check tile providers in `addProviderTiles()` #929

Closed jack-davison closed 1 month ago

jack-davison commented 2 months ago

Fixes #921 Fixes #677

In short, it adds the .check arg to addProviderTiles(), which defaults to TRUE. When TRUE, if a user mistakenly provides a provider not in leaflet.providers::providers_loaded(), the function will error.

Also adds a test to check this new argument is working as it should.

PR task list:

jack-davison commented 2 months ago

@schloerke, you gave this example in https://github.com/rstudio/leaflet/issues/921#issuecomment-2252807843_

addProviderTiles <- function(
  map,
  provider,
  layerId = NULL,
  group = NULL,
  options = providerTileOptions(),
  ...,
  check = TRUE
) {
  if (isTRUE(check)) {
    check_provider(provider)
  }
  map$dependencies <- c(map$dependencies, leafletProviderDependencies())
  invokeMethod(map, getMapData(map), "addProviderTiles",
    provider, layerId, group, options)
}

addProviderTiles() didn't originally have a ... param - I've added it as per your example, but it currently doesn't do anything! Did you want it adding for some reason, or was it just a mistake in your suggestion?

schloerke commented 1 month ago

Thank you, @jack-davison !