knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of leaflet.providers
is to provide regularly updated data on the third-party tile providers supported by leaflet
. The data is extracted from leaflet-providers.js.
While leaflet.providers
will be regularly released with updated providers data, the package comes with functions use_providers()
and get_providers()
, which enable users to fetch up-to-date providers information directly from leaflet-providers.js between package updates and to load this providers data in leaflet
. Users may also fetch older versions of the providers data with the leaflet-providers.js
version number.
You can install the released version of leaflet.providers
from CRAN:
``` {r craninstall, eval = FALSE}
install.packages("leaflet.providers")
And the development version from [GitHub](https://github.com/) with: ``` {r pakinstall, eval = FALSE} pak::pak("rstudio/leaflet.providers")
The following are basic example of the default providers data that comes leaflet.providers
as well as the available methods to fetch and load custom providers.
In general, you do not need to load or interact with leaflet.providers
directly.
Instead, leaflet.providers
is used indirectly by the leaflet package in the leaflet::addProviderTiles()
function.
library(leaflet) leaflet() |> setView(lng = -71.0589, lat = 42.3601, zoom = 12) |> addTiles() |> addProviderTiles("OpenTopoMap")
You can choose a specific version of leaflet-providers.js
by calling use_providers()
with the desired version or the providers from a desired version:
# Shorthand method: use_providers("1.7.0") # Longer method: # 1. Retrieve v 1.7.0 providers_170 <- get_providers("1.7.0") # 2. Load custom providers data use_providers(providers_170) # Reset loaded providers to default providers use_providers()
Now that use_providers()
has been called with a custom
leaflet.providers
object obtained via get_providers()
(in this case,
a previous version of the data),
leaflet
will use the custom
providers instead of the default provider data.
Note that the package
V8
is required forget_providers()
.
library(leaflet.providers) str(providers_default(), max.level = 2)
providers_loaded()$version_num
names(providers_loaded()$providers)
str(providers_loaded()$providers_details)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.