AddWebMapElements: Add Elements to Web Map

AddWebMapElementsR Documentation

Add Elements to Web Map

Description

Augment a Leaflet web map with additional elements. The AddHomeButton function adds a button that zooms to the initial map extent. The AddClusterButton function adds a button that toggles marker clusters on and off. The AddSearchButton function adds a control that may be used to search markers/features location by property. And the AddCircleLegend function adds a map legend.

Usage

AddHomeButton(map, extent = NULL, position = "topleft")

AddClusterButton(map, clusterId, position = "topleft")

AddSearchButton(
  map,
  group,
  propertyName = "label",
  zoom = NULL,
  textPlaceholder = "Search...",
  openPopup = FALSE,
  position = "topleft"
)

AddLegend(
  map,
  labels,
  colors,
  radius,
  opacity = 0.5,
  symbol = c("square", "circle"),
  title = "EXPLANATION",
  position = "topright"
)

Arguments

map

'leaflet'. Map widget object

extent

'Spatial*', 'Raster*', 'Extent', 'matrix', or 'numeric' vector. Extent object (or object from which an raster::extent object can be extracted/created) representing a rectangular geographical area on the map. The extent must be specified in the coordinate reference system (CRS) of the web map, usually in latitude and longitude using WGS 84 (also known as EPSG:4326). By default, the extent object is read from the map widget.

position

'character' string. Position of the button on the web map. Possible values are "topleft", "topright", "bottomleft", and "bottomright".

clusterId

'character' string. Identification for the marker cluster layer.

group

'character' string. Name of the group whose features will be searched.

propertyName

'character' string. Property name used to describe markers, such as, "label" and "popup".

zoom

'integer' count. Zoom level for move to location after marker found in search.

textPlaceholder

'character' string. Message to show in search element.

openPopup

'logical' flag. Whether to open the marker popup associated with the searched for marker.

labels

'character' vector. Labels in the legend.

colors

'character' vector. HTML colors corresponding to labels.

radius

'numeric' number. Border radius of symbols in the legend, in pixels.

opacity

'numeric' number. Opacity of symbols in the legend, from 0 to 1.

symbol

'character' string. Symbol type in the legend, either "square" or "circle".

title

'character' string. Legend title

Value

An object of class 'leaflet'. A new map object with added element.

Author(s)

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center

See Also

CreateWebMap

Examples

city <- rgdal::readOGR(system.file("extdata/city.geojson",
                       package = "inlmisc")[1])
opt <- leaflet::markerClusterOptions(showCoverageOnHover = FALSE)
map <- CreateWebMap("Topo")
map <- leaflet::addMarkers(map, label = ~name, popup = ~name,
                           clusterOptions = opt,
                           clusterId = "cluster",
                           group = "marker", data = city)
map <- AddHomeButton(map)
map <- AddClusterButton(map, clusterId = "cluster")
map <- AddSearchButton(map, group = "marker", zoom = 15,
                       textPlaceholder = "Search city names...")
map

labels <- c("Non-capital", "Capital")
colors <- c("green", "red")
fillColor <- colors[(city@data$capital > 0) + 1]
map <- CreateWebMap("Topo")
map <- leaflet::addCircleMarkers(map, radius = 6, color = "white",
                                 weight = 1, opacity = 1,
                                 fillColor = fillColor,
                                 fillOpacity = 1, fill = TRUE,
                                 data = city)
map <- AddLegend(map, labels = labels, colors = colors, radius = 5,
                 opacity = 1, symbol = "circle")
map


USGS-R/inlmisc documentation built on Sept. 17, 2022, 2:38 a.m.