---
title: "Web Maps"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteIndexEntry{Web Maps}
  %\VignetteEncoding{UTF-8}
---

Use the [Leaflet] map below to explore [The National Map] (TNM) base layers that
describe the landscape of the United States and its territories.
The base layers outside these areas may be unavailable at higher zoom levels.

```{r}
map <- webmap::make_map(collapse = FALSE) |>
  leaflet::setView(lng = -98.583, lat = 39.833, zoom = 3)
map
```

Read a [GeoJSON] file containing the locations of U.S. cities.

```{r}
city <- system.file("extdata/city.geojson", package = "webmap") |>
  sf::st_read(quiet = TRUE)
city
```
Create a new web map that includes only the `"Topo"` base map layer.
And add clustered marker locations to call out city locations.

```{r}
map <- webmap::make_map("Topo") |>
  leaflet::addMarkers(
    label = ~name,
    popup = ~name,
    clusterOptions = leaflet::markerClusterOptions(
      showCoverageOnHover = FALSE
    ),
    clusterId = "cluster",
    group = "marker",
    data = city
  )
map
```

Modify the existing map widget object (`map`) to place buttons on the map that adds control to
(1) toggle full screen on and off,
(2) zoom to the provided data extent,
(3) toggle marker clusters on and off, and
(4) search markers location by property.

```{r}
map <- map |>
  webmap::add_fullscreen_button(pseudo_fullscreen = TRUE) |>
  webmap::add_home_button() |>
  webmap::add_cluster_button(cluster_id = "cluster") |>
  webmap::add_search_button(
    group = "marker",
    zoom = 15,
    text_placeholder = "Search city names..."
  )
map
```

<!-- Embedded References -->

[Leaflet]: https://leafletjs.com/
[The National Map]: https://www.usgs.gov/programs/national-geospatial-program/national-map
[GeoJSON]: https://en.wikipedia.org/wiki/GeoJSON
