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

Fix for issue 7438 by improving getRoundNum() function. #7469

Merged
merged 2 commits into from
Oct 25, 2018

Conversation

MichaelHedman
Copy link
Contributor

@MichaelHedman MichaelHedman commented Oct 23, 2018

Fix for issue #7438 by improving getRoundNum() function. Added corresponding unit test and debug page.

  • Changed getRoundNum() function in scale_control.js so that it will return numbers < 1, decimal rounded.
  • Added corresponding unit test in scale.test.js
  • Added debug page 7438.html

d >= 0.001 ? Math.round(d * 1000) / 1000 :
d >= 0.0001 ? Math.round(d * 10000) / 10000 :
d >= 0.00001 ? Math.round(d * 100000) / 100000 : Math.round(d * 1000000) / 1000000;
// Could go on forever of course, depending on the unit used. But this is good enough for 'imperial', 'metric' and 'nautical'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be generalized — looks like you can calculate the multiplier with Math.pow(10, Math.ceil(-Math.log(d) / Math.LN10)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I thought of that, but couldn't come up with the right formula. I'll try adding your formula.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Please check latest commit.

Copy link
Member

@mourner mourner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me!

@mourner mourner merged commit ab7d06a into mapbox:master Oct 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants