Package 'webmap'

Title: Create Interactive Web Maps Using 'The National Map' Services
Description: Creates interactive web maps using the 'JavaScript' 'Leaflet' library with base layers of 'The National Map' ('TNM'). 'TNM' services provide access to base geospatial information that describes the landscape of the United States and its territories. This package is dependent on, and intended to be used with, the 'leaflet' package.
Authors: Jason C. Fisher [aut, cre] , Stefano Cudini [ctb, cph] (leaflet-search library), John Firebaugh [ctb, cph] (Leaflet.fullscreen library)
Maintainer: Jason C. Fisher <[email protected]>
License: MIT + file LICENSE
Version: 1.1.0
Built: 2024-11-21 03:04:43 UTC
Source: https://github.com/cran/webmap

Help Index


Add cluster control button to a web map

Description

Add a button to a Leaflet map to toggle marker clusters on and off.

Usage

add_cluster_button(map, cluster_id, position = "topleft")

Arguments

map

'leaflet'. Map widget object

cluster_id

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

position

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

Value

A new HTML web map with added element, an object of class 'leaflet'.

Author(s)

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

See Also

make_map function for creating a map widget.

Examples

make_map(maps = "Topo") |>
  leaflet::addMarkers(
    lng = ~lng,
    lat = ~lat,
    label = ~name,
    popup = ~name,
    clusterOptions = leaflet::markerClusterOptions(
      showCoverageOnHover = FALSE
    ),
    clusterId = "cluster",
    group = "marker",
    data = us_cities
  ) |>
  add_cluster_button(cluster_id = "cluster")

Add full-screen button to a web map

Description

Add a button to a Leaflet map that toggles full screen on and off. Functionality provided by the leaflet-fullscreen plugin for Leaflet.

Usage

add_fullscreen_button(map, pseudo_fullscreen = FALSE, position = "topleft")

Arguments

map

'leaflet'. Map widget object

pseudo_fullscreen

'logical' flag. Whether to fullscreen to page width and height.

position

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

Value

A new HTML web map with added element, an object of class 'leaflet'.

Author(s)

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

See Also

make_map function for creating a map widget.

Examples

make_map(maps = "Topo") |>
  add_fullscreen_button()

Add home button to a web map

Description

Add a button to a Leaflet map that zooms to the provided map extent.

Usage

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

Arguments

map

'leaflet'. Map widget object

extent

'bbox', or 'numeric' vector of length four, with xmin, xmax, ymin and ymax values. Extent object 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 will be automatically determined from latitudes and longitudes of the map elements.

position

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

Value

A new HTML web map with added element, an object of class 'leaflet'.

Author(s)

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

See Also

make_map function for creating a map widget.

Examples

make_map(maps = "Topo") |>
  add_home_button(
    extent = c(-124.409, -114.131, 32.534, 42.009) # California
  )

Add legend to a web map

Description

Add a legend to a Leaflet map.

Usage

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

Arguments

map

'leaflet'. Map widget object

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

position

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

Value

A new HTML web map with added element, an object of class 'leaflet'.

Author(s)

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

See Also

make_map function for creating a map widget.

Examples

# define marker colors based on whether a city serves as a capital
colors <- c(
  "Non-capital" = "green",
  "Capital" = "red"
)
fill_colors <- colors[(us_cities$capital > 0) + 1L] |>
  as.character()

# print map with city circle markers and a map legend
make_map(maps = "Topo") |>
  leaflet::addCircleMarkers(
    lng = ~lng,
    lat = ~lat,
    radius = 6,
    color = "white",
    weight = 1,
    opacity = 1,
    fillColor = fill_colors,
    fillOpacity = 1,
    fill = TRUE,
    data = us_cities
  ) |>
  add_legend(
    labels = names(colors),
    colors = colors,
    radius = 5,
    opacity = 1,
    symbol = "circle"
  )

Add search button to a web map

Description

Add a button to a Leaflet map to search markers/features location by property. Functionality provided by the leaflet-search plugin for Leaflet.

Usage

add_search_button(
  map,
  group,
  property_name = "label",
  zoom = NULL,
  text_placeholder = "Search...",
  open_popup = FALSE,
  position = "topleft"
)

Arguments

map

'leaflet'. Map widget object

group

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

property_name

'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.

text_placeholder

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

open_popup

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

position

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

Value

A new HTML web map with added element, an object of class 'leaflet'.

Author(s)

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

See Also

make_map function for creating a map widget.

Examples

make_map(maps = "Topo") |>
  leaflet::addMarkers(
    lng = ~lng,
    lat = ~lat,
    label = ~name,
    popup = ~name,
    group = "marker",
    data = us_cities
  ) |>
  add_search_button(
    group = "marker",
    zoom = 15,
    text_placeholder = "Search city names..."
  )

Create a web map using TNM services

Description

Create a Leaflet map widget that includes base maps offered through The National Map (TNM) cached service endpoints. Information about the content of these base maps can be found within the TNM Base Maps document. TNM content is limited to the United States and territories. The map widget can be rendered on HTML pages generated from R Markdown, Shiny, or other applications.

Usage

make_map(
  maps,
  ...,
  protocol = c("WMTS", "WMS"),
  hydro = FALSE,
  collapse = FALSE
)

Arguments

maps

'character' vector. TNM base maps to include in the web map. Choices include "Topo", "Imagery", "Imagery Topo", "Hydrography", "Shaded Relief", and "Blank". See 'Details' section for a description of each base map. By default, all base maps are included. The one exception is the "Blank" map, which is only accessible using a Web Map Service (WMS), see protocol argument.

...

Arguments to be passed to the leaflet function.

protocol

'character' string. Standard protocol for serving pre-rendered georeferenced TNM map tiles. Select "WMTS" for the Web Map Tile Service (the default) and "WMS" for the Web Map Service.

hydro

'logical' flag. Whether to show or hide (the default) the "Hydrography" overlay base map.

collapse

'logical' flag. Whether the layers control should be rendered as an icon that expands when hovered over. Default is FALSE.

Details

Composite base maps include:

  • "Topo" a tile base map that combines the most current TNM data, and other public-domain data, into a multi-scale topographic reference map. Data includes boundaries, geographic names, transportation, contours, hydrography, land cover, shaded relief, and bathymetry.
    basemap-topo.png

  • "Imagery" is a tile base map of orthoimagery in TNM. Orthoimagery data typically are high resolution aerial images that combine the visual attributes of an aerial photograph with the spatial accuracy and reliability of a planimetric map. USGS digital orthoimage resolution may vary from 6 inches to 1 meter.
    basemap-imagery.png

  • "Imagery Topo" is a tile base map of orthoimagery in TNM as a backdrop, and a limited selection of topographic data (boundaries, names, transportation, contours, and hydrography).
    basemap-imagery-topo.png

  • "Hydrography" is a overlay of cartographic representation of the National Hydrography Dataset (NHD). The NHD is a comprehensive set of digital geospatial data that encodes information about naturally occurring and constructed bodies of surface water, paths through which water flows, related features such as stream gages and dams, and additional hydrologic information.
    basemap-hydrography.png

  • "Shaded Relief" is a tile base map of terrain representation in the form of hillshades created from the 3D Elevation Program (3DEP). 3DEP maintains a seamless dataset of best available raster elevation data, in the form of digital elevation models (DEMs) for the conterminous United States, Alaska, Hawaii, and Territorial Islands of the United States.
    basemap-shaded-relief.png

  • "OSM" is the OpenStreetMap tile base map.
    basemap-osm.png

  • "Blank" consists of ocean tints to give the outline of land cover as an empty base map.
    basemap-blank.png

Value

An object of class 'leaflet', a hypertext markup language (HTML) map widget. See example for instructions on how to add additional graphic layers (such as points, lines, and polygons) to the map widget. Graphic layers added to the web map must be in latitude and longitude using WGS 84 (also known as EPSG:4326).

Author(s)

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

Examples

# Create map widget
map <- make_map()

# Print map widget
map

# Print map with markers
pts <- rbind(
  c(-112.049, 43.517),
  c(-122.171, 37.456),
  c( -77.367, 38.947),
  c(-149.803, 61.187),
  c( -80.248, 26.080)
)
leaflet::addMarkers(map,
  lng = pts[, 1],
  lat = pts[, 2]
)

# Print map of satellite imagery with a rectangle in the vicinity of UCLA
make_map(
  maps = "Imagery",
  collapse = TRUE
) |>
  leaflet::addRectangles(
    lng1 = -118.456,
    lat1 =   34.078,
    lng2 = -118.436,
    lat2 =   34.062,
    fillColor = "transparent"
  )

US Major Cities

Description

This dataset contains the locations of cities within the United States with populations of about 40,000 or greater, all state capitals, and the national capital.

Usage

us_cities

Format

A data frame with columns:

name

City name

capital

Capital status code indicates whether a city is a capital or not. A value of 0 indicates that the city is not a capital, while a value of 1 indicates that the city is a capital. If the city is a state capital, the value is 2.

lng

Longitude in decimal degrees.

lat

Latitude in decimal degrees.

Source

The census-designated place population as of January 30, 2024, as enumerated by the 2020 United States census.

Examples

str(us_cities)