qfes / rdeck

Deck.gl widget for R
https://qfes.github.io/rdeck
MIT License
97 stars 0 forks source link

possible to use different map projections? #107

Open DanWismer opened 10 months ago

DanWismer commented 10 months ago

Great package! I just discovered your work today from reading this blog!

Is it possible to use a different Mapbox GL JS map projection such as Albers? And can you render projected layers on top of the projected basemap?

Thanks!

anthonynorth commented 10 months ago

Great package! I just discovered your work today from reading this blog!

Thanks!

Is it possible to use a different Mapbox GL JS map projection such as Albers?

This is disabled currently, since I've not explored how to do this:

And can you render projected layers on top of the projected basemap?

Projected deck.gl layers might be doable (or even simple) with interleaved rendering (planned).

What {rdeck} maps with different projections will currently look like:

sa1s <-
  strayr::read_absmap("sa12016") |>
  dplyr::mutate(
    position = rdeck::xy(cent_long, cent_lat),
    val = runif(dplyr::n() * as.numeric(state_code_2016)) |>
      round(2)
  )

map <- 
  rdeck::rdeck(initial_bounds = wk::wk_bbox(sa1s$position)) |>
  rdeck::add_scatterplot_layer(
    data = sa1s,
    radius_min_pixels = 5,
    get_fill_color = rdeck::scale_color_linear(val)
  )

# HACK: change projection
map$x$mapgl$projection <- "albers"

# render
map

rdeck

DanWismer commented 10 months ago

This is awesome!

If there a way to get the basemap to align with those points?

Can you do this albers projection with a raster?

For some some context, I have only built web maps using leaflet and have been searching for a way to have a projected raster (or tiles) not in web Mercator overlay a projected basemap not in web Mercator.

anthonynorth commented 10 months ago

The deck.gl map controller only supports web mercator, so the example above has very weird behaviour for the basemap and isn't usable with or without data.

If there a way to get the basemap to align with those points? Can you do this albers projection with a raster?

Maybe. Exploration needed to know for sure.

I think first steps are to pivot to MapboxOverlay api which makes the mapbox basemap the controller. That would make the basemap behave correctly, also allows for simple switching between interleave/overlay modes. Deck.gl layers working with different mapbox projections is an unknown.