Created
February 3, 2024 11:23
-
-
Save tordans/174be0b9f4037f7611aa945c5f73536d to your computer and use it in GitHub Desktop.
Maplibre GL JS number formatting snipped
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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