Merge pull request #2977 from yohanboniface/geojson-edge-case
Fix array of array of LatLngs toGeoJSON edge case
This commit is contained in:
commit
9923e4bb91
@ -120,7 +120,7 @@ describe("L.Polyline (multi) #toGeoJSON", function () {
|
||||
});
|
||||
|
||||
describe("L.Polygon#toGeoJSON", function () {
|
||||
it("returns a 2D Polygon object (no holes)", function () {
|
||||
it("returns a 2D Polygon object (no holes) from a flat LatLngs array", function () {
|
||||
var polygon = new L.Polygon([[1, 2], [3, 4], [5, 6]]);
|
||||
expect(polygon.toGeoJSON().geometry).to.eql({
|
||||
type: 'Polygon',
|
||||
@ -128,7 +128,7 @@ describe("L.Polygon#toGeoJSON", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a 3D Polygon object (no holes)", function () {
|
||||
it("returns a 3D Polygon object (no holes) from a flat LatLngs array", function () {
|
||||
var polygon = new L.Polygon([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
|
||||
expect(polygon.toGeoJSON().geometry).to.eql({
|
||||
type: 'Polygon',
|
||||
@ -136,6 +136,26 @@ describe("L.Polygon#toGeoJSON", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a 2D Polygon object from a simple GeoJSON like input", function () {
|
||||
var multiPolygon = new L.Polygon([[[1, 2], [3, 4], [5, 6]]]);
|
||||
expect(multiPolygon.toGeoJSON().geometry).to.eql({
|
||||
type: 'Polygon',
|
||||
coordinates: [
|
||||
[[2, 1], [4, 3], [6, 5], [2, 1]]
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a 3D MultiPolygon object from a simple GeoJSON like input", function () {
|
||||
var multiPolygon = new L.Polygon([[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]);
|
||||
expect(multiPolygon.toGeoJSON().geometry).to.eql({
|
||||
type: 'Polygon',
|
||||
coordinates: [
|
||||
[[2, 1, 3], [5, 4, 6], [8, 7, 9], [2, 1, 3]]
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a 2D Polygon object (with holes)", function () {
|
||||
var polygon = new L.Polygon([[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]]]);
|
||||
expect(polygon.toGeoJSON().geometry).to.eql({
|
||||
@ -157,11 +177,12 @@ describe("L.Polygon#toGeoJSON", function () {
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("L.Polygon (multi) #toGeoJSON", function () {
|
||||
it("returns a 2D MultiPolygon object", function () {
|
||||
var multiPolygon = new L.Polygon([[[1, 2], [3, 4], [5, 6]]]);
|
||||
var multiPolygon = new L.Polygon([[[[1, 2], [3, 4], [5, 6]]]]);
|
||||
expect(multiPolygon.toGeoJSON().geometry).to.eql({
|
||||
type: 'MultiPolygon',
|
||||
coordinates: [
|
||||
@ -171,7 +192,7 @@ describe("L.Polygon (multi) #toGeoJSON", function () {
|
||||
});
|
||||
|
||||
it("returns a 3D MultiPolygon object", function () {
|
||||
var multiPolygon = new L.Polygon([[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]);
|
||||
var multiPolygon = new L.Polygon([[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]]);
|
||||
expect(multiPolygon.toGeoJSON().geometry).to.eql({
|
||||
type: 'MultiPolygon',
|
||||
coordinates: [
|
||||
@ -179,6 +200,28 @@ describe("L.Polygon (multi) #toGeoJSON", function () {
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a 2D MultiPolygon object with two polygons", function () {
|
||||
var multiPolygon = new L.Polygon([[[[1, 2], [3, 4], [5, 6]]], [[[7, 8], [9, 10], [11, 12]]]]);
|
||||
expect(multiPolygon.toGeoJSON().geometry).to.eql({
|
||||
type: 'MultiPolygon',
|
||||
coordinates: [
|
||||
[[[2, 1], [4, 3], [6, 5], [2, 1]]],
|
||||
[[[8, 7], [10, 9], [12, 11], [8, 7]]]
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a 2D MultiPolygon object with polygon having a hole", function () {
|
||||
var multiPolygon = new L.Polygon([[[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]]]]);
|
||||
expect(multiPolygon.toGeoJSON().geometry).to.eql({
|
||||
type: 'MultiPolygon',
|
||||
coordinates: [
|
||||
[[[2, 1], [4, 3], [6, 5], [2, 1]], [[8, 7], [10, 9], [12, 11], [8, 7]]]
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("L.LayerGroup#toGeoJSON", function () {
|
||||
|
@ -206,10 +206,6 @@ L.Polygon.prototype.toGeoJSON = function () {
|
||||
|
||||
var coords = L.GeoJSON.latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true);
|
||||
|
||||
if (holes && this._latlngs.length === 1) {
|
||||
multi = true;
|
||||
coords = [coords];
|
||||
}
|
||||
if (!holes) {
|
||||
coords = [coords];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user