Skip to contents

This function produces an interactive view of the extent/bbox of the supplied spatial object

Usage

viewExtent(
  x,
  map = NULL,
  popup = NULL,
  layer.name = NULL,
  alpha.regions = 0.2,
  label = NULL,
  ...
)

Arguments

x

either a Raster*, sf* or Spatial* object

map

a leaflet or mapview map the extent should be added to. If NULL standard background layers are created.

popup

a list of HTML strings with the popup contents, usually created from popupTable. See addControl for details.

layer.name

the name of the layer to be shown on the map.

alpha.regions

opacity of the fills or the raster layer(s).

label

a character vector of labels to be shown on mouseover. See addControl for details.

...

Arguments passed on to leaflet::addRectangles

html

the content of the control. May be provided as string or as HTML generated with Shiny/htmltools tags

position

position of control: "topleft", "topright", "bottomleft", or "bottomright".

layerId

the layer id

className

extra CSS classes to append to the control, space separated

data

the data object from which the argument values are derived; by default, it is the data object provided to leaflet() initially, but can be overridden

urlTemplate

a character string as the URL template

attribution

the attribution text of the tile layer (HTML)

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.

options

a list of extra options for tile layers, popups, paths (circles, rectangles, polygons, ...), or other map elements

baseUrl

a base URL of the WMS service

layers

comma-separated list of WMS layers to show

lng

a numeric vector of longitudes, or a one-sided formula of the form ~x where x is a variable in data; by default (if not explicitly provided), it will be automatically inferred from data by looking for a column named lng, long, or longitude (case-insensitively)

lat

a vector of latitudes or a formula (similar to the lng argument; the names lat and latitude are used when guessing the latitude column from data)

icon

the icon(s) for markers; an icon is represented by an R list of the form list(iconUrl = "?", iconSize = c(x, y)), and you can use icons() to create multiple icons; note when you use an R list that contains images as local files, these local image files will be base64 encoded into the HTML page so the icon images will still be available even when you publish the map elsewhere

popupOptions

A Vector of popupOptions() to provide popups

labelOptions

A Vector of labelOptions() to provide label options for each label. Default NULL

clusterOptions

if not NULL, markers will be clustered using Leaflet.markercluster; you can use markerClusterOptions() to specify marker cluster options

clusterId

the id for the marker cluster layer

radius

a numeric vector of radii for the circles; it can also be a one-sided formula, in which case the radius values are derived from the data (units in meters for circles, and pixels for circle markers)

stroke

whether to draw stroke along the path (e.g., the borders of polygons or circles)

color

stroke color

weight

stroke width in pixels

opacity

stroke opacity (or layer opacity for tile layers)

fill

whether to fill the path with color (e.g., filling on polygons or circles)

fillColor

fill color

fillOpacity

fill opacity

dashArray

a string that defines the stroke dash pattern

bringToFront

Whether the shape should be brought to front on hover.

sendToBack

whether the shape should be sent to back on mouse out.

highlightOptions

Options for highlighting the shape on mouse over.

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

lng1,lat1,lng2,lat2

latitudes and longitudes of the south-west and north-east corners of rectangles

geojson

a GeoJSON list, or character vector of length 1

topojson

a TopoJSON list, or character vector of length 1

Author

Tim Appelhans

Examples

library(leaflet)

viewExtent(breweries)
viewExtent(franconia) + breweries
mapview(franconia) %>% leafem::addExtent(franconia, fillColor = "yellow")
leaflet() %>% addProviderTiles("OpenStreetMap") %>% leafem::addExtent(breweries)
leaflet() %>% addProviderTiles("OpenStreetMap") %>% leafem::addExtent(breweries)