Fix handling of NaN in getScaleZoom (#4914)
* Fixed an issue when crs.zoom returns NaN in getScaleZoom * Small documentation fixes
This commit is contained in:
parent
63fd4edc76
commit
62fdf6f642
@ -1088,11 +1088,20 @@ describe("Map", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('#getScaleZoom && #getZoomScale', function () {
|
describe('#getScaleZoom && #getZoomScale', function () {
|
||||||
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 toZoom = 6.25;
|
var toZoom = 6.25;
|
||||||
var fromZoom = 8.5;
|
var fromZoom = 8.5;
|
||||||
var scale = map.getScaleZoom(toZoom, fromZoom);
|
var scale = map.getZoomScale(toZoom, fromZoom);
|
||||||
expect(Math.round(map.getZoomScale(scale, fromZoom) * 100) / 100).to.eql(toZoom);
|
expect(Math.round(map.getScaleZoom(scale, fromZoom) * 100) / 100).to.eql(toZoom);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("converts scale to zoom and returns Infinity if map crs.zoom returns NaN", function () {
|
||||||
|
var stub = sinon.stub(map.options.crs, "zoom");
|
||||||
|
stub.returns(NaN);
|
||||||
|
var scale = 0.25;
|
||||||
|
var fromZoom = 8.5;
|
||||||
|
expect(map.getScaleZoom(scale, fromZoom)).to.eql(Infinity);
|
||||||
|
map.options.crs.zoom.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ L.CRS = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// @method zoom(scale: Number): Number
|
// @method zoom(scale: Number): Number
|
||||||
// Inverse of `scale()`, returns the zoom level correspondingto a scale
|
// Inverse of `scale()`, returns the zoom level corresponding to a scale
|
||||||
// factor of `scale`.
|
// factor of `scale`.
|
||||||
zoom: function (scale) {
|
zoom: function (scale) {
|
||||||
return Math.log(scale / 256) / Math.LN2;
|
return Math.log(scale / 256) / Math.LN2;
|
||||||
|
@ -609,7 +609,8 @@ L.Map = L.Evented.extend({
|
|||||||
getScaleZoom: function (scale, fromZoom) {
|
getScaleZoom: function (scale, fromZoom) {
|
||||||
var crs = this.options.crs;
|
var crs = this.options.crs;
|
||||||
fromZoom = fromZoom === undefined ? this._zoom : fromZoom;
|
fromZoom = fromZoom === undefined ? this._zoom : fromZoom;
|
||||||
return crs.zoom(scale * crs.scale(fromZoom));
|
var zoom = crs.zoom(scale * crs.scale(fromZoom));
|
||||||
|
return isNaN(zoom) ? Infinity : zoom;
|
||||||
},
|
},
|
||||||
|
|
||||||
// @method project(latlng: LatLng, zoom: Number): Point
|
// @method project(latlng: LatLng, zoom: Number): Point
|
||||||
@ -851,14 +852,14 @@ L.Map = L.Evented.extend({
|
|||||||
this._pixelOrigin = this._getNewPixelOrigin(center);
|
this._pixelOrigin = this._getNewPixelOrigin(center);
|
||||||
|
|
||||||
// @event zoom: Event
|
// @event zoom: Event
|
||||||
// Fired repeteadly during any change in zoom level, including zoom
|
// Fired repeatedly during any change in zoom level, including zoom
|
||||||
// and fly animations.
|
// and fly animations.
|
||||||
if (zoomChanged || (data && data.pinch)) { // Always fire 'zoom' if pinching because #3530
|
if (zoomChanged || (data && data.pinch)) { // Always fire 'zoom' if pinching because #3530
|
||||||
this.fire('zoom', data);
|
this.fire('zoom', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @event move: Event
|
// @event move: Event
|
||||||
// Fired repeteadly during any movement of the map, including pan and
|
// Fired repeatedly during any movement of the map, including pan and
|
||||||
// fly animations.
|
// fly animations.
|
||||||
return this.fire('move', data);
|
return this.fire('move', data);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user