View source: R/layer_polygon.R
ol_geom_polygon | R Documentation |
Function to create a polygon layer to add to an OpenLayers Map object.
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())
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 |
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.opacity |
numeric in [0,1]. Controls circle opacity if
no opacity provided in |
lwd |
numeric polygon border width. Used only if no |
ol.lty |
(experimental) numeric vector with length > 1, or
|
color |
character border color string, or vector of color strings. Used
only if no |
label |
character vector of polygon feature labels. |
label.params |
named list (e.g., |
tooltip |
character vector polygon feature tooltip popups. |
tooltip.params |
named list (e.g., |
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.
A list object of class Layer.SpatialPolygon
.
fill
color
lwd
ol_lty
(experimental; See OpenLayers
ol/style/Stroke Documentation,
'lineDash' property for more information.)
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 |
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 |
ol_aes
, ol_map
, ol_geom_point
,
ol_geom_line
, ol_geom_circle
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 & color." ) browseURL("miami_polygons.html") ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.