mapview
mapview copied to clipboard
USGS basemaps don't display in mapview map
Hi folks, awesome package, thanks so much for all your work. This may be an issue out of your control, if so, feel free to ignore/close this. Just wondering why it's not working. I'd like to add a USGS basemap layer to a map I'm making. I'm using OSX Mojave 10.14.6, and R v4.0.3.
This doesn't work
It makes a map but displays no point, nor the option to toggle these basemap layers:
library(sf) # Linking to GEOS 3.8.1, GDAL 3.1.1, PROJ 6.3.1
library(mapview) # GDAL version >= 3.1.0 | setting mapviewOptions(fgb = TRUE)
mapviewOptions(basemaps = c("OpenTopoMap", "USGS.USImageryTopo"))
pt <- st_sfc(st_point(c(-122.39, 41.52)), crs=4326)
mapview(pt)
This works
Makes a map with two layers that I can toggle, and shows point.
library(sf) # Linking to GEOS 3.8.1, GDAL 3.1.1, PROJ 6.3.1
library(mapview) # GDAL version >= 3.1.0 | setting mapviewOptions(fgb = TRUE)
mapviewOptions(basemaps = c("OpenTopoMap", "Esri.WorldImagery"))
pt <- st_sfc(st_point(c(-122.39, 41.52)), crs=4326)
mapview(pt)
I've tried switching fgb=FALSE
and still no change. I've also tried a few other USGS layers and have had no success. Any thoughts? Or is this just specific to the USGS leaflet layers (http://leaflet-extras.github.io/leaflet-providers/preview/). Thanks for any insight!
Thanks @ryanpeek.
The map creation breaks early on the javascript side in the browser. If you open your browser console (press F12 usually) you should see an error along the lines of Uncaught No such provider (USGS)
Providers for the leaflet package are packaged in the leaflet.providers package. On my installation I see
names(leaflet.providers::providers_loaded()$providers)
[1] "OpenStreetMap" "OpenStreetMap.Mapnik"
[3] "OpenStreetMap.DE" "OpenStreetMap.CH"
[5] "OpenStreetMap.France" "OpenStreetMap.HOT"
[7] "OpenStreetMap.BZH" "OpenSeaMap"
[9] "OpenPtMap" "OpenTopoMap"
[11] "OpenRailwayMap" "OpenFireMap"
[13] "SafeCast" "Thunderforest"
[15] "Thunderforest.OpenCycleMap" "Thunderforest.Transport"
[17] "Thunderforest.TransportDark" "Thunderforest.SpinalMap"
[19] "Thunderforest.Landscape" "Thunderforest.Outdoors"
[21] "Thunderforest.Pioneer" "Thunderforest.MobileAtlas"
[23] "Thunderforest.Neighbourhood" "OpenMapSurfer"
[25] "OpenMapSurfer.Roads" "OpenMapSurfer.Hybrid"
[27] "OpenMapSurfer.AdminBounds" "OpenMapSurfer.ContourLines"
[29] "OpenMapSurfer.Hillshade" "OpenMapSurfer.ElementsAtRisk"
[31] "Hydda" "Hydda.Full"
[33] "Hydda.Base" "Hydda.RoadsAndLabels"
[35] "MapBox" "Stamen"
[37] "Stamen.Toner" "Stamen.TonerBackground"
[39] "Stamen.TonerHybrid" "Stamen.TonerLines"
[41] "Stamen.TonerLabels" "Stamen.TonerLite"
[43] "Stamen.Watercolor" "Stamen.Terrain"
[45] "Stamen.TerrainBackground" "Stamen.TerrainLabels"
[47] "Stamen.TopOSMRelief" "Stamen.TopOSMFeatures"
[49] "TomTom" "TomTom.Basic"
[51] "TomTom.Hybrid" "TomTom.Labels"
[53] "Esri" "Esri.WorldStreetMap"
[55] "Esri.DeLorme" "Esri.WorldTopoMap"
[57] "Esri.WorldImagery" "Esri.WorldTerrain"
[59] "Esri.WorldShadedRelief" "Esri.WorldPhysical"
[61] "Esri.OceanBasemap" "Esri.NatGeoWorldMap"
[63] "Esri.WorldGrayCanvas" "OpenWeatherMap"
[65] "OpenWeatherMap.Clouds" "OpenWeatherMap.CloudsClassic"
[67] "OpenWeatherMap.Precipitation" "OpenWeatherMap.PrecipitationClassic"
[69] "OpenWeatherMap.Rain" "OpenWeatherMap.RainClassic"
[71] "OpenWeatherMap.Pressure" "OpenWeatherMap.PressureContour"
[73] "OpenWeatherMap.Wind" "OpenWeatherMap.Temperature"
[75] "OpenWeatherMap.Snow" "HERE"
[77] "HERE.normalDay" "HERE.normalDayCustom"
[79] "HERE.normalDayGrey" "HERE.normalDayMobile"
[81] "HERE.normalDayGreyMobile" "HERE.normalDayTransit"
[83] "HERE.normalDayTransitMobile" "HERE.normalDayTraffic"
[85] "HERE.normalNight" "HERE.normalNightMobile"
[87] "HERE.normalNightGrey" "HERE.normalNightGreyMobile"
[89] "HERE.normalNightTransit" "HERE.normalNightTransitMobile"
[91] "HERE.reducedDay" "HERE.reducedNight"
[93] "HERE.basicMap" "HERE.mapLabels"
[95] "HERE.trafficFlow" "HERE.carnavDayGrey"
[97] "HERE.hybridDay" "HERE.hybridDayMobile"
[99] "HERE.hybridDayTransit" "HERE.hybridDayGrey"
[101] "HERE.hybridDayTraffic" "HERE.pedestrianDay"
[103] "HERE.pedestrianNight" "HERE.satelliteDay"
[105] "HERE.terrainDay" "HERE.terrainDayMobile"
[107] "FreeMapSK" "MtbMap"
[109] "CartoDB" "CartoDB.Positron"
[111] "CartoDB.PositronNoLabels" "CartoDB.PositronOnlyLabels"
[113] "CartoDB.DarkMatter" "CartoDB.DarkMatterNoLabels"
[115] "CartoDB.DarkMatterOnlyLabels" "CartoDB.Voyager"
[117] "CartoDB.VoyagerNoLabels" "CartoDB.VoyagerOnlyLabels"
[119] "CartoDB.VoyagerLabelsUnder" "HikeBike"
[121] "HikeBike.HikeBike" "HikeBike.HillShading"
[123] "BasemapAT" "BasemapAT.basemap"
[125] "BasemapAT.grau" "BasemapAT.overlay"
[127] "BasemapAT.highdpi" "BasemapAT.orthofoto"
[129] "nlmaps" "nlmaps.standaard"
[131] "nlmaps.pastel" "nlmaps.grijs"
[133] "nlmaps.luchtfoto" "NASAGIBS"
[135] "NASAGIBS.ModisTerraTrueColorCR" "NASAGIBS.ModisTerraBands367CR"
[137] "NASAGIBS.ViirsEarthAtNight2012" "NASAGIBS.ModisTerraLSTDay"
[139] "NASAGIBS.ModisTerraSnowCover" "NASAGIBS.ModisTerraAOD"
[141] "NASAGIBS.ModisTerraChlorophyll" "NLS"
[143] "JusticeMap" "JusticeMap.income"
[145] "JusticeMap.americanIndian" "JusticeMap.asian"
[147] "JusticeMap.black" "JusticeMap.hispanic"
[149] "JusticeMap.multi" "JusticeMap.nonWhite"
[151] "JusticeMap.white" "JusticeMap.plurality"
[153] "Wikimedia" "GeoportailFrance"
[155] "GeoportailFrance.parcels" "GeoportailFrance.ignMaps"
[157] "GeoportailFrance.maps" "GeoportailFrance.orthos"
[159] "OneMapSG" "OneMapSG.Default"
[161] "OneMapSG.Night" "OneMapSG.Original"
[163] "OneMapSG.Grey" "OneMapSG.LandLot"
so USGS maps don't seem to be supported. I think you'd need to file a feature request with the folks at leaflet.providers to get them supported.
@ryanpeek I was just trying to do something similar and found a workaround that you may be still interested in. Once establishing the mapview object, you can add the USGS Imagery Topo basemap with leaflet::addTiles()
. The trouble I've found is that this particular basemap has a maximum zoom threshold below what I would prefer and can't seem to change, so I still establish "Esri.WorldImagery" as the map.type in mapview()
. But anything zoomed further out shows USGS.USImageryTopo.
Using your example:
library(sf)
library(mapview)
library(leaflet)
library(tidyverse)
pt <- st_sfc(st_point(c(-122.39, 41.52)), crs=4326)
mv_obj <- mapview(pt, map.types = "Esri.WorldImagery")
mv_obj@map %>%
leaflet::addTiles(url = "https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryTopo/MapServer/tile/{z}/{y}/{x}")
The url for the leaflet basemap can be found here.
@snmarkley1 Thanks much! this is helpful to know about.