diff --git a/rollup.config.js b/rollup.config.js index 3008550..8dbe29f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -45,7 +45,7 @@ const bundle = (format, filename, options = {}) => ({ export default [ bundle('cjs', pkg.main), - bundle('es', pkg.module), + bundle('esm', pkg.module), bundle('umd', pkg.browser.replace('.min', ''), { resolve: true, stats: true }), bundle('umd', pkg.browser, { resolve: true, minimize: true }), ]; \ No newline at end of file diff --git a/spec/geodesic-circle.test.ts b/spec/geodesic-circle.test.ts index 1eb12f9..2f348d0 100644 --- a/spec/geodesic-circle.test.ts +++ b/spec/geodesic-circle.test.ts @@ -19,6 +19,20 @@ const defaultOptions: GeodesicOptions = { wrap: true, steps: 24, fill: true, noC const eps = 0.000001; +function checkFixture(specimen: L.LatLngLiteral[][], fixture: L.LatLngLiteral[][]): void { + expect(specimen).to.be.an("array"); + expect(specimen).to.be.length(fixture.length); + specimen.forEach((line, k) => { + expect(line).to.be.length(fixture[k].length); + line.forEach((point, l) => { + expect(point).to.be.an("object"); + expect(point).to.include.all.keys("lat", "lng"); + expect(point.lat).to.be.closeTo(fixture[k][l].lat, eps); + expect(point.lng).to.be.closeTo(fixture[k][l].lng, eps); + }); + }); +} + describe("Main functionality", function () { let map: L.Map; const radius = 1000 * 1000; @@ -100,4 +114,35 @@ describe("Main functionality", function () { expect(circle.statistics.vertices).to.be.equal(25); }); +}); + +describe("Bugs", function () { + let map: L.Map; + + beforeEach(function () { + map = L.map(document.createElement('div')); + }); + + afterEach(function () { + map.remove(); + }); + + it("Calling getBounds on a GeodesicCircle throws an error (#48)", async function () { + const circle = new GeodesicCircleClass(Seattle, { radius: 10}); + const group = new L.FeatureGroup([circle]).addTo(map); + + expect(circle.options).to.be.deep.equal({ ...defaultOptions, ...{ radius: 10 } }); + expect(circle.polyline).to.be.an("object"); + expect(circle.center.lat).to.be.closeTo(Seattle.lat, eps); + expect(circle.center.lng).to.be.closeTo(Seattle.lng, eps); + + expect(map.hasLayer(group)).to.be.true; + map.eachLayer(function (layer) { + expect(layer).to.be.instanceOf(L.FeatureGroup); + }); + + const bounds = group.getBounds(); + expect(bounds).to.be.instanceOf(L.LatLngBounds); + checkFixture([[bounds.getCenter()]], [[Seattle]]); + }); }); \ No newline at end of file diff --git a/spec/geodesic-line.test.ts b/spec/geodesic-line.test.ts index b6e66a8..3f04f24 100644 --- a/spec/geodesic-line.test.ts +++ b/spec/geodesic-line.test.ts @@ -265,3 +265,32 @@ describe("GeoJSON-Support", function () { expect(mockLog.mock.calls[0][0]).to.match(/Type "GeometryCollection" not supported/); }); }); + +describe("Re-Implementing Layer-Functions", function () { + let map: L.Map; + + beforeEach(function () { + map = L.map(document.createElement('div')); + }); + + afterEach(function () { + map.remove(); + }); + + it("getBounds()", async function () { + const line = new GeodesicLine([FlindersPeak, Buninyong]); + const group = new L.FeatureGroup([line]).addTo(map); + + expect(line.options).to.be.deep.equal(defaultOptions); + expect(line.polyline).to.be.an("object"); + + expect(map.hasLayer(group)).to.be.true; + map.eachLayer(function (layer) { + expect(layer).to.be.instanceOf(L.FeatureGroup); + }); + + const bounds = group.getBounds(); + expect(bounds).to.be.instanceOf(L.LatLngBounds); + checkFixture([[bounds.getCenter()]], [[{lat: (FlindersPeak.lat+Buninyong.lat)/2, lng: (FlindersPeak.lng+Buninyong.lng)/2}]]); + }); +}); \ No newline at end of file diff --git a/src/geodesic-circle.ts b/src/geodesic-circle.ts index ab35746..95a4dad 100644 --- a/src/geodesic-circle.ts +++ b/src/geodesic-circle.ts @@ -43,6 +43,10 @@ export class GeodesicCircleClass extends L.Layer { return this; } + getBounds(): L.LatLngBounds { + return this.polyline.getBounds(); + } + private update(): void { const latlngs = this.geom.circle(this.center, this.radius); diff --git a/src/geodesic-line.ts b/src/geodesic-line.ts index 9ec6b47..a5c516e 100644 --- a/src/geodesic-line.ts +++ b/src/geodesic-line.ts @@ -43,6 +43,10 @@ export class GeodesicLine extends L.Layer { return this; } + getBounds(): L.LatLngBounds { + return this.polyline.getBounds(); + } + private updateLatLngs(latlngs: L.LatLngExpression[] | L.LatLngExpression[][]): void { const latLngLiteral = latlngExpressionArraytoLiteralArray(latlngs); const geodesic = this.geom.multiLineString(latLngLiteral);