mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-08-16 16:45:22 +00:00
fix map.getCenter() returning a mutable object (#8167)
This commit is contained in:

committed by
GitHub

parent
2da373f2ab
commit
5f2b480d3e
@ -119,6 +119,13 @@ describe("Map", function () {
|
||||
map.invalidateSize();
|
||||
expect(map.getCenter()).not.to.eql(center);
|
||||
});
|
||||
|
||||
it("returns a new object that can be mutated without affecting the 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 () {
|
||||
@ -1027,14 +1034,14 @@ describe("Map", function () {
|
||||
beforeEach(function () {
|
||||
container.style.height = container.style.width = "500px";
|
||||
map.setView(L.latLng([53.0, 0.15]), 12, {animate: false});
|
||||
center = map.getCenter();
|
||||
center = map.getCenter().clone();
|
||||
tl = map.getBounds().getNorthWest();
|
||||
tlPix = map.getPixelBounds().min;
|
||||
});
|
||||
|
||||
it("does not pan the map when the target is within bounds", function () {
|
||||
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 within the border area", function () {
|
||||
@ -1066,13 +1073,13 @@ describe("Map", function () {
|
||||
|
||||
it("supports different padding values for each border", function () {
|
||||
var p = tlPix.add([40, 0]), // Top-Left
|
||||
opts = {paddingTL: [60, 20], paddingBR: [10, 10]};
|
||||
opts = {paddingTL: [60, 20], paddingBR: [10, 10], animate: false};
|
||||
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
|
||||
map.panInside(map.unproject(L.point(br.x - 20, br.y)), opts);
|
||||
expect(center).to.not.equal(map.getCenter);
|
||||
map.panInside(map.unproject(L.point(br.x + 20, br.y)), opts);
|
||||
expect(center).to.not.eql(map.getCenter());
|
||||
});
|
||||
|
||||
it("pans on both X and Y axes when the target is outside of the view area and both the point's coords are outside the bounds", function () {
|
||||
|
Reference in New Issue
Block a user