ol_geom_polygon: OpenLayers Polygon Layer

View source: R/layer_polygon.R

ol_geom_polygonR Documentation

OpenLayers Polygon Layer

Description

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

Usage

ol_geom_polygon(polygon.obj, mapping = ol_aes(), name = NULL,
  df = NULL, toggle.control = FALSE, fill = "#00FF00",
  fill.opacity = 0.5, lwd = 1, ol.lty = list(), color = "#000000",
  label = NULL, label.params = list(), tooltip = NULL,
  tooltip.params = list())

Arguments

polygon.obj

SpatialPolygonsDataFrame, SpatialPolygons, list of polygon-like objects, or a two-column matrix of longitude-latitude coordinates to be used as ordered polygon vertices.

mapping

list created by ol_aes.

name

character Layer name.

df

data.frame with same number of polygon objects as polygon.obj. Used for aestheic mapping. Defaults to polygon.obj@data if class(polygon.obj)==SpatialPolygonsDataFrame) and df is not provided.

toggle.control

logical indicating whether this layer will have a visibility toggle.

fill

character color string, or vector of color strings. Used only if no fill aesthetic is provided in mapping

fill.opacity

numeric in [0,1]. Controls circle opacity if no opacity provided in fill or fill aesthetic.

lwd

numeric polygon border width. Used only if no lwd aesthetic is provided in mapping

ol.lty

(experimental) numeric vector with length > 1, or list of such vectors. Used only if no ol.lty aesthetic is provided in mapping. See OpenLayers ol/style/Stroke Documentation, 'lineDash' property for more information.

color

character border color string, or vector of color strings. Used only if no color aesthetic is provided in mapping

label

character vector of polygon feature labels.

label.params

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

tooltip

character vector polygon feature tooltip popups.

tooltip.params

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

Details

This function creates a list object containing the data required to generate an OpenLayers vector layer with features using MultiPolygon. See OpenLayers MultiPolygon Documentation for details.

Value

A list object of class Layer.SpatialPolygon.

Aesthetics

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

Formatting Tooltips With label.params

The tooltip.params parameter enable the user to control tooltip formats. Unlike the label.params, not all tooltip.params are embedded in Openlayers javascript objects; some are translated to corresponding CSS properties. The table below provides a list of supported properties and their descriptions. OpenLayers Overlay Documentation provides additional information about Overlay Properties.

font character tootltip CSS font
offsetX numeric OpenLayers Overlay x-offset
offsetY numeric OpenLayers Overlay y-offset
positioning character OpenLayers Overlay positioning string
stroke_color character Tooltip CSS font-color
fill_color character Tooltip CSS background-color
padding, character Tooltip CSS padding
border, character Tooltip CSS border
borderradius character Tooltip CSS border-radius

See Also

ol_aes, ol_map, ol_geom_point, ol_geom_line, ol_geom_circle

Examples

polygon.matrix1 <- matrix(
    c(
        -80.385+c(0,0.05,0.05,0,0),
        25.782618+c(0,0,0.05,0.05,0)
    ),
    ncol=2
)
polygon.matrix2 <- matrix(
    c(
        -80.34+c(0,0.05,0.025,0),
        25.73++c(0,0,0.025*sqrt(3),0)
    ),
    ncol=2
)
polygon.list<-list(polygon.matrix1,polygon.matrix2)
polygon.df <- data.frame(shape=c("rectangle","triangle"),no=c(1,2))
miami.OSM.basemap <- ol_map(
    center=c(-80.385790,25.782618),
    zoom=9
    ) + 
   streetmap() 
polygon.layer <- ol_geom_polygon(
    polygon.list,
    mapping=ol_aes(
        fill=shape,
    ),
    df=polygon.df,
    lwd=1,
    name="Miami Polygons",
    toggle.control=TRUE,
    tooltip=polygon.df$no
)
polygon.fill.scale <- ol_scale_fill_discrete(display=TRUE)
polygons.over.miami <- miami.OSM.basemap + 
    polygon.layer + 
    polygon.fill.scale

## Not run: 
# Output to file and view
ol_map2HTML(
  polygons.over.miami,
  'miami_polygons.html',
  map.heading="Miami Shapes",
  map.note="Note: Mouseover popup values are 
    independent of shape size &amp; color."
)
browseURL("miami_polygons.html")

## End(Not run)

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