-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyles.R
97 lines (87 loc) · 2.56 KB
/
styles.R
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
#' Basemap Styles
#' @param theme Theme name for **CARTO** and **Stamen** basemaps
#' @return URL to a TileJSON style file or parameterized raster tiles URL
#' @export
#' @rdname styles
carto <- function(theme = c("dark-matter", "voyager", "positron")) {
theme <- match.arg(theme)
# Attribution is within the style data
sprintf(
"https://basemaps.cartocdn.com/gl/%s-gl-style/style.json",
theme
)
}
#' @export
#' @rdname styles
stamen <- function(theme = c("watercolor", "terrain", "toner")) {
theme <- match.arg(theme)
x <- structure(
sprintf(
"https://stamen-tiles-%s.a.ssl.fastly.net/%s/{z}/{x}/{y}.png",
letters[1:4],
theme
),
attribution = ifelse(
theme == "watercolor",
.stamen_attr$watercolor,
.stamen_attr$default
)
)
.raster_to_style("stamen", x)
}
#' @export
#' @rdname styles
openstreetmap <- function() {
x <- structure(
sprintf(
"https://%s.tile.openstreetmap.org/{z}/{x}/{y}.png",
letters[1:3]
),
attribution = paste0(
"\u00a9 ",
'<a href="https://www.openstreetmap.org/copyright">',
"OpenStreetMap",
"</a>",
" contributors"
)
)
.raster_to_style("osm", x)
}
#' @keywords internal
.raster_to_style <- function(layer_id, tiles) {
src <- list(
type = "raster",
tiles = as.vector(tiles),
tileSize = 256,
attribution = attributes(tiles)$attribution
)
lyr <- list(
id = layer_id,
type = "raster",
source = "raster-tiles",
minzoom = 0,
maxzoom = 22
)
list(
version = 8,
sources = list("raster-tiles" = src),
layers = list(lyr)
)
}
# nolint start
#' @keywords internal
.stamen_attr <- list(
default = paste(
'Map tiles by <a href="http://stamen.com">Stamen Design</a>,',
'under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>.',
'Data by <a href="http://openstreetmap.org">OpenStreetMap</a>,',
'under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.'
),
watercolor = paste(
'Map tiles by <a href="http://stamen.com">Stamen Design</a>,',
'under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>.',
'Data by <a href="http://openstreetmap.org">OpenStreetMap</a>,',
'under <a href="http://creativecommons.org/licenses/by/3.0">CC BY SA</a>.'
)
)
# nolint end