Skip to content

Commit

Permalink
toGeoJSON() should still work if no values in coords array (#8737)
Browse files Browse the repository at this point in the history
  • Loading branch information
Falke-Design committed Dec 22, 2022
1 parent 11049bc commit f42cab9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions spec/suites/layer/GeoJSONSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,11 @@ describe("L.GeoJSON functions", function () {
expect(coords).to.eql([[1, 2, 3], [4, 5, 6], [1, 2, 3]]);
expect(coords[0] === coords[2]).to.not.ok();
});
it('still works if no values in coords array', () => {
expect(function () {
L.GeoJSON.latLngsToCoords([[]], 1, true);
}).to.not.throwException();
});
});

describe("#asFeature", function () {
Expand Down
2 changes: 1 addition & 1 deletion src/layer/GeoJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export function latLngsToCoords(latlngs, levelsDeep, closed, precision) {
latLngToCoords(latlngs[i], precision));
}

if (!levelsDeep && closed) {
if (!levelsDeep && closed && coords.length > 0) {
coords.push(coords[0].slice());
}

Expand Down

0 comments on commit f42cab9

Please sign in to comment.