mapbox / mapbox-gl-style-spec

76 stars 38 forks source link

Provide a way to format & localize numbers #452

Closed 1ec5 closed 7 years ago

1ec5 commented 8 years ago

It’s possible for a style to localize string labels by choosing a language-specific field in the source. But when it comes to numeric types (elevations of peaks, for instance), the viewer is stuck with an unformatted number of the form ####.## using European digits. Ideally, it should be possible for a topo map to show elevations in #,###.## form for English, in # ###,## form for French, and in #,##,###.## form for various Indic languages. Meanwhile, an Arabic or Gujarati map would use the appropriate numeral system.

I’m not sure whether the number format should be controlled by the style (and thus defined in this specification) or determined by the system locale (and thus be implementation-specific). But I figured I’d start here because the conventional approach to localized strings involves changing style properties.

/cc @mikemorris @kkaefer @lucaswoj

lucaswoj commented 8 years ago

👍

While we're thinking about this, we should think about units too. A couple countries (namely Burma and Liberia (😈)) are still using imperial units.

dpieri commented 8 years ago

It would be very helpful for our use case to be able to do simple math in labels. We display feet everywhere on our map (I know, I know..) but we rely on Mapbox Terrain for elevation contours. These are in meters and people keep getting confused by this. Currently the text field on our contour labels is {ele}m, I'd love to be able to use {ele*3.28}ft

As far as I can tell, my only option is to create my own contour tileset and convert meters to feet.

Another fix would be to include something like ele_ft in the Mapbox Terrain's contour layer so each style can pick the unit it prefers. It looks like Mapbox Streets v7 takes this approach for peak labels.

1ec5 commented 8 years ago

Unit customization and more general math functionality would be covered by #47. I think we should keep these two concepts separate, because (except for mixed numbers or non-positional systems like Roman or Chinese numerals) number formatting is all about text processing rather than arithmetic.

lucaswoj commented 7 years ago

This issue was moved to mapbox/mapbox-gl-js#4119