"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "spec/suites/map/MapSpec.js" between
Leaflet-1.8.0.tar.gz and Leaflet-1.9.0.tar.gz

About: Leaflet is a JavaScript library for mobile-friendly interactive maps.

MapSpec.js  (Leaflet-1.8.0):MapSpec.js  (Leaflet-1.9.0)
skipping to change at line 122 skipping to change at line 122
map.setZoom(19); map.setZoom(19);
expect(map.getCenter()).to.eql(center); expect(map.getCenter()).to.eql(center);
}); });
it("returns correct center after invalidateSize (#1919)", functio n () { it("returns correct center after invalidateSize (#1919)", functio n () {
var center = L.latLng(10, 10); var center = L.latLng(10, 10);
map.setView(center, 1); map.setView(center, 1);
map.invalidateSize(); map.invalidateSize();
expect(map.getCenter()).not.to.eql(center); expect(map.getCenter()).not.to.eql(center);
}); });
it("returns a new object that can be mutated without affecting th
e map", function () {
map.setView([10, 10], 1);
var center = map.getCenter();
center.lat += 10;
expect(map.getCenter()).to.eql(L.latLng(10, 10));
});
}); });
describe("#whenReady", function () { describe("#whenReady", function () {
describe("when the map has not yet been loaded", function () { describe("when the map has not yet been loaded", function () {
it("calls the callback when the map is loaded", function () { it("calls the callback when the map is loaded", function () {
var spy = sinon.spy(); var spy = sinon.spy();
map.whenReady(spy); map.whenReady(spy);
expect(spy.called).to.not.be.ok(); expect(spy.called).to.not.be.ok();
map.setView([0, 0], 1); map.setView([0, 0], 1);
skipping to change at line 184 skipping to change at line 191
}); });
it("passes duration option to panBy", function () { it("passes duration option to panBy", function () {
var map = L.map(document.createElement("div"), {zoom: 13, center: [0, 0]}); var map = L.map(document.createElement("div"), {zoom: 13, center: [0, 0]});
map.panBy = sinon.spy(); map.panBy = sinon.spy();
map.setView([51.605, -0.11], 13, {animate: true, duration : 13}); map.setView([51.605, -0.11], 13, {animate: true, duration : 13});
map.remove(); // clean up map.remove(); // clean up
expect(map.panBy.callCount).to.eql(1); expect(map.panBy.callCount).to.eql(1);
expect(map.panBy.args[0][1].duration).to.eql(13); expect(map.panBy.args[0][1].duration).to.eql(13);
}); });
it("prevents firing movestart noMoveStart", function (done) {
var movestartSpy = sinon.spy();
map.on("movestart", movestartSpy);
var moveendSpy = sinon.spy();
map.on("moveend", moveendSpy);
map.setView([51.505, -0.09], 13, {pan: {noMoveStart: true
}});
setTimeout(function () {
expect(movestartSpy.notCalled).to.eql(true);
expect(moveendSpy.calledOnce).to.eql(true);
done();
}, 100);
});
});
describe("#setZoom", function () {
describe("when the map has not yet been loaded", function () {
it("set zoom level is not limited by max zoom", function
() {
map.options.maxZoom = 10;
map.setZoom(15);
expect(map.getZoom()).to.be(15);
});
it("overwrites zoom passed as map option", function () {
var map2 = L.map(document.createElement("div"), {
zoom: 13});
map2.setZoom(15);
var zoom = map2.getZoom();
map2.remove(); // clean up
expect(zoom).to.be(15);
});
});
describe("when the map has been loaded", function () {
beforeEach(function () {
map.setView([0, 0], 0); // loads map
});
it("set zoom level is limited by max zoom", function () {
map.options.maxZoom = 10;
map.setZoom(15);
expect(map.getZoom()).to.be(10);
});
it("does not overwrite zoom passed as map option", functi
on () {
var map2 = L.map(document.createElement("div"), {
zoom: 13});
map2.setView([0, 0]);
map2.setZoom(15);
var zoom = map2.getZoom();
map2.remove(); // clean up
expect(zoom).to.be(13);
});
});
it("changes previous zoom level", function () {
map.zoom = 10;
map.setZoom(15);
expect(map.getZoom()).to.be(15);
});
it("can be passed without a zoom specified and keep previous zoom
", function () {
var prevZoom = map.getZoom();
map.setZoom();
expect(map.getZoom()).to.be(prevZoom);
});
it("can be passed with a zoom level of undefined and keep previou
s zoom", function () {
var prevZoom = map.getZoom();
map.setZoom(undefined);
expect(map.getZoom()).to.be(prevZoom);
});
it("can be passed with a zoom level of infinity", function () {
map.setZoom(Infinity);
expect(map.getZoom()).to.be(Infinity);
});
});
describe("#setZoomAround", function () {
beforeEach(function () {
map.setView([0, 0], 0); // loads map
});
it("pass Point and change pixel in view", function () {
var point = L.point(5, 5);
map.setZoomAround(point, 5);
expect(map.getBounds().contains(map.options.crs.pointToLa
tLng(point, 5))).to.be(false);
});
it("pass Point and change pixel in view at high zoom", function (
) {
var point = L.point(5, 5);
map.setZoomAround(point, 18);
expect(map.getBounds().contains(map.options.crs.pointToLa
tLng(point, 18))).to.be(false);
});
it("pass latLng and keep specified latLng in view", function () {
map.setZoomAround([5, 5], 5);
expect(map.getBounds().contains([5, 5])).to.be(true);
});
it("pass latLng and keep specified latLng in view at high zoom fa
ils", function () {
map.setZoomAround([5, 5], 12); // usually fails around 9
zoom level
expect(map.getBounds().contains([5, 5])).to.be(false);
});
it("throws if map is not loaded", function () {
var unloadedMap = L.map(document.createElement("div"));
expect(unloadedMap.setZoomAround).withArgs([5, 5], 4).to.
throwException();
});
it("throws if zoom is empty", function () {
expect(map.setZoomAround).withArgs([5, 5]).to.throwExcept
ion();
});
it("throws if zoom is undefined", function () {
expect(map.setZoomAround).withArgs([5, 5], undefined).to.
throwException();
});
it("throws if latLng is undefined", function () {
expect(map.setZoomAround).withArgs([undefined, undefined]
, 4).to.throwException();
});
it("does not throw if latLng is infinity", function () {
map.setView([5, 5]);
map.setZoomAround([Infinity, Infinity], 4);
expect(map.getCenter()).to.be.ok();
});
}); });
describe("#getBounds", function () { describe("#getBounds", function () {
it("is safe to call from within a moveend callback during initial load (#1027)", function () { it("is safe to call from within a moveend callback during initial load (#1027)", function () {
var map = L.map(document.createElement("div")); var map = L.map(document.createElement("div"));
map.on("moveend", function () { map.on("moveend", function () {
map.getBounds(); map.getBounds();
}); });
map.setView([51.505, -0.09], 13); map.setView([51.505, -0.09], 13);
map.remove(); // clean up map.remove(); // clean up
skipping to change at line 303 skipping to change at line 452
map.setMaxBounds(bounds, {animate: false}); map.setMaxBounds(bounds, {animate: false});
map.setMaxBounds(); map.setMaxBounds();
// set view outside // set view outside
var center = L.latLng([0, 0]); var center = L.latLng([0, 0]);
map.once("moveend", function () { map.once("moveend", function () {
expect(center.equals(map.getCenter())).to.be(true ); expect(center.equals(map.getCenter())).to.be(true );
done(); done();
}); });
map.setView(center, 18, {animate: false}); map.setView(center, 18, {animate: false});
}); });
it("does not try to remove listeners if it wasn't set before", fu
nction () {
L.tileLayer("", {minZoom: 0, maxZoom: 20}).addTo(map);
container.style.width = container.style.height = "500px";
var bounds = L.latLngBounds([51.5, -0.05], [51.55, 0.05])
;
map.off = sinon.spy();
map.setMaxBounds(bounds, {animate: false});
expect(map.off.called).not.to.be.ok();
});
});
describe("#setMinZoom and #setMaxZoom", function () {
describe("when map is not loaded", function () {
it("change min and max zoom but not zoom", function () {
map.setZoom(2);
map.setMinZoom(3);
expect(map.getZoom()).to.eql(2);
expect(map.getMinZoom()).to.eql(3);
map.setMaxZoom(7);
expect(map.getZoom()).to.eql(2);
expect(map.getMaxZoom()).to.eql(7);
});
it("do not fire 'zoomlevelschange'", function () {
var spy = sinon.spy();
map.on("zoomlevelschange", spy);
map.setZoom(5);
map.setMinZoom(3);
map.setMaxZoom(7);
expect(map.getZoom()).to.eql(5);
expect(map.getMinZoom()).to.eql(3);
expect(map.getMaxZoom()).to.eql(7);
expect(spy.called).to.not.be.ok();
});
});
describe("when map is loaded", function () {
var spy;
beforeEach(function () {
map.setView([0, 0], 4); // loads map
spy = sinon.spy();
map.on("zoomlevelschange", spy);
});
it("do not fire 'zoomlevelschange' if zoom level did not
change", function () {
map.setMinZoom(2);
map.setMaxZoom(7);
expect(map.getZoom()).to.eql(4);
expect(map.getMinZoom()).to.eql(2);
expect(map.getMaxZoom()).to.eql(7);
expect(spy.calledTwice).to.be.ok();
var postSpy = sinon.spy();
map.on("zoomlevelschange", postSpy);
map.setMinZoom(2);
map.setMaxZoom(7);
expect(postSpy.called).to.not.be.ok();
});
it("fire 'zoomlevelschange' but do not change zoom if max
/min zoom is less/more current zoom", function () {
map.setMinZoom(2);
map.setMaxZoom(7);
expect(map.getZoom()).to.eql(4);
expect(map.getMinZoom()).to.eql(2);
expect(map.getMaxZoom()).to.eql(7);
expect(spy.calledTwice).to.be.ok();
});
});
it("reset min/max zoom if set to undefined or missing param", fun
ction () {
map.setMinZoom(undefined);
map.setMaxZoom();
expect(map.options.minZoom).to.be(undefined);
expect(map.options.maxZoom).to.be(undefined);
expect(map.getMinZoom()).to.be(0); // min layer zoom used
instead
expect(map.getMaxZoom()).to.be(Infinity); // max layer zo
om used instead
});
it("allow infinity to be passed", function () {
map.setMinZoom(Infinity);
map.setMaxZoom(Infinity);
expect(map.getMinZoom()).to.be(Infinity);
expect(map.getMaxZoom()).to.be(Infinity);
});
}); });
describe("#getMinZoom and #getMaxZoom", function () { describe("#getMinZoom and #getMaxZoom", function () {
describe("#getMinZoom", function () { describe("#getMinZoom", function () {
it("returns 0 if not set by Map options or TileLayer opti ons", function () { it("returns 0 if not set by Map options or TileLayer opti ons", function () {
expect(map.getMinZoom()).to.be(0); expect(map.getMinZoom()).to.be(0);
}); });
}); });
it("minZoom and maxZoom options overrides any minZoom and maxZoom set on layers", function () { it("minZoom and maxZoom options overrides any minZoom and maxZoom set on layers", function () {
skipping to change at line 366 skipping to change at line 614
removeMapContainer(map, container); removeMapContainer(map, container);
container = createContainer(); container = createContainer();
map = L.map(container, {zoom: 20}); map = L.map(container, {zoom: 20});
L.tileLayer("", {maxZoom: 15}).addTo(map); L.tileLayer("", {maxZoom: 15}).addTo(map);
expect(map.getZoom()).to.be(15); expect(map.getZoom()).to.be(15);
}); });
}); });
describe("createPane", function () {
it("create a new pane to mapPane when container not specified", f
unction () {
map.createPane('controlPane');
expect(map.getPane('controlPane').className).to.eql('leaf
let-pane leaflet-control-pane');
});
it("create a new pane to container specified", function () {
map.createPane('controlPane', map.getPane('tooltipPane'))
;
expect(map.getPane('controlPane').parentElement.className
).to.eql(
'leaflet-pane leaflet-tooltip-pane');
});
it("create a new pane to mapPane when container is invalid", func
tion () {
map.createPane('controlPane', undefined);
expect(map.getPane('controlPane').parentElement.className
).to.eql(
'leaflet-pane leaflet-map-pane');
});
it("replace same named pane", function () {
var overlayPane = map.getPane('overlayPane');
map.createPane('overlayPane');
expect(map.getPane('overlayPane')).to.not.be(overlayPane)
;
});
});
describe("#getPane", function () {
it("return pane by String", function () {
expect(map.getPane('tilePane').className).to.eql('leaflet
-pane leaflet-tile-pane');
});
it("return pane by pane", function () {
expect(map.getPane(map.getPanes()['shadowPane']).classNam
e).to.eql(
'leaflet-pane leaflet-shadow-pane');
});
it("return empty pane when not found", function () {
expect(map.getPane('foo bar')).to.eql(undefined);
});
});
describe("#getPanes", function () {
it("return all default panes", function () {
var keys = Object.keys(map.getPanes());
expect(keys).to.eql(
['mapPane', 'tilePane', 'overlayPane', 'shadowPan
e', 'markerPane', 'tooltipPane', 'popupPane']);
});
it("return empty pane when map deleted", function () {
var map2 = L.map(document.createElement('div'));
map2.remove();
expect(map2.getPanes()).to.eql({});
});
});
describe("#getContainer", function () {
it("return container object", function () {
expect(map.getContainer()._leaflet_id).to.be.ok();
});
it("return undefined on empty container id", function () {
var container2 = createContainer();
var map2 = L.map(container2);
map2.remove(); // clean up
expect(map2.getContainer()._leaflet_id).to.eql(undefined)
;
});
});
describe("#getSize", function () {
it("return map size in pixels", function () {
expect(map.getSize()).to.eql(L.point([400, 400]));
});
it("return map size if not specified", function () {
var map2 = L.map(document.createElement("div"));
expect(map2.getSize()).to.eql(L.point([0, 0]));
map2.remove(); // clean up
});
it("return map size if 0x0 pixels", function () {
container.style.width = "0px";
container.style.height = "0px";
expect(map.getSize()).to.eql(L.point([0, 0]));
});
it("return new pixels on change", function () {
container.style.width = "300px";
expect(map.getSize()).to.eql(L.point([300, 400]));
});
it("return clone of size object from map", function () {
expect(map.getSize()).to.not.be(map._size);
});
it("return previous size on empty map", function () {
var container2 = createContainer();
var map2 = L.map(container2);
map2.remove(); // clean up
expect(map2.getSize()).to.eql(L.point([400, 400]));
});
});
describe("#getPixelBounds", function () {
beforeEach(function () {
map.setView([0, 0], 0); // load map
});
it("return map bounds in pixels", function () {
expect(map.getPixelBounds()).to.eql(L.bounds([-72, -72],
[328, 328]));
});
it("return changed map bounds if really zoomed in", function () {
map.setZoom(20);
expect(map.getPixelBounds()).to.eql(L.bounds([134217528,
134217528], [134217928, 134217928]));
});
it("return new pixels on view change", function () {
map.setView([50, 50], 5);
expect(map.getPixelBounds()).to.eql(L.bounds([5034, 2578]
, [5434, 2978]));
});
it("throw error if center and zoom were not set / map not loaded"
, function () {
var container2 = createContainer();
var map2 = L.map(container2);
expect(map2.getPixelBounds).to.throwException();
map2.remove(); // clean up
});
});
describe("#getPixelOrigin", function () {
beforeEach(function () {
map.setView([0, 0], 0); // load map
});
it("return pixel origin", function () {
expect(map.getPixelOrigin()).to.eql(L.point([-72, -72]));
});
it("return new pixels on view change", function () {
map.setView([50, 50], 5);
expect(map.getPixelOrigin()).to.eql(L.point([5034, 2578])
);
});
it("return changed map bounds if really zoomed in", function () {
map.setZoom(20);
expect(map.getPixelOrigin()).to.eql(L.point([134217528, 1
34217528]));
});
it("throw error if center and zoom were not set / map not loaded"
, function () {
var container2 = createContainer();
var map2 = L.map(container2);
expect(map2.getPixelOrigin).to.throwException();
map2.remove(); // clean up
});
});
describe("#getPixelWorldBounds", function () {
it("return map bounds in pixels", function () {
expect(map.getPixelWorldBounds()).to.eql(L.bounds(
[5.551115123125783e-17, 5.551115123125783e-17], [
1, 1]));
});
it("return changed map bounds if really zoomed in", function () {
map.setZoom(20);
expect(map.getPixelWorldBounds()).to.eql(L.bounds(
[1.4901161193847656e-8, 1.4901161193847656e-8], [
268435456, 268435456]));
});
it("return new pixels on zoom change", function () {
map.setZoom(5);
expect(map.getPixelWorldBounds()).to.eql(L.bounds(
[4.547473508864641e-13, 4.547473508864641e-13], [
8192, 8192]));
map.setView([0, 0]);
// view does not change pixel world bounds
expect(map.getPixelWorldBounds()).to.eql(L.bounds(
[4.547473508864641e-13, 4.547473508864641e-13], [
8192, 8192]));
});
it("return infinity bounds on infinity zoom", function () {
map.setZoom(Infinity);
expect(map.getPixelWorldBounds()).to.eql(L.bounds(
[Infinity, Infinity], [Infinity, Infinity]));
});
});
describe("#hasLayer", function () { describe("#hasLayer", function () {
it("throws when called without proper argument", function () { it("throws when called without proper argument", function () {
var hasLayer = L.Util.bind(map.hasLayer, map); var hasLayer = L.Util.bind(map.hasLayer, map);
expect(hasLayer).withArgs(new L.Layer()).to.not.throwExce ption(); // control case expect(hasLayer).withArgs(new L.Layer()).to.not.throwExce ption(); // control case
expect(hasLayer).withArgs(undefined).to.throwException(); expect(hasLayer).withArgs(undefined).to.throwException();
expect(hasLayer).withArgs(null).to.throwException(); expect(hasLayer).withArgs(null).to.throwException();
expect(hasLayer).withArgs(false).to.throwException(); expect(hasLayer).withArgs(false).to.throwException();
expect(hasLayer).to.throwException(); expect(hasLayer).to.throwException();
}); });
skipping to change at line 1022 skipping to change at line 1482
it("Snaps to a number after adding marker", function () { it("Snaps to a number after adding marker", function () {
// expect(L.Browser.any3d).to.be.ok(); // precondition // expect(L.Browser.any3d).to.be.ok(); // precondition
map.addLayer(L.marker(center)); map.addLayer(L.marker(center));
expect(map.getZoom()).to.be(undefined); expect(map.getZoom()).to.be(undefined);
map.fitBounds(bounds); map.fitBounds(bounds);
expect(map.getZoom()).to.be(2); expect(map.getZoom()).to.be(2);
}); });
}); });
describe("#fitWorld", function () {
var bounds = L.latLngBounds([90, -180], [-90, 180]),
boundsCenter = bounds.getCenter();
beforeEach(function () {
// fitBounds needs a map container with non-null area
container.style.width = container.style.height = "100px";
});
it("map zooms out to max view with default settings", function ()
{
map.setZoom(5);
map.fitWorld();
expect(map.getZoom()).to.eql(0);
expect(map.getCenter().equals(boundsCenter, 0.05)).to.eql
(true);
});
});
describe("#panInside", function () { describe("#panInside", function () {
var center, var center,
tl, tl,
tlPix; tlPix;
beforeEach(function () { beforeEach(function () {
container.style.height = container.style.width = "500px"; container.style.height = container.style.width = "500px";
map.setView(L.latLng([53.0, 0.15]), 12, {animate: false}) ; map.setView(L.latLng([53.0, 0.15]), 12, {animate: false}) ;
center = map.getCenter(); center = map.getCenter().clone();
tl = map.getBounds().getNorthWest(); tl = map.getBounds().getNorthWest();
tlPix = map.getPixelBounds().min; tlPix = map.getPixelBounds().min;
}); });
it("does not pan the map when the target is within bounds", funct ion () { it("does not pan the map when the target is within bounds", funct ion () {
map.panInside(tl, {animate:false}); map.panInside(tl, {animate:false});
expect(center).to.equal(map.getCenter()); expect(center).to.eql(map.getCenter());
}); });
it("pans the map when padding is provided and the target is withi n the border area", function () { it("pans the map when padding is provided and the target is withi n the border area", function () {
var padding = [40, 20], var padding = [40, 20],
p = tlPix.add([30, 0]), // Top-left p = tlPix.add([30, 0]), // Top-left
distanceMoved; distanceMoved;
map.panInside(map.unproject(p), {padding: padding, animat e: false}); map.panInside(map.unproject(p), {padding: padding, animat e: false});
distanceMoved = map.getPixelBounds().min.subtract(tlPix); distanceMoved = map.getPixelBounds().min.subtract(tlPix);
expect(distanceMoved.equals(L.point([-10, -20]))).to.eql( true); expect(distanceMoved.equals(L.point([-10, -20]))).to.eql( true);
skipping to change at line 1069 skipping to change at line 1547
tlPix = map.getPixelBounds().min; tlPix = map.getPixelBounds().min;
p = [map.getPixelBounds().max.x - 15, map.getPixelBounds( ).max.y]; // Bottom-right p = [map.getPixelBounds().max.x - 15, map.getPixelBounds( ).max.y]; // Bottom-right
map.panInside(map.unproject(p), {padding: padding, animat e: false}); map.panInside(map.unproject(p), {padding: padding, animat e: false});
distanceMoved = map.getPixelBounds().min.subtract(tlPix); distanceMoved = map.getPixelBounds().min.subtract(tlPix);
expect(distanceMoved.equals(L.point([25, 20]))).to.eql(tr ue); expect(distanceMoved.equals(L.point([25, 20]))).to.eql(tr ue);
}); });
it("supports different padding values for each border", function () { it("supports different padding values for each border", function () {
var p = tlPix.add([40, 0]), // Top-Left var p = tlPix.add([40, 0]), // Top-Left
opts = {paddingTL: [60, 20], paddingBR: [10, 10]}; opts = {paddingTL: [60, 20], paddingBR: [10, 10], ani mate: false};
map.panInside(map.unproject(p), opts); map.panInside(map.unproject(p), opts);
expect(center).to.equal(map.getCenter()); expect(center).to.eql(map.getCenter());
var br = map.getPixelBounds().max; // Bottom-Right var br = map.getPixelBounds().max; // Bottom-Right
map.panInside(map.unproject(L.point(br.x - 20, br.y)), op map.panInside(map.unproject(L.point(br.x + 20, br.y)), op
ts); ts);
expect(center).to.not.equal(map.getCenter); expect(center).to.not.eql(map.getCenter());
}); });
it("pans on both X and Y axes when the target is outside of the v iew area and both the point's coords are outside the bounds", function () { it("pans on both X and Y axes when the target is outside of the v iew area and both the point's coords are outside the bounds", function () {
var p = map.unproject(tlPix.subtract([200, 200])); var p = map.unproject(tlPix.subtract([200, 200]));
map.panInside(p, {animate: false}); map.panInside(p, {animate: false});
expect(map.getBounds().contains(p)).to.be(true); expect(map.getBounds().contains(p)).to.be(true);
expect(map.getCenter().lng).to.not.eql(center.lng); expect(map.getCenter().lng).to.not.eql(center.lng);
expect(map.getCenter().lat).to.not.eql(center.lat); expect(map.getCenter().lat).to.not.eql(center.lat);
}); });
skipping to change at line 1339 skipping to change at line 1817
it("doesn't throw error if location is not found and map is not e xisting", function () { it("doesn't throw error if location is not found and map is not e xisting", function () {
map._locateOptions = {setView: true}; map._locateOptions = {setView: true};
var fn = L.Util.bind(map._handleGeolocationError, map); var fn = L.Util.bind(map._handleGeolocationError, map);
map.remove(); map.remove();
map = null; map = null;
expect(function () { expect(function () {
fn({coords: {latitude: 40.415296, longitude: 10.7 419264, accuracy: 1129.5646101470752}}); fn({coords: {latitude: 40.415296, longitude: 10.7 419264, accuracy: 1129.5646101470752}});
}).to.not.throwException(); }).to.not.throwException();
}); });
}); });
describe('#disableClickPropagation', function () {
it('does not break if element is not in the DOM anymore', functio
n () {
map.setView([0, 0], 0);
var parent = document.createElement('div');
var child = document.createElement('div');
parent.appendChild(child);
container.appendChild(parent);
L.DomEvent.on(child, 'click', function () {
L.DomUtil.remove(parent);
});
expect(function () {
happen.once(child, {type: 'click'});
}).to.not.throwException();
});
});
describe("#distance", function () {
it("measure distance in meters", function () {
var LA = L.latLng(34.0485672098387, -118.217781922035);
var columbus = L.latLng(39.95715687063701, -83.0020570585
7633);
expect(map.distance(LA, columbus)).to.be.within(3173910,
3173915);
});
it("accurately measure in small distances", function () {
var p1 = L.latLng(40.160857881285416, -83.00841851162649)
;
var p2 = L.latLng(40.16246493902907, -83.008622359483);
expect(map.distance(p1, p2)).to.be.within(175, 185);
});
it("accurately measure in long distances", function () {
var canada = L.latLng(60.01810635103154, -112.19675246283
015);
var newZeland = L.latLng(-42.36275164460971, 172.39309066
597883);
expect(map.distance(canada, newZeland)).to.be.within(1327
4700, 13274800);
});
it("throw with undefined values", function () {
expect(map.distance).withArgs(undefined, undefined).to.th
rowException();
});
it("throw with infinity values", function () {
expect(map.distance).withArgs(Infinity, Infinity).to.thro
wException();
});
it("throw with only 1 lat", function () {
expect(map.distance).withArgs(20, 50).to.throwException()
;
});
it("return 0 with 2 same latLng", function () {
var p = L.latLng(20, 50);
expect(map.distance(p, p)).to.eql(0);
});
});
describe("#containerPointToLayerPoint", function () {
it("return same point of LayerPoint is 0, 0", function () {
expect(map.containerPointToLayerPoint(L.point(25, 25))).t
o.eql(L.point(25, 25));
});
it("return point relative to LayerPoint", function (done) {
map.setView([20, 20], 2);
map.once("moveend", function () {
expect(map.containerPointToLayerPoint(L.point(30,
30))).to.eql(L.point(80, 80));
done();
});
map.panBy([50, 50]);
});
});
describe("#layerPointToContainerPoint", function () {
it("return same point of ContainerPoint is 0, 0", function () {
expect(map.layerPointToContainerPoint(L.point(25, 25))).t
o.eql(L.point(25, 25));
});
it("return point relative to ContainerPoint", function (done) {
map.setView([20, 20], 2);
map.once("moveend", function () {
expect(map.layerPointToContainerPoint(L.point(30,
30))).to.eql(L.point(-20, -20));
done();
});
map.panBy([50, 50]);
});
});
describe("_addZoomLimit", function () {
it("update zoom levels when min zoom is a number in a layer that
is added to map", function () {
map._addZoomLimit(L.tileLayer("", {minZoom: 4}));
expect(map._layersMinZoom).to.be(4);
});
it("update zoom levels when max zoom is a number in a layer that
is added to map", function () {
map._addZoomLimit(L.tileLayer("", {maxZoom: 10}));
expect(map._layersMaxZoom).to.be(10);
});
it("update zoom levels when min zoom is a number in two layers th
at are added to map", function () {
map._addZoomLimit(L.tileLayer("", {minZoom: 6}));
map._addZoomLimit(L.tileLayer("", {minZoom: 4}));
expect(map._layersMinZoom).to.be(4);
});
it("update zoom levels when max zoom is a number in two layers th
at are added to map", function () {
map._addZoomLimit(L.tileLayer("", {maxZoom: 10}));
map._addZoomLimit(L.tileLayer("", {maxZoom: 8}));
expect(map._layersMaxZoom).to.be(10);
});
// This test shows the NaN usage - it's not clear if NaN is a wan
ted "feature"
it("update zoom levels when min zoom is NaN in a layer that is ad
ded to map, so that min zoom becomes NaN,", function () {
map._addZoomLimit(L.tileLayer("", {minZoom: NaN}));
expect(isNaN(map._layersMinZoom)).to.be(true);
});
// This test shows the NaN usage - it's not clear if NaN is a wan
ted "feature"
it("update zoom levels when max zoom is NaN in a layer that is ad
ded to map, so that max zoom becomes NaN", function () {
map._addZoomLimit(L.tileLayer("", {maxZoom: NaN}));
expect(isNaN(map._layersMaxZoom)).to.be(true);
});
// This test shows the NaN usage - it's not clear if NaN is a wan
ted "feature"
// Test is clearly wrong, but kept for future fixes
// it("update zoom levels when min zoom is NaN in at least one of
many layers that are added to map, so that min zoom becomes NaN", function () {
// map._addZoomLimit(L.tileLayer("", {minZoom: 6}));
// map._addZoomLimit(L.tileLayer("", {minZoom: NaN})); --> R
esults in maxZoom = NaN --> _updateZoomLevels is not called.
// Not same logic as for maxZoom.
// map._addZoomLimit(L.tileLayer("", {minZoom: 4}));
// expect(isNaN(map._layersMinZoom)).to.be(true);
// });
// This test shows the NaN usage - it's not clear if NaN is a wan
ted "feature"
it("update zoom levels when max zoom is NaN in at least one of ma
ny layers that are added to map, so that max zoom becomes NaN", function () {
map._addZoomLimit(L.tileLayer("", {maxZoom: 10}));
map._addZoomLimit(L.tileLayer("", {maxZoom: 8}));
map._addZoomLimit(L.tileLayer("", {maxZoom: NaN}));
expect(isNaN(map._layersMaxZoom)).to.be(true);
});
it("doesn't update zoom levels when min and max zoom are both NaN
in a layer that is added to map", function () {
map._addZoomLimit(L.tileLayer("", {minZoom: NaN, maxZoom:
NaN}));
expect(map._layersMinZoom === undefined && map._layersMax
Zoom === undefined).to.be(true);
});
});
describe("#containerPointToLatLng", function () {
it("throws if map is not set before", function () {
expect(function () {
map.containerPointToLatLng();
}).to.throwError();
});
it("returns geographical coordinate for point relative to map con
tainer", function () {
var center = L.latLng(10, 10);
map.setView(center, 50);
var p = map.containerPointToLatLng(L.point(200, 200));
expect(p.lat).to.be.within(10.0000000, 10.0000001);
expect(p.lng).to.be.within(10.0000000, 10.0000001);
});
});
describe("#latLngToContainerPoint", function () {
it("throws if map is not set before", function () {
expect(function () {
map.latLngToContainerPoint();
}).to.throwError();
});
it("returns point relative to map container for geographical coor
dinate", function () {
var center = L.latLng(10, 10);
map.setView(center);
var p = map.latLngToContainerPoint(center);
expect(p.x).to.be.equal(200);
expect(p.y).to.be.equal(200);
});
});
describe("#panTo", function () {
it("throws if map is not set before", function () {
expect(function () {
map.panTo();
}).to.throwError();
});
it("pans the map to accurate location", function () {
var center = L.latLng([50, 30]);
expect(map.panTo(center)).to.be(map);
expect(map.getCenter().distanceTo(center)).to.be.lessThan
(5);
});
});
describe("#latLngToLayerPoint", function () {
it("throws if map is not set before", function () {
expect(function () {
map.latLngToLayerPoint();
}).to.throwError();
});
it("returns the corresponding pixel coordinate relative to the or
igin pixel", function () {
var center = L.latLng([10, 10]);
map.setView(center, 0);
var p = map.latLngToLayerPoint(center);
expect(p.x).to.be.equal(200);
expect(p.y).to.be.equal(200);
});
});
}); });
 End of changes. 11 change blocks. 
7 lines changed or deleted 783 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)