Merge pull request #3455 from Leaflet/polyline-isempty
Add Polyline/Polygon.isEmpty method
This commit is contained in:
commit
983fce0fee
@ -75,6 +75,30 @@ describe('Polygon', function () {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#isEmpty", function () {
|
||||||
|
|
||||||
|
it('should return true for a polygon with no latlngs', function () {
|
||||||
|
var layer = new L.Polygon([]);
|
||||||
|
expect(layer.isEmpty()).to.be(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for simple polygon', function () {
|
||||||
|
var latLngs = [[1, 2], [3, 4], [5, 6]];
|
||||||
|
var layer = new L.Polygon(latLngs);
|
||||||
|
expect(layer.isEmpty()).to.be(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for a multi-polygon', function () {
|
||||||
|
var latLngs = [
|
||||||
|
[[[10, 20], [30, 40], [50, 60]]],
|
||||||
|
[[[0, 10], [10, 10], [10, 0]], [[2, 3], [2, 4], [3, 4]]]
|
||||||
|
];
|
||||||
|
var layer = new L.Polygon(latLngs);
|
||||||
|
expect(layer.isEmpty()).to.be(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe("#setLatLngs", function () {
|
describe("#setLatLngs", function () {
|
||||||
it("doesn't overwrite the given latlng array", function () {
|
it("doesn't overwrite the given latlng array", function () {
|
||||||
var originalLatLngs = [
|
var originalLatLngs = [
|
||||||
|
@ -49,6 +49,30 @@ describe('Polyline', function () {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#isEmpty", function () {
|
||||||
|
|
||||||
|
it('should return true for a polyline with no latlngs', function () {
|
||||||
|
var polyline = new L.Polyline([]);
|
||||||
|
expect(polyline.isEmpty()).to.be(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for simple polyline', function () {
|
||||||
|
var latLngs = [[1, 2], [3, 4]];
|
||||||
|
var polyline = new L.Polyline(latLngs);
|
||||||
|
expect(polyline.isEmpty()).to.be(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for multi-polyline', function () {
|
||||||
|
var latLngs = [
|
||||||
|
[[1, 2], [3, 4]],
|
||||||
|
[[11, 12], [13, 14]]
|
||||||
|
];
|
||||||
|
var polyline = new L.Polyline(latLngs);
|
||||||
|
expect(polyline.isEmpty()).to.be(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe("#setLatLngs", function () {
|
describe("#setLatLngs", function () {
|
||||||
it("doesn't overwrite the given latlng array", function () {
|
it("doesn't overwrite the given latlng array", function () {
|
||||||
var originalLatLngs = [
|
var originalLatLngs = [
|
||||||
|
@ -8,6 +8,10 @@ L.Polygon = L.Polyline.extend({
|
|||||||
fill: true
|
fill: true
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isEmpty: function () {
|
||||||
|
return !this._latlngs.length || !this._latlngs[0].length;
|
||||||
|
},
|
||||||
|
|
||||||
getCenter: function () {
|
getCenter: function () {
|
||||||
var i, j, p1, p2, f, area, x, y, center,
|
var i, j, p1, p2, f, area, x, y, center,
|
||||||
points = this._rings[0],
|
points = this._rings[0],
|
||||||
|
@ -25,6 +25,10 @@ L.Polyline = L.Path.extend({
|
|||||||
return this.redraw();
|
return this.redraw();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isEmpty: function () {
|
||||||
|
return !this._latlngs.length;
|
||||||
|
},
|
||||||
|
|
||||||
closestLayerPoint: function (p) {
|
closestLayerPoint: function (p) {
|
||||||
var minDistance = Infinity,
|
var minDistance = Infinity,
|
||||||
minPoint = null,
|
minPoint = null,
|
||||||
|
Loading…
Reference in New Issue
Block a user