Skip to content

bernsteining/mercator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mercator

Mercator is a typst plugin to render GeoJSON as SVG in typst.

build locally

cargo build --target wasm32-unknown-unknown --release 
wasm-opt -O4 --enable-bulk-memory --strip-debug \
target/wasm32-unknown-unknown/release/mercator.wasm -o mercator/mercator.wasm
cp -r mercator/* ~/.local/share/typst/packages/local/mercator/0.1.1/

usage

#import "@preview/mercator:0.1.1"

// inline

#let config = json.encode((
  "stroke": "black",
  "stroke_width": 0.02,
  "fill": "green",
  "fill_opacity": 0.5,
  "viewbox": array((10.0, -70.0, 5.0, 5.0))))

#show raw.where(lang: "geojson"): it => mercator.render-map(it.text, config, width: 400pt)

```geojson
<GeoJSON string>
```

// from file

#let france = read(
  "departements_fr.json",
  encoding: "utf8",
)

#let config3 = json.encode((
  "stroke": "red",
  "stroke_width": 0.005,
  "fill": "white",
  "fill_opacity": 0.5,
  "viewbox": array((-5.0, -54.0, 15.0, 14.6))))

#figure(mercator.render-map(france, config3, width:550pt, height: 400pt), caption: "Départements français")

example

typst compile mercator/example/example.typ

french map

Check the source of example.typ & the result example.pdf.

optimization benchmarks:

  • normal: typst compile mercator/examples/france/all_france.typ 675.27s user 1.92s system 104% cpu 10:46.13 total
  • basic opti with wasm-opt: typst compile mercator/examples/france/all_france.typ 653.37s user 1.41s system 105% cpu 10:19.52 total
  • rust side opti (2) + wasm-opt: typst compile mercator/examples/france/all_france.typ 538.37s user 1.76s system 106% cpu 8:25.55 total
  • rust (3) + wasm-opt: typst compile mercator/examples/france/all_france.typ 503.80s user 1.48s system 107% cpu 7:48.93 total

About

🌎 Render GeoJSON in Typst documents.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published