Learn R Programming

inlmisc (version 0.4.3)

AddWebMapElements: Add Miscellaneous Web Map Elements

Description

These functions can be used to 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 search element that may be used to locate, and move to, a marker. 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'. Extent object (or object from which an 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'. Position of the button on the web map. Possible values are "topleft", "topright", "bottomleft", and "bottomright".

clusterId

'character'. Identification for the marker cluster layer.

group

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

propertyName

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

zoom

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

textPlaceholder

'character'. Text message to show in search element.

openPopup

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

labels

'character'. Vector of text labels in the legend.

colors

'character'. Vector of (HTML) colors corresponding to labels.

radius

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

opacity

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

symbol

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

title

'character'. Legend title

Value

Used for the side-effect of a button placed on a web map.

See Also

CreateWebMap

Examples

Run this code
# NOT RUN {
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) + 1L]
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

# }

Run the code above in your browser using DataLab