addHeightgraph: Add a Heightgraph layer

View source: R/heightgraph.R

addHeightgraphR Documentation

Add a Heightgraph layer

Description

Visualize height information and road attributes of linestring segments. The linestrings must be a Simple Feature LINESTRING Z and are transformed to GeoJSON. The function therefore inherits arguments from addGeoJSON.

Usage

addHeightgraph(
  map,
  data = NULL,
  columns = NULL,
  layerId = NULL,
  group = NULL,
  color = "#03F",
  weight = 5,
  opacity = 0.5,
  dashArray = NULL,
  smoothFactor = 1,
  noClip = FALSE,
  pathOpts = leaflet::pathOptions(),
  options = heightgraphOptions()
)

Arguments

map

a map widget object created from leaflet()

data

A Simple Feature LINESTRING with Z dimension.

columns

A character vector of the columns you want to include in the heightgraph control

layerId

the layer id

group

the name of the group the newly created layers should belong to (for clearGroup and addLayersControl purposes). Human-friendly group names are permitted–they need not be short, identifier-style names. Any number of layers and even different types of layers (e.g. markers and polygons) can share the same group name.

color

stroke color

weight

stroke width in pixels

opacity

stroke opacity (or layer opacity for tile layers)

dashArray

a string that defines the stroke dash pattern

smoothFactor

how much to simplify the polyline on each zoom level (more means better performance and less accurate representation)

noClip

whether to disable polyline clipping

pathOpts

List of further options for the path. See pathOptions

options

List of further plugin options. See heightgraphOptions

Value

the new map object

Note

When used in Shiny, 3 events update a certain Shiny Input:

  1. A click updates input$MAPID_heightgraph_click

  2. A mouseover updates input$MAPID_heightgraph_mouseover

  3. A mouseout updates input$MAPID_heightgraph_mouseout

If you want to explicitly remove the Heightgraph control, please use removeControl with the layerId = "hg_control".

References

https://github.com/GIScience/Leaflet.Heightgraph

See Also

Other Heightgraph Functions: heightgraphOptions()

Examples

## Not run: 
library(leaflet)
library(leaflet.extras2)
library(sf)

data <- st_cast(st_as_sf(leaflet::atlStorms2005[4,]), "LINESTRING")
data <- st_transform(data, 4326)
data <- data.frame(st_coordinates(data))
data$elev <-  runif(nrow(data), 10, 500)
data$L1 <- NULL
L1 <- round(seq.int(1, 4, length.out = nrow(data)))
data <- st_as_sf(st_sfc(lapply(split(data, L1), sfg_linestring)))
data <- st_as_sf(st_sfc(lapply(split(data, L1), function(x) {
    st_linestring(as.matrix(x))
})))
data$steepness <- 1:nrow(data)
data$suitability <- nrow(data):1
data$popup <- apply(data, 1, function(x) {
 sprintf("Steepness: %s<br>Suitability: %s", x$steepness, x$suitability)
})

leaflet() %>%
  addTiles(group = "base") %>%
  addHeightgraph(color = "red", columns = c("steepness", "suitability"),
                 opacity = 1, data = data, group = "heightgraph",
                 options = heightgraphOptions(width = 400))

## End(Not run)

leaflet.extras2 documentation built on Aug. 21, 2023, 5:08 p.m.