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
andaddLayersControl
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
Note
When used in Shiny, 3 events update a certain Shiny Input:
A click updates
input$MAPID_heightgraph_click
A mouseover updates
input$MAPID_heightgraph_mouseover
A mouseout updates
input$MAPID_heightgraph_mouseout
If you want to explicitly remove the Heightgraph control, please use
removeControl
with the layerId = "hg_control"
.
See also
Other Heightgraph Functions:
heightgraphOptions()
Examples
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 <- round(runif(nrow(data), 10, 500), 2)
data$L1 <- NULL
L1 <- round(seq.int(1, 4, length.out = nrow(data)))
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)
)