Skip to content

Commit 8559669

Browse files
committed
...
1 parent 5d7ff97 commit 8559669

File tree

4 files changed

+83
-12
lines changed

4 files changed

+83
-12
lines changed

R/tmap_source.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ get_source_info = function(shp, start_local_host = TRUE) {
3737

3838
if (start_local_host) {
3939
port = servr::random_port()
40-
#dir = dirname(shp)
41-
# srv = servr::httr(dir = dir) # not sure why this doesn't work
4240
srv = freestiler::serve_tiles(shp, port = port)
4341
url = paste0(srv$url, "/", basename(shp))
4442
} else {

_pkgdown.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
url: https://r-tmap.github.io/tmap.sources/
2+
template:
3+
bootstrap: 5
4+
bslib:
5+
primary: "#5f8640"
6+
7+
# figures:
8+
dev: ragg::agg_png
9+
dpi: 300
10+
11+
development:
12+
version_tooltip: "tmap.sources documentation"
13+
14+
reference:
15+
16+
- title: GEt tmap source meta data
17+
contents:
18+
- tmap_source_meta()
19+
20+
navbar:
21+
structure:
22+
left: [reference, pmtiles, news]
23+
components:
24+
home: ~
25+
pmtiles:
26+
text: PMTiles
27+
href: articles/pmtiles

sandbox/test.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ NLD_dist$edu_ids = cut(NLD_dist$edu_appl_sci, breaks = c(0, 21.5, 29.5, 39.8, 51
1212
NLD_dist$edu_fill = c4a("plasma", 5)[cut(NLD_dist$edu_appl_sci, breaks = c(0, 21.5, 29.5, 39.8, 51.5, 90), include.lowest = TRUE)]
1313
NLD_dist$edu_fill[is.na(NLD_dist$edu_fill)] = c4a_na("plasma")
1414

15+
1516
freestile(
1617
NLD_dist,
1718
"NLD_dist.pmtiles",

vignettes/pmtiles.Rmd

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,72 @@ knitr::knit_hooks$set(output = function(x, options) {
3535
3636
```
3737

38-
```{r, echo = FALSE, message = FALSE}
38+
39+
40+
## Introduction
41+
42+
Until version 4.3, it was only possible to visualize spatial data stored in memory with `tmap`, e.g. objects from the class packages `sf`, `terra`, or `stars`. This package, `tmap.sources` makes it possible to visualize remote spatial data. Currently only `PMTiles`, a remote tile-based data sources are supported, but support for other remote data sources will be added later.
43+
44+
To run `tmap.sources`, besides `tmap`, another package is required, namely [`tmap.mapgl`](https://r-tmap.github.io/tmap.mapgl/articles/mapgl), because we require the tmap mode `"maplibre"`:
45+
46+
47+
```{r}
3948
library(tmap)
4049
library(tmap.mapgl)
4150
library(tmap.sources)
51+
tmap_mode("maplibre")
4252
```
4353

54+
## Remote PMTiles file
4455

45-
## Mode maplibre
46-
47-
Currently, the only mode that supports pmtiles is `maplibre`:
56+
OvertureMaps contain a few very large PMTiles. The following is one with the [buildings](https://docs.overturemaps.org/guides/buildings/), across the World.
4857

4958

50-
```{r}
51-
tmap_mode("maplibre")
59+
```{r, fig.height = 3.5}
60+
tm_shape(
61+
"https://overturemaps-tiles-us-west-2-beta.s3.amazonaws.com/2026-01-21/buildings.pmtiles",
62+
bbox = "Amsterdam") +
63+
tm_polygons(fill = "#ee7700") +
64+
tm_maplibre(zoom = 14)
5265
```
5366

54-
OvertureMaps contain a few very large pmtiles; one with all the [buildings](https://docs.overturemaps.org/guides/buildings/):
5567

68+
We can also use a categorical color palette:
5669

5770
```{r, fig.height = 3.5}
58-
tm_shape("https://overturemaps-tiles-us-west-2-beta.s3.amazonaws.com/2024-07-22/buildings.pmtiles", bbox = "Amsterdam") +
59-
tm_polygons(fill = "#ee7700") +
60-
tm_maplibre(zoom = 14)
71+
library(tmap)
72+
library(tmap.sources)
73+
74+
# Define the mapping
75+
building_subtypes <- data.frame(
76+
level = c("residential", "commercial", "industrial", "educational",
77+
"civic", "religious", "medical", "transportation",
78+
"entertainment", "agricultural", "military", "outbuilding",
79+
"service"),
80+
color = c("#f4a460", "#4169e1", "#708090", "#ffd700",
81+
"#dc143c", "#9370db", "#ff6347", "#20b2aa",
82+
"#ff69b4", "#6b8e23", "#556b2f", "#d2b48c",
83+
"#87ceeb"),
84+
label = c("Residential", "Commercial", "Industrial", "Educational",
85+
"Civic", "Religious", "Medical", "Transportation",
86+
"Entertainment", "Agricultural", "Military", "Outbuilding",
87+
"Service")
88+
)
89+
90+
tm_shape(
91+
"https://overturemaps-tiles-us-west-2-beta.s3.amazonaws.com/2026-01-21/buildings.pmtiles",
92+
bbox = "Amsterdam") +
93+
tm_polygons(
94+
fill = "subtype",
95+
fill.scale = tm_scale_categorical(
96+
levels = building_subtypes$level,
97+
values = building_subtypes$color,
98+
labels = building_subtypes$label,
99+
value.na = "#cccccc",
100+
label.na = "Unknown"
101+
),
102+
fill.legend = tm_legend("Building type")
103+
) +
104+
tm_maplibre(zoom = 14)
61105
```
106+

0 commit comments

Comments
 (0)