ablakey/Leaflet.SimpleGraticule

Labels poorly formatted on decimal intervals

Opened this issue · 0 comments

First, congratulations for your first open source project. Your comment encouraged me to offer my feedback and help.
I use SimpleGraticule with these intervals:
zoomIntervals:[
{start:0,end:3,interval:20},
{start:4,end:5,interval:10},
{start:6,end:7,interval:5},
{start:8,end:10,interval:1},
{start:11,end:12,interval:0.5},
{start:13,end:18,interval:0.2},
]
When the interval goes below 1, the labels will, sometimes, appear like -4.00000000001 or -3.9999999998.
I've added this to the getMins funcion:
this.dec=0;
if (Math.floor(s)<s){
var sd=s;
while(Math.floor(sd)<sd){
this.dec++;
sd=s*Math.pow(10, this.dec);
}
}
And changed the way x and y values are calculated on the constructLines function to:
var x = Math.round((mins.x + i * this.options.interval) * Math.pow(10, this.dec)) / Math.pow(10, this.dec);

Maybe this is not the optimal way to do it, but it solved the problem. Hope this helps to improve your plugin.

Best,

Marcelo Gallacci