Skip to contents

The MapLibre style-spec layers the engine emits for a geopic FeatureCollection (geopic-core's maplibre module; the engine's docs/geopic.md § 6): the same six layers the rpic.dev Maps page, the JavaScript and Python bindings and rpic --geojson --maplibre draw with, so a drawing looks the same on every map. In draw order: pic-fill (polygon fills), pic-stroke and pic-stroke-dashed (outlines and lines), pic-dot (dots), pic-text (text) and pic-title (shape titles). Every layer reads one GeoJSON source named "pic" and styles each feature from its simplestyle and geopic:* properties.

Usage

rpic_maplibre_layers(x, ..., text_scale = 1)

Arguments

x

the drawing: the result of rpic_geojson() (or any GeoJSON FeatureCollection text: a string of class "json", or one whose first non-blank character is an opening brace or bracket — so pic source that opens with a brace group needs a statement or comment before it), an sf data frame from rpic_sf() (its "geojson" attribute, the engine's own text, is used — not its rows, so an sf that has lost rows since is an error and edited columns are not seen), or pic source — a pic() object or a string — which is georeferenced with rpic_geojson(x, ...).

...

arguments passed to rpic_geojson() when x is pic source.

text_scale

multiplies every label's font size (pic-text and pic-title): a finite number in (0, 16]. The default, 1, keeps the labels true to the ground; 1.5 draws them half as large again, so they stay legible further out. Strokes and dots keep their ground sizes. The scale is applied inside the engine's sizing (LayerOptions, the engine's DECISIONS G11), so the upper text-size zoom stop still keeps labels within MapLibre's 255 px limit — the same output as rpic --geojson --maplibre --text-scale.

Value

a list of six layer specs, each a named list with id, type, source ("pic"), filter, paint and (for some) layout, in draw order. JSON arrays are atomic vectors when they hold two or more numbers or strings and lists otherwise (so ["zoom"] is list("zoom")): jsonlite::toJSON(layers, auto_unbox = TRUE) — what htmlwidgets does — writes the engine's JSON back.

Details

Every size — stroke width, dot radius, font size — is true to the ground: the collection's registration gives metres per inch, so a 1-inch-wide label covers the same ground at every zoom (an exponential interpolation over zoom, base 2).

The layers read the feature properties under their GeoJSON names (stroke-width, geopic:kind, ...), so the source they draw must be the engine's GeoJSON, not a re-serialised sf data frame (whose columns are geopic_kind, ...: rpic_sf_names()). add_rpic() takes care of that.

Errors

A JSON text that is not a FeatureCollection raises an rpic_geo_error with e$info$kind == "invalid_geojson"; a text_scale that is not a single number in (0, 16] one with e$info$kind == "invalid_options".

See also

Examples

layers <- pic('geo_lon = -34.8711; geo_lat = -8.0631
geo_scale = 1000
circle rad 2 at (0, 0)
"Recife" at (0, 0)') |>
  rpic_maplibre_layers()
vapply(layers, function(l) l$id, "")
#> [1] "pic-fill"          "pic-stroke"        "pic-stroke-dashed"
#> [4] "pic-dot"           "pic-text"          "pic-title"        
layers[[2]]$paint$`line-width`[1:3]   # "interpolate", exponential 2, zoom
#> [[1]]
#> [1] "interpolate"
#> 
#> [[2]]
#> [[2]][[1]]
#> [1] "exponential"
#> 
#> [[2]][[2]]
#> [1] 2
#> 
#> 
#> [[3]]
#> [[3]][[1]]
#> [1] "zoom"
#> 
#> 

# larger labels: the text-size factor of pic-text grows by 1.5
big <- rpic_maplibre_layers('geo_lon = -34.8711; geo_lat = -8.0631
geo_scale = 1000
"Recife" at (0, 0)', text_scale = 1.5)