Giter VIP home page Giter VIP logo

Comments (2)

mbacou avatar mbacou commented on June 2, 2024

Never mind, this works no problem!

token = Sys.getenv("MAPBOX_TOKEN")
terrain_img = "terrain-rgb"
surface_img = "satellite"

elev_map = list(
  rScaler = 6553.6,
  gScaler = 25.6,
  bScaler = 0.1,
  offset = -10000  
)

props = list(
      minZoom = 0,
      maxZoom = 23,
      strategy = "no-overlap",
      elevationDecoder = elev_map,
      elevationData = sprintf(
        "https://api.mapbox.com/v4/mapbox.%s/{z}/{x}/{y}.png?access_token=%s",
        terrain_img, token),
      texture = sprintf(
        "https://api.mapbox.com/v4/mapbox.%s/{z}/{x}/{y}.png?access_token=%s",
        surface_img, token),
      wireframe = FALSE,
      color = c(255, 255, 255)
)

deckgl(
  element_id = "mapgl",
  latitude = 13,
  longitude =-6,
  zoom = 12,
  bearing = 140,
  pitch = 60,
  maxPitch = 89,
  height = "360px"
) %>%
  add_layer("TerrainLayer",
    id = "terrain",
    properties = props)

from deckgl.

jvandens avatar jvandens commented on June 2, 2024

I'm trying to do a similar thing, but with a downloaded bathymetry raster layer from the marmap package. See below for reproducible example, I don't understand why deckgl is not rendering the terrain layer, but I suspect it's something with how the png image is produced?

library(marmap)

# noaa bathy
b <- getNOAA.bathy(lon1 = -74.2, lon2 =  -73.3, lat1=40.3,
                   lat2 = 40.7, resolution = 0.1)

# convert to raster and save as png?
r <- as.raster(b)
png(file = "output/bathy_grey.png")
raster::plot(r, maxpixels=ncell(r), col=grey.colors(255), 
             axes=FALSE, box=FALSE, legend=FALSE)
dev.off()

elevation_data <- normalizePath( "output/bathy_grey.png")
bounds =  c(r@extent@xmin, r@extent@ymin, r@extent@xmax, r@extent@ymax)

elevation <-  sprintf("data:image/png;base64,%s", base64enc::base64encode(elevation_data))

elev_map = list(
  rScaler = 1,
  gScaler = 0,
  bScaler = 0,
  offset = 0  
)

props = list(
  strategy = "no-overlap",
  elevationDecoder = elev_map,
  elevationData = elevation,
  bounds = bounds 
)

deckgl(
  latitude = 40.5,
  longitude = -74,
  zoom = 10,
  pitch = 45,
  height = "600px") |> 
  add_basemap() |> 
  add_layer("TerrainLayer",
            id = "terrain",
            properties = props)

from deckgl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.