-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathREADME.Rmd
143 lines (96 loc) · 4.06 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
[leaflet]: https://rstudio.github.io/leaflet/
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# leaflet.providers
<!-- badges: start -->
[](https://CRAN.R-project.org/package=leaflet.providers)
[](https://github.com/rstudio/leaflet.providers/actions)
[](https://app.codecov.io/gh/rstudio/leaflet.providers?branch=main)
<!-- badges: end -->
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](https://github.com/leaflet-extras/leaflet-providers).
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](https://github.com/leaflet-extras/leaflet-providers) 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.
## Installation
You can install the released version of `leaflet.providers` from [CRAN](https://CRAN.R-project.org):
``` {r craninstall, eval = FALSE}
# CRAN version
install.packages("leaflet.providers")
```
And the development version from [GitHub](https://github.com/) with:
``` {r pakinstall, eval = FALSE}
pak::pak("rstudio/leaflet.providers")
```
## Example
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.
### Usage
In general, you do not need to load or interact with `leaflet.providers` directly.
Instead, `leaflet.providers` is used indirectly by the [leaflet package][leaflet] in the `leaflet::addProviderTiles()` function.
``` r
library(leaflet)
leaflet() |>
setView(lng = -71.0589, lat = 42.3601, zoom = 12) |>
addTiles() |>
addProviderTiles("OpenTopoMap")
```
### Fetch custom providers
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:
``` r
# 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`][leaflet] will use the custom
providers instead of the default provider data.
> Note that the package `V8` is required for `get_providers()`.
### Default providers
```{r providersdefault, eval = FALSE}
library(leaflet.providers)
str(providers_default(), max.level = 2)
```
<div style = "height:150px; overflow-y: scroll;">
```{r providersdefault1, echo = FALSE}
library(leaflet.providers)
str(providers_default(), max.level = 2)
```
</div>
### View the loaded providers data
#### The version number of the source leaflet-providers.js
```{r example0}
providers_loaded()$version_num
```
#### Supported tile providers
```{r examplept1, eval = FALSE}
names(providers_loaded()$providers)
```
<div style = "height:150px; overflow-y: scroll;">
```{r examplept2, echo=FALSE}
names(providers_loaded()$providers)
```
</div>
#### Tile providers' details
```{r example2pt1, eval = FALSE}
str(providers_loaded()$providers_details)
```
<div style = "height:150px; overflow-y: scroll;">
```{r example2pt2, echo=FALSE}
str(providers_loaded()$providers_details, list.len = 200)
```
</div>