PolygonSpec.js (Leaflet-1.8.0) | : | PolygonSpec.js (Leaflet-1.9.0) | ||
---|---|---|---|---|
skipping to change at line 157 | skipping to change at line 157 | |||
}); | }); | |||
}); | }); | |||
describe('#getCenter', function () { | describe('#getCenter', function () { | |||
it('should compute center of a big simple polygon around equator' , function () { | it('should compute center of a big simple polygon around equator' , function () { | |||
var latlngs = [ | var latlngs = [ | |||
[[0, 0], [10, 0], [10, 10], [0, 10]] | [[0, 0], [10, 0], [10, 10], [0, 10]] | |||
]; | ]; | |||
var layer = L.polygon(latlngs).addTo(map); | var layer = L.polygon(latlngs).addTo(map); | |||
expect(layer.getCenter()).to.be.nearLatLng([5, 5], 1e-1); | expect(layer.getCenter()).to.be.nearLatLng([5.01914809902 5293, 5]); | |||
}); | }); | |||
it('should compute center of a small simple polygon', function () { | it('should compute center of a small simple polygon', function () { | |||
var latlngs = [ | var latlngs = [ | |||
[[0, 0], [0.010, 0], [0.010, 0.010], [0, 0.010]] | [[0, 0], [0.010, 0], [0.010, 0.010], [0, 0.010]] | |||
]; | ]; | |||
var layer = L.polygon(latlngs).addTo(map); | var layer = L.polygon(latlngs).addTo(map); | |||
map.setZoom(0); // Make the polygon disappear in screen. | map.setZoom(0); // Make the polygon disappear in screen. | |||
expect(layer.getCenter()).to.be.nearLatLng([0, 0]); | expect(layer.getCenter()).to.be.nearLatLng([0.005, 0.005] ); | |||
}); | }); | |||
it('throws error if not yet added to map', function () { | it('throws error if not yet added to map', function () { | |||
expect(function () { | expect(function () { | |||
var latlngs = [ | var latlngs = [ | |||
[[0, 0], [10, 0], [10, 10], [0, 10]] | [[0, 0], [10, 0], [10, 10], [0, 10]] | |||
]; | ]; | |||
var layer = L.polygon(latlngs); | var layer = L.polygon(latlngs); | |||
layer.getCenter(); | layer.getCenter(); | |||
}).to.throwException('Must add layer to map before using getCenter()'); | }).to.throwException('Must add layer to map before using getCenter()'); | |||
}); | }); | |||
it('should compute same center for low and high zoom', function ( | ||||
) { | ||||
var latlngs = [ | ||||
[[0, 0], [0.010, 0], [0.010, 0.010], [0, 0.010]] | ||||
]; | ||||
var layer = L.polygon(latlngs).addTo(map); | ||||
map.setZoom(0); | ||||
var center = layer.getCenter(); | ||||
map.setZoom(18); | ||||
expect(layer.getCenter()).to.be.nearLatLng(center); | ||||
}); | ||||
it("should compute center for multi-polygon including hole", func | ||||
tion () { | ||||
var latlngs = [ | ||||
[[[10, 20], [30, 40], [50, 60]]], | ||||
[[[0, 10], [10, 10], [10, 0]], [[2, 3], [2, 4], [ | ||||
3, 4]]] | ||||
]; | ||||
var layer = L.polygon(latlngs).addTo(map); | ||||
expect(layer.getCenter()).to.be.nearLatLng([31.4365322969 | ||||
11807, 39.99999999999979]); | ||||
}); | ||||
}); | }); | |||
describe("#_defaultShape", function () { | describe("#_defaultShape", function () { | |||
it("should return latlngs on a simple polygon", function () { | it("should return latlngs on a simple polygon", function () { | |||
var latlngs = [ | var latlngs = [ | |||
L.latLng([1, 2]), | L.latLng([1, 2]), | |||
L.latLng([3, 4]) | L.latLng([3, 4]) | |||
]; | ]; | |||
var polygon = L.polygon(latlngs); | var polygon = L.polygon(latlngs); | |||
End of changes. 3 change blocks. | ||||
2 lines changed or deleted | 25 lines changed or added |