Skip to content

Commit 73b03f6

Browse files
authored
fix(ui): fix formatting of speed and cost (#412)
1 parent ef2e01c commit 73b03f6

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

debug/index.html

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727
<div style="color: white;">km/h:</div><div style="background: #5e4fa2">0-10</div><div style="background: #3288bd">10-20</div><div style="background: #66c2a5">20-30</div><div style="background: #abdda4">30-40</div><div style="background: #e6f598">40-50</div><div style="background: #fee08b">50-60</div><div style="background: #fdae61">60-70</div><div style="background: #f46d43">70-80</div><div style="background: #d53e4f">80-90</div><div style="background: #9e0142">90+</div>
2828
</div>
2929
<script>
30+
function numberFieldText(fieldName, suffix) {
31+
return [
32+
"concat",
33+
[
34+
"number-format",
35+
["get", fieldName],
36+
{
37+
"min-fraction-digits": 0,
38+
"max-fraction-digits": 2
39+
}
40+
],
41+
suffix || ""
42+
];
43+
}
44+
3045
var simple = {
3146
"version": 8,
3247
"name": "OSRM debug",
@@ -893,7 +908,7 @@
893908
"text-rotation-alignment": "map",
894909
"text-anchor": "center",
895910
"text-keep-upright": false,
896-
"text-field": "{speed} km/h ➜"
911+
"text-field": numberFieldText("speed", " km/h ➜")
897912
},
898913
"metadata": {},
899914
"filter": [
@@ -916,7 +931,7 @@
916931
{
917932
"id": "osrm-0", "type": "symbol", "source": "osrm", "source-layer": "turns",
918933
"layout": { "icon-image": "0", "icon-offset": {stops: [[15,[10,0]],[18,[20,0]]]}, "icon-allow-overlap": true, "icon-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] },
919-
"text-field": "{cost}", "text-offset": {"base": 1, stops: [[15,[0.2,0.0]],[18,[3,0]]]}, "text-allow-overlap": true, "text-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] } ,
934+
"text-field": numberFieldText("cost"), "text-offset": {"base": 1, stops: [[15,[0.2,0.0]],[18,[3,0]]]}, "text-allow-overlap": true, "text-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] } ,
920935
"text-size": { "base": 1, "stops": [ [ 10, 8 ], [ 18, 11 ] ] }, "text-font": ["Noto Sans Bold"], "symbol-avoid-edges": false},
921936
"paint": { "icon-color" : "#ffffff", "icon-halo-color" : "#ffffff", "icon-halo-width" : 2,
922937
"text-color": "hsl(0, 0%, 100%)", "text-halo-width": 1, "text-halo-color": "hsl(0, 0%, 0%)", "text-halo-blur": 0},
@@ -925,7 +940,7 @@
925940
{
926941
"id": "osrm-45", "type": "symbol", "source": "osrm", "source-layer": "turns",
927942
"layout": { "icon-image": "45", "icon-offset": {stops: [[15,[15,15]],[18,[30,30]]]}, "icon-allow-overlap": true, "icon-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] },
928-
"text-field": "{cost}", "text-offset": {"base": 1, stops: [[15,[0.2,0.2]],[18,[3,3]]]}, "text-allow-overlap": true, "text-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] } ,
943+
"text-field": numberFieldText("cost"), "text-offset": {"base": 1, stops: [[15,[0.2,0.2]],[18,[3,3]]]}, "text-allow-overlap": true, "text-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] } ,
929944
"text-size": { "base": 1, "stops": [ [ 10, 8 ], [ 18, 11 ] ] }, "text-font": ["Noto Sans Bold"], "symbol-avoid-edges": false},
930945
"paint": { "icon-color" : "#ffffff", "icon-halo-color" : "#ffffff", "icon-halo-width" : 2,
931946
"text-color": "hsl(0, 0%, 100%)", "text-halo-width": 1, "text-halo-color": "hsl(0, 0%, 0%)", "text-halo-blur": 0},
@@ -934,7 +949,7 @@
934949
{
935950
"id": "osrm-90", "type": "symbol", "source": "osrm", "source-layer": "turns",
936951
"layout": { "icon-image": "90", "icon-offset": {stops: [[15,[15,15]],[18,[30,30]]]}, "icon-allow-overlap": true, "icon-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] },
937-
"text-field": "{cost}", "text-offset": {"base": 1, stops: [[15,[0.2,0.2]],[18,[3,3]]]}, "text-allow-overlap": true, "text-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] } ,
952+
"text-field": numberFieldText("cost"), "text-offset": {"base": 1, stops: [[15,[0.2,0.2]],[18,[3,3]]]}, "text-allow-overlap": true, "text-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] } ,
938953
"text-size": { "base": 1, "stops": [ [ 10, 8 ], [ 18, 11 ] ] }, "text-font": ["Noto Sans Bold"], "symbol-avoid-edges": false},
939954
"paint": { "icon-color" : "#ffffff", "icon-halo-color" : "#ffffff", "icon-halo-width" : 2,
940955
"text-color": "hsl(0, 0%, 100%)", "text-halo-width": 1, "text-halo-color": "hsl(0, 0%, 0%)", "text-halo-blur": 0},
@@ -943,7 +958,7 @@
943958
{
944959
"id": "osrm-135", "type": "symbol", "source": "osrm", "source-layer": "turns",
945960
"layout": { "icon-image": "135", "icon-offset": {stops: [[15,[15,15]],[18,[30,30]]]}, "icon-allow-overlap": true, "icon-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] },
946-
"text-field": "{cost}", "text-offset": {"base": 1, stops: [[15,[0.2,0.2]],[18,[3,3]]]}, "text-allow-overlap": true, "text-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] } ,
961+
"text-field": numberFieldText("cost"), "text-offset": {"base": 1, stops: [[15,[0.2,0.2]],[18,[3,3]]]}, "text-allow-overlap": true, "text-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] } ,
947962
"text-size": { "base": 1, "stops": [ [ 10, 8 ], [ 18, 11 ] ] }, "text-font": ["Noto Sans Bold"], "symbol-avoid-edges": false},
948963
"paint": { "icon-color" : "#ffffff", "icon-halo-color" : "#ffffff", "icon-halo-width" : 2,
949964
"text-color": "hsl(0, 0%, 100%)", "text-halo-width": 1, "text-halo-color": "hsl(0, 0%, 0%)", "text-halo-blur": 0},
@@ -952,7 +967,7 @@
952967
{
953968
"id": "osrm-n45", "type": "symbol", "source": "osrm", "source-layer": "turns",
954969
"layout": { "icon-image": "n45", "icon-offset": {stops: [[15,[15,30]],[18,[30,60]]]}, "icon-allow-overlap": true, "icon-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] },
955-
"text-field": "{cost}", "text-offset": {"base": 1, stops: [[15,[0.15,0.4]],[18,[2.5,6]]]}, "text-allow-overlap": true, "text-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] } ,
970+
"text-field": numberFieldText("cost"), "text-offset": {"base": 1, stops: [[15,[0.15,0.4]],[18,[2.5,6]]]}, "text-allow-overlap": true, "text-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] } ,
956971
"text-size": { "base": 1, "stops": [ [ 10, 8 ], [ 18, 11 ] ] }, "text-font": ["Noto Sans Bold"], "symbol-avoid-edges": false},
957972
"paint": { "icon-color" : "#ffffff", "icon-halo-color" : "#ffffff", "icon-halo-width" : 2,
958973
"text-color": "hsl(0, 0%, 100%)", "text-halo-width": 1, "text-halo-color": "hsl(0, 0%, 0%)", "text-halo-blur": 0},
@@ -961,7 +976,7 @@
961976
{
962977
"id": "osrm-n90", "type": "symbol", "source": "osrm", "source-layer": "turns",
963978
"layout": { "icon-image": "n90", "icon-offset": {stops: [[15,[15,30]],[18,[30,60]]]}, "icon-allow-overlap": true, "icon-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] },
964-
"text-field": "{cost}", "text-offset": {"base": 1, stops: [[15,[0.15,0.4]],[18,[2.5,6]]]}, "text-allow-overlap": true, "text-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] } ,
979+
"text-field": numberFieldText("cost"), "text-offset": {"base": 1, stops: [[15,[0.15,0.4]],[18,[2.5,6]]]}, "text-allow-overlap": true, "text-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] } ,
965980
"text-size": { "base": 1, "stops": [ [ 10, 8 ], [ 18, 11 ] ] }, "text-font": ["Noto Sans Bold"], "symbol-avoid-edges": false},
966981
"paint": { "icon-color" : "#ffffff", "icon-halo-color" : "#ffffff", "icon-halo-width" : 2,
967982
"text-color": "hsl(0, 0%, 100%)", "text-halo-width": 1, "text-halo-color": "hsl(0, 0%, 0%)", "text-halo-blur": 0},
@@ -970,7 +985,7 @@
970985
{
971986
"id": "osrm-n135", "type": "symbol", "source": "osrm", "source-layer": "turns",
972987
"layout": { "icon-image": "n135", "icon-offset": {stops: [[15,[15,30]],[18,[30,60]]]}, "icon-allow-overlap": true, "icon-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] },
973-
"text-field": "{cost}", "text-offset": {"base": 1, stops: [[15,[0.15,0.4]],[18,[2.5,6]]]}, "text-allow-overlap": true, "text-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] } ,
988+
"text-field": numberFieldText("cost"), "text-offset": {"base": 1, stops: [[15,[0.15,0.4]],[18,[2.5,6]]]}, "text-allow-overlap": true, "text-rotate": { property: "bearing_in", stops: [[0, 0], [360, 360]] } ,
974989
"text-size": { "base": 1, "stops": [ [ 10, 8 ], [ 18, 11 ] ] }, "text-font": ["Noto Sans Bold"], "symbol-avoid-edges": false},
975990
"paint": { "icon-color" : "#ffffff", "icon-halo-color" : "#ffffff", "icon-halo-width" : 2,
976991
"text-color": "hsl(0, 0%, 100%)", "text-halo-width": 1, "text-halo-color": "hsl(0, 0%, 0%)", "text-halo-blur": 0},
@@ -992,4 +1007,4 @@
9921007
</script>
9931008

9941009
</body>
995-
</html>
1010+
</html>

0 commit comments

Comments
 (0)