Question Details

No question body available.

Tags

r leaflet

Answers (1)

July 28, 2026 Score: 5 Rep: 8,988 Quality: Medium Completeness: 80%

The reason addTiles() and addProviderTiles() don't (and won't) work is because they handle image tiles (e.g. .png), and OpenFreeMap hosts vector tiles. To illustrate, note the geometry types in the following:

library(sf)

download.file( "tiles.openfreemap.org/planet/20260621080001pt/9/277/167.pbf", destfile = "sample.pbf", mode = "wb" )

stlayers("sample.pbf")

Driver: MVT

Available layers:

layername geometrytype features fields crsname

1 boundary Multi Line String 2 4

2 landcover Multi Polygon 814 3

3 landuse Multi Polygon 4 2

4 mountainpeak Point 40 11

5 park 47 34

6 place Point 289 80

7 transportation Multi Line String 17 7

8 transportationname Multi Line String 3 22

9 water Polygon 73 4

10 watername Line String 2 27

11 waterway Multi Line String 17 12

To render vector tiles in leaflet, the OpenFreeMap Quick Start Guide: Using Leaflet section shows the dependencies required to do this. It uses MapLibre GL JS in the background. You will need both the htmltools and htmlwidgets packages to inject these dependencies into your leaflet map:

library(leaflet)
library(htmltools)
library(htmlwidgets)

Load CSS and JS dependencies (from Leaflet section in docs) via htmltools

mltags % setView(lng = 174.76, lat = -36.85, zoom = 12) %>% prependContent(mltags) %>% onRender(" function(el, x) { var map = this;

L.maplibreGL({ style: 'https://tiles.openfreemap.org/styles/bright' }).addTo(map);

} ")

The "bright" map style is hardcoded here, but you can replace that with "positron", "liberty", "dark", or "fiord" e.g.

'https://tiles.openfreemap.org/styles/liberty'

Note that the "3D" style is not available.

An alternative is to use the mapgl package, which accesses MapLibre GL JS dependencies without explicitly needing to declare them:

# install.packages("mapgl")

library(mapgl)

maplibre( style = openfreemap_style("bright"), center = c(174.76, -36.85), zoom = 12 )