Render a 2D floating overlay over the map.

Cache fallback messages are disabled by default. Set options(rayshader.verbose_scene_cache = TRUE) to print when cached metadata is reused.

Note: Multiple layers with transparency can cause rendering issues in rgl.

render_floating_overlay(
  overlay = NULL,
  altitude = NULL,
  alpha = 1,
  remove_na = TRUE,
  reorient = TRUE,
  clear_layers = FALSE,
  horizontal_offset = c(0, 0),
  zscale = 1,
  vertical_exaggeration = 1,
  heightmap = NULL,
  ...
)

Arguments

overlay

Overlay (4D RGBA array) to be rendered on the 3D map.

altitude

Altitude to place the overlay.

alpha

Default 1. Multiplies the layer's transparency by this factor. 0 is completely transparent.

remove_na

Default TRUE. Whether to make the overlay transparent above empty spaces represented by NA values in the active heightmap.

reorient

Default TRUE. Whether to transpose the heightmap's NA mask to match the overlay texture orientation.

clear_layers

Default FALSE. Clears all existing floating layers on the visualization.

horizontal_offset

Default c(0,0). Distance (in 3D space) to offset the floating offset in the x/y directions.

zscale

Default 1. The ratio between the x and y spacing (which are assumed to be equal) and the z axis. For example, if the elevation levels are in units of 1 meter and the grid values are separated by 10 meters, zscale would be 10. Adjust the zscale down to exaggerate elevation features.

vertical_exaggeration

Default 1. Multiplier applied to the effective visual relief. If omitted, rayshader uses the cached scene value from plot_3d() or plot_gg() when available; pass explicitly to override for this call.

heightmap

Default NULL. Height matrix whose existing NA cells mask the overlay when remove_na = TRUE. If omitted, this is taken from the cached scene set by plot_3d() or plot_gg(). Pass explicitly to override the cached value.

...

Additional arguments to pass to rgl::triangles3d().

Value

Adds a 3D floating layer to the map. No return value.

Examples

#Render the road network as a floating overlay layer, along with a label annotation and a floating
#point annotation
if(all(length(find.package("sf", quiet = TRUE)) > 0,
      length(find.package("magick", quiet = TRUE)) > 0)) {
 monterey = c(-121.892933,36.603053)
 monterey_city = sf::st_sfc(sf::st_point(monterey))
 sf::st_crs(monterey_city) = sf::st_crs(montereybay_spatial)

 #Generate Overlays
 road_overlay = generate_line_overlay(monterey_roads_sf, heightmap = montereybay_spatial)
 point_overlay = generate_point_overlay(monterey_city, color="red", size=1,
                                        heightmap = montereybay_spatial)

 #Create 3D plot (water transparency set to 1 because multiple transparency layers can interfere)
 montereybay_spatial |>
   height_shade() |>
   add_shadow(ray_shade(vertical_exaggeration = 4),0.3) |>
   plot_3d(water = TRUE, water_alpha = 1, window_size = 800,
           water_color = "lightblue", vertical_exaggeration = 4)
 render_camera(theta=-55,phi=45,zoom=0.8)

 #Render label
 render_label(lat = monterey[2], long = monterey[1], altitude = 9900,
              text = "Monterey", text_color = "black", line_color="darkred")

 #Render Floating Overlays
 render_floating_overlay(road_overlay, altitude = 10000)
 render_floating_overlay(point_overlay, altitude = 100)
 render_snapshot()
}