0

I have a Mapbox tileset that I have set to an Albers projection, however I have been unsuccessful at getting it to show in the correct conical projection (ie top of continental U.S. is curved) using R Leaflet.

I have tried starting with a barebones leaflet map object and adding the tiles, and also tried setting the leaflet options crs to esri 102003, but I still get a map that is not in the Albers projection. (I've tried tons of other things too, but will leave out for brevity).

How can I maintain the Albers projection for the Mapbox tiles in my leaflet map?

Code with no crs set:

library(tidyverse)
library(leaflet)
library(mapboxapi)

leaflet() %>% 
  mapboxapi::addMapboxTiles(style_id = "cl9rbsx37000114o3okjal1ej",
                            username = my_mapbox_user, # You will need a mapbox account and access token to run this, but the style is public
                            access_token = my_mapbox_token
  ) %>% 
  setView(lat = 39.383333, lng = -101.683333, zoom = 5)

Code with crs ESRI 102003:


esri102003 <- leafletCRS(
  code = "ESRI:102003",
  proj4def = "+proj=aea +lat_0=37.5 +lon_0=-96 +lat_1=29.5 +lat_2=45.5 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +type=crs"
)
leaflet(options = leafletOptions(crs = esri102003)) %>% 
  mapboxapi::addMapboxTiles(style_id = "cl5gziyik000114mvx4palaee",
                            username = "jzadra",
                            access_token = "pk.eyJ1IjoianphZHJhIiwiYSI6ImNrMWwwb29jYzAwaTMzZHBvNzQ2NDE2NGIifQ.26_gaV_TD6T8I0Hz8oM94g"
  ) %>% 
  setView(lat = 39.383333, lng = -101.683333, zoom = 5)

Both of the above code chunks produce this map: enter image description here

Screenshot of mapbox studio showing albers projection:

enter image description here

jzadra
  • 4,012
  • 2
  • 26
  • 46
  • Crossposted to https://github.com/rstudio/leaflet/issues/828 due to lack of any response here. – jzadra Nov 02 '22 at 17:33
  • Probably nonsense but is this perhaps related to [setView- closed #582](https://github.com/rstudio/leaflet/issues/582)? – Chris Nov 04 '22 at 13:40
  • I don't know anything about mapbox studio but I think leaflet doesn't do any proyection transformation on raster tileset it downloads, perhaps you must check if "style" is ok. – Ric Nov 05 '22 at 11:18

0 Answers0