Closed CIOData closed 4 months ago
It's kind of a wonky solution, based on this: https://gis.stackexchange.com/questions/398348/mapbox-map-with-no-style-only-self-hosted-vector-data
I'd be open to it as a feature request! Note that the Albers projection is only available in Mapbox, not MapLibre.
library(mapgl)
library(tigris)
library(jsonlite)
js_object <- list(
version = 8,
sources = structure(list(), .Names = character(0)),
layers = list()
)
json_output <- toJSON(js_object, auto_unbox = TRUE, pretty = TRUE)
us_states <- states(cb = TRUE, resolution = "20m") |>
shift_geometry()
mapboxgl(style = json_output,
projection = "albers",
center = c(-98.8, 37.68),
zoom = 3.4) |>
add_fill_layer(
id = "states",
source = us_states,
fill_color = "navy",
fill_opacity = 0.7,
tooltip = "NAME"
)
You can also author a custom blank style with a background in Mapbox Studio, then use that. Here I've got a style with a light grey background I set up in Studio.
style_url <- "mapbox://styles/kwalkertcu/clz2wwap502f301pafh8ad1zv/draft"
mapboxgl(style = style_url,
projection = "albers",
center = c(-98.8, 37.68),
zoom = 3.4) |>
add_fill_layer(
id = "states",
source = us_states,
fill_color = "navy",
fill_opacity = 0.7,
tooltip = "NAME"
)
This was helpful, but I've run into a funny issue. When I try to use this solution with add_fill_extrusion_layer()
I get a half copy of the map off in the distance at certain zoom levels.
This does not happen when I use just add_fill_layer()
.
Any thoughts on what might be happening? I can't seem to figure it out.
I am trying to create a map using shifted geometry for the US (i.e. Alaska and Hawaii moved), and need to have an empty/solid color basemap option for displaying it. I can't seem to find an option for doing this in
mapboxgl()
ormaplibre()
.