Skip to content

Commit

Permalink
Fixed zoom returning NaN if passed in scale bigger than scales defined
Browse files Browse the repository at this point in the history
  • Loading branch information
theashyster committed Sep 15, 2016
1 parent 6feb358 commit f1539a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/proj4leaflet.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@
},

zoom: function(scale) {
// Find closest number in this._scales, down
// Find closest number in this._scales, down
var downScale = this._closestElement(this._scales, scale),
downZoom = this._scales.indexOf(downScale),
nextScale,
nextZoom,
scaleDiff;
// Check if scale is downScale => return array index
Expand All @@ -137,7 +138,11 @@
}
// Interpolate
nextZoom = downZoom + 1;
scaleDiff = this._scales[nextZoom] - downScale;
nextScale = this._scales[nextZoom];
if (nextScale === undefined) {
return Infinity;
}
scaleDiff = nextScale - downScale;
return (scale - downScale) / scaleDiff + downZoom;
},

Expand Down
12 changes: 11 additions & 1 deletion test/specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ describe('L.Proj.CRS', function() {
worldSize *= 2;
}
});
it('convert zoom to scale and viceversa and return the same values', function () {

it('converts zoom to scale and vice versa and returns the same values', function () {
var crs = new L.Proj.CRS('EPSG:3006',
'+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs',
{
Expand All @@ -151,4 +152,13 @@ describe('L.Proj.CRS', function() {
expect(crs.zoom(crs.scale(0.5))).toBe(0.5);
expect(crs.zoom(crs.scale(0.51))).toBe(0.51);
});

it('converts scale to zoom and returns Infinity if the scale passed in is bigger than maximum scale', function () {
var crs = new L.Proj.CRS('EPSG:3006', '', {
scales: [1, 2, 3]
});

expect(crs.zoom(4)).toBe(Infinity);
expect(crs.zoom(Infinity)).toBe(Infinity);
});
});

0 comments on commit f1539a8

Please sign in to comment.