Skip to content

Instantly share code, notes, and snippets.

@tordans
Created February 3, 2024 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tordans/174be0b9f4037f7611aa945c5f73536d to your computer and use it in GitHub Desktop.
Save tordans/174be0b9f4037f7611aa945c5f73536d to your computer and use it in GitHub Desktop.
Maplibre GL JS number formatting snipped
// Source https://osmus.slack.com/archives/C01G3D28DAB/p1706567778474359?thread_ts=1706534773.353969&cid=C01G3D28DAB
"text-field": [
"let",
"thousands",
["floor", ["/", ["get", "length_m"], 1000]],
[
"let",
"reminder",
[
"to-string",
["-", ["get", "length_m"], ["*", ["var", "thousands"], 1000]]
],
[
"let",
"part1",
[
"concat",
["slice", "000", ["length", ["var", "reminder"]]],
["var", "reminder"]
],
[
"case",
[">", ["var", "thousands"], 0],
[
"concat",
["var", "thousands"],
",",
["var", "part1"],
" km"
],
["concat", ["var", "reminder"], " km"]
]
]
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment