Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking for correctly input leaflet provider strings #921

Closed
jack-davison opened this issue Jun 6, 2024 · 2 comments · Fixed by #929
Closed

Checking for correctly input leaflet provider strings #921

jack-davison opened this issue Jun 6, 2024 · 2 comments · Fixed by #929

Comments

@jack-davison
Copy link
Contributor

jack-davison commented Jun 6, 2024

I'm posting this as it potentially links to quarto-dev/quarto-cli#9897.

In short, I came into an issue where a slightly misspelled leaflet provider string ended up breaking my whole Quarto document, which was an issue that was tricky to track down!

But what struck me - why can leaflet() chug along happily and render something with an incorrectly specified provider tileset? e.g., if you were to run leaflet(breweries91) |> addProviderTiles("woops") |> addMarkers() you get a broken leaflet map without any markers on it or anything, rather than an error. Could addProviderTiles() not check the provider arg against leaflet::providers to provide a useful error in such cases?

e.g., just an internal check within addProviderTiles() along the lines of:

check_provider <- function(provider) {
  provider <- match.arg(provider, names(leaflet::providers))
  return(provider)
}

check_provider("CartoDB.Positron")
#> [1] "CartoDB.Positron"

check_provider("CartoDB.Bositron")
#> Error in match.arg(provider, names(leaflet::providers)): 'arg' should be one of "OpenStreetMap", "OpenStreetMap.Mapnik", "OpenStreetMap.DE", "OpenStreetMap.CH", "OpenStreetMap.France", "OpenStreetMap.HOT", "OpenStreetMap.BZH", "MapTilesAPI", "MapTilesAPI.OSMEnglish", "MapTilesAPI.OSMFrancais", "MapTilesAPI.OSMEspagnol", "OpenSeaMap", "OPNVKarte", "OpenTopoMap", "OpenRailwayMap", "OpenFireMap", "SafeCast", "Stadia", "Stadia.AlidadeSmooth", "Stadia.AlidadeSmoothDark", "Stadia.OSMBright", "Stadia.Outdoors", "Stadia.StamenToner", "Stadia.StamenTonerBackground", "Stadia.StamenTonerLines", "Stadia.StamenTonerLabels", "Stadia.StamenTonerLite", "Stadia.StamenWatercolor", "Stadia.StamenTerrain", "Stadia.StamenTerrainBackground", "Stadia.StamenTerrainLabels", "Stadia.StamenTerrainLines", "Thunderforest", "Thunderforest.OpenCycleMap", "Thunderforest.Transport", "Thunderforest.TransportDark", "Thunderforest.SpinalMap", "Thunderforest.Landscape", "Thunderforest.Outdoors", "Thunderforest.Pioneer", "Thunderforest.MobileAtlas", "Thunderforest.Neighbourhood", "CyclOSM", "Jawg", "Jawg.Streets", "Jawg.Terrain", "Jawg.Sunny", "Jawg.Dark", "Jawg.Light", "Jawg.Matrix", "MapBox", "MapTiler", "MapTiler.Streets", "MapTiler.Basic", "MapTiler.Bright", "MapTiler.Pastel", "MapTiler.Positron", "MapTiler.Hybrid", "MapTiler.Toner", "MapTiler.Topo", "MapTiler.Voyager", "TomTom", "TomTom.Basic", "TomTom.Hybrid", "TomTom.Labels", "Esri", "Esri.WorldStreetMap", "Esri.DeLorme", "Esri.WorldTopoMap", "Esri.WorldImagery", "Esri.WorldTerrain", "Esri.WorldShadedRelief", "Esri.WorldPhysical", "Esri.OceanBasemap", "Esri.NatGeoWorldMap", "Esri.WorldGrayCanvas", "OpenWeatherMap", "OpenWeatherMap.Clouds", "OpenWeatherMap.CloudsClassic", "OpenWeatherMap.Precipitation", "OpenWeatherMap.PrecipitationClassic", "OpenWeatherMap.Rain", "OpenWeatherMap.RainClassic", "OpenWeatherMap.Pressure", "OpenWeatherMap.PressureContour", "OpenWeatherMap.Wind", "OpenWeatherMap.Temperature", "OpenWeatherMap.Snow", "HERE", "HERE.normalDay", "HERE.normalDayCustom", "HERE.normalDayGrey", "HERE.normalDayMobile", "HERE.normalDayGreyMobile", "HERE.normalDayTransit", "HERE.normalDayTransitMobile", "HERE.normalDayTraffic", "HERE.normalNight", "HERE.normalNightMobile", "HERE.normalNightGrey", "HERE.normalNightGreyMobile", "HERE.normalNightTransit", "HERE.normalNightTransitMobile", "HERE.reducedDay", "HERE.reducedNight", "HERE.basicMap", "HERE.mapLabels", "HERE.trafficFlow", "HERE.carnavDayGrey", "HERE.hybridDay", "HERE.hybridDayMobile", "HERE.hybridDayTransit", "HERE.hybridDayGrey", "HERE.hybridDayTraffic", "HERE.pedestrianDay", "HERE.pedestrianNight", "HERE.satelliteDay", "HERE.terrainDay", "HERE.terrainDayMobile", "HEREv3", "HEREv3.normalDay", "HEREv3.normalDayCustom", "HEREv3.normalDayGrey", "HEREv3.normalDayMobile", "HEREv3.normalDayGreyMobile", "HEREv3.normalDayTransit", "HEREv3.normalDayTransitMobile", "HEREv3.normalNight", "HEREv3.normalNightMobile", "HEREv3.normalNightGrey", "HEREv3.normalNightGreyMobile", "HEREv3.normalNightTransit", "HEREv3.normalNightTransitMobile", "HEREv3.reducedDay", "HEREv3.reducedNight", "HEREv3.basicMap", "HEREv3.mapLabels", "HEREv3.trafficFlow", "HEREv3.carnavDayGrey", "HEREv3.hybridDay", "HEREv3.hybridDayMobile", "HEREv3.hybridDayTransit", "HEREv3.hybridDayGrey", "HEREv3.pedestrianDay", "HEREv3.pedestrianNight", "HEREv3.satelliteDay", "HEREv3.terrainDay", "HEREv3.terrainDayMobile", "FreeMapSK", "MtbMap", "CartoDB", "CartoDB.Positron", "CartoDB.PositronNoLabels", "CartoDB.PositronOnlyLabels", "CartoDB.DarkMatter", "CartoDB.DarkMatterNoLabels", "CartoDB.DarkMatterOnlyLabels", "CartoDB.Voyager", "CartoDB.VoyagerNoLabels", "CartoDB.VoyagerOnlyLabels", "CartoDB.VoyagerLabelsUnder", "HikeBike", "HikeBike.HikeBike", "HikeBike.HillShading", "BasemapAT", "BasemapAT.basemap", "BasemapAT.grau", "BasemapAT.overlay", "BasemapAT.terrain", "BasemapAT.surface", "BasemapAT.highdpi", "BasemapAT.orthofoto", "nlmaps", "nlmaps.standaard", "nlmaps.pastel", "nlmaps.grijs", "nlmaps.water", "nlmaps.luchtfoto", "NASAGIBS", "NASAGIBS.ModisTerraTrueColorCR", "NASAGIBS.ModisTerraBands367CR", "NASAGIBS.ViirsEarthAtNight2012", "NASAGIBS.ModisTerraLSTDay", "NASAGIBS.ModisTerraSnowCover", "NASAGIBS.ModisTerraAOD", "NASAGIBS.ModisTerraChlorophyll", "NLS", "JusticeMap", "JusticeMap.income", "JusticeMap.americanIndian", "JusticeMap.asian", "JusticeMap.black", "JusticeMap.hispanic", "JusticeMap.multi", "JusticeMap.nonWhite", "JusticeMap.white", "JusticeMap.plurality", "GeoportailFrance", "GeoportailFrance.plan", "GeoportailFrance.parcels", "GeoportailFrance.orthos", "OneMapSG", "OneMapSG.Default", "OneMapSG.Night", "OneMapSG.Original", "OneMapSG.Grey", "OneMapSG.LandLot", "USGS", "USGS.USTopo", "USGS.USImagery", "USGS.USImageryTopo", "WaymarkedTrails", "WaymarkedTrails.hiking", "WaymarkedTrails.cycling", "WaymarkedTrails.mtb", "WaymarkedTrails.slopes", "WaymarkedTrails.riding", "WaymarkedTrails.skating", "OpenAIP", "OpenSnowMap", "OpenSnowMap.pistes", "AzureMaps", "AzureMaps.MicrosoftImagery", "AzureMaps.MicrosoftBaseDarkGrey", "AzureMaps.MicrosoftBaseRoad", "AzureMaps.MicrosoftBaseHybridRoad", "AzureMaps.MicrosoftTerraMain", "AzureMaps.MicrosoftWeatherInfraredMain", "AzureMaps.MicrosoftWeatherRadarMain", "SwissFederalGeoportal", "SwissFederalGeoportal.NationalMapColor", "SwissFederalGeoportal.NationalMapGrey", "SwissFederalGeoportal.SWISSIMAGE"

Created on 2024-06-06 with reprex v2.1.0

@jack-davison
Copy link
Contributor Author

I can see this is actually a duplicate of #677 from 2020!

@schloerke
Copy link
Contributor

Maybe something like

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)
}

This gives us an out in case someone was doing something funny. But I do like safe guarding the default behavior.

(PR welcome! Thank you)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants