ol_geom_text: OpenLayers Text Layer

View source: R/layer_text.R

ol_geom_textR Documentation

OpenLayers Text Layer

Description

Function to create a Text layer to add to an OpenLayers Map object.

Usage

ol_geom_text(point.obj, label, name = NULL, toggle.control = FALSE,
  label.params = list(), tooltip = NULL, tooltip.params = list())

Arguments

point.obj

SpatialPointsDataframe, SpatialPoints, or a matrix containing columns of point longitudes and latitudes, respectively.

label

character vector of text labels to put at points.

name

character Layer name.

toggle.control

logical indicating whether this layer will have a visibility toggle.

label.params

named list (e.g., list(property=value)) of label position and format parameters. See below.

tooltip

character vector of point feature tooltip popups.

tooltip.params

named list (e.g., list(property=value)) of tooltip position and format parameters. See ol_geom_polygon documentation.

Details

This function stores the data required to generate an OpenLayers vector layer with text features using Point geometries. It does not enable aesthetic mappings to variables.

Value

A list object of class Layer.Text.

Formatting Labels With label.params

The label.params parameter provide direct access to OpenLayers feature text styling (see OpenLayers Documentation). Multiple values for any of these properties is not supported. The following ol/style/Text properties are supported:

font character label font CSS string
offsetX numeric label x-offset
offsetY numeric label y-offset
rotation numeric label rotation
textAlign character label text horizontal alighment
textBaseline character label text vertical alignment
stroke_color character text color
fill_color character text fill color

See Also

ol_map, ol_geom_point

Examples

text.pts <- matrix(
    c(
        -101.5, 39.2,
        -101.1, 54,
        -101.1, 21.4
    ),
    byrow=TRUE,
    ncol=2
)
text.labels <- c("USA","Canada","Mexico")
mymap <- ol_map(
    center=c(-100,25),
    zoom=3
) +
    oceanbase() +
    ol_geom_text(
        text.pts,
        text.labels,
        toggle.control=TRUE,
        label.params=list(
            font="16px sans-serif",
            stroke_color="#FF0000",
            fill_color="#FFFFFF00"
        )
    )
## Not run: 
# Write to file and view in browser
ol_map2HTML(mymap, "textmap.html")
browseURL("textmap.html")

## End(Not run)

cemarks/ROpenLayers documentation built on March 31, 2022, 12:05 p.m.