Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout property proposal: numeric-precision #3361

Closed
wants to merge 3 commits into from
Closed

Conversation

mourner
Copy link
Member

@mourner mourner commented Oct 13, 2016

An alternative solution for #3358. Introduces numeric-precision layout property that affects how numbers are interpolated in text fields. If set,
numbers in resolved text fields of a layer will have the specified precision (e.g. "numeric-precision": 2 will make 123.45678 appear s 123.46).

This is just a proof of concept; a proper implementation would require corresponding style-spec changes, including settling on a default value there.

cc @danpat @jfirebaugh

@lucaswoj
Copy link
Contributor

I'm not sure that the layer's layout properties is the best place for this bit of metadata. Users would be unable to use different numeric precisions for different {tokens} within text-field (and maybe even {icon-image}). Whether or not this is a common use case, it brings up a few questions about our long term API design direction.

I'm excited about exploring string operations in the spirit of mapbox/mapbox-gl-function#28

@jfirebaugh
Copy link
Contributor

Agree 100% with @lucaswoj.

@mourner
Copy link
Member Author

mourner commented Oct 13, 2016

I agree that arbitrary expression functions are much more powerful and may be better suited for this kind of task, although it may take us a very long time to get there.

I'm also interested to see how would such an arbitrary expression look for rounding a number. Would we introduce special keywords like round? What if the property's name is round?

@lucaswoj
Copy link
Contributor

lucaswoj commented Oct 14, 2016

I'm also interested to see how would such an arbitrary expression look for rounding a number. Would we introduce special keywords like round? What if the property's name is round?

I think it'd look like a string formatting library in Javascript

... we create a syntax that is:

  • a valid subset of an existing programming language (Javascript?)

Spitballing syntax here, supposing the feature had a property called foo and feature properties were available on this:

this.foo.toPrecision(2)

http://www.w3schools.com/jsref/jsref_toprecision.asp

@mourner mourner closed this Oct 19, 2016
@jfirebaugh jfirebaugh deleted the numeric-precision branch February 3, 2017 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants