diff --git a/demo/main-bundle.js b/demo/main-bundle.js index e432af3..3d63a04 100644 --- a/demo/main-bundle.js +++ b/demo/main-bundle.js @@ -801,7 +801,7 @@ function svgPointToCoordinate(point, svgMeta, options, svgTransform) { point1 = new Vector2_1.default(transformedPoint.x, transformedPoint.y); } var aspect = svgMeta.width / svgMeta.height; - var outputPoint = new Vector2_1.default((point1.x - svgMeta.x) / (svgMeta.width * aspect), (point1.y - svgMeta.y) / svgMeta.height); + var outputPoint = new Vector2_1.default((point1.x - svgMeta.x) / svgMeta.width, (point1.y - svgMeta.y) / (svgMeta.height * aspect)); var scale = options.width / constants_1.EARTH_CIRCUMFERENCE; var centerPoint = (0, projections_1.mercator)({ lon: options.center.longitude, lat: options.center.latitude }); outputPoint = outputPoint diff --git a/dist/utils.js b/dist/utils.js index ac8f7d1..b42799a 100644 --- a/dist/utils.js +++ b/dist/utils.js @@ -38,7 +38,7 @@ function svgPointToCoordinate(point, svgMeta, options, svgTransform) { point1 = new Vector2_1.default(transformedPoint.x, transformedPoint.y); } var aspect = svgMeta.width / svgMeta.height; - var outputPoint = new Vector2_1.default((point1.x - svgMeta.x) / (svgMeta.width * aspect), (point1.y - svgMeta.y) / svgMeta.height); + var outputPoint = new Vector2_1.default((point1.x - svgMeta.x) / svgMeta.width, (point1.y - svgMeta.y) / (svgMeta.height * aspect)); var scale = options.width / constants_1.EARTH_CIRCUMFERENCE; var centerPoint = (0, projections_1.mercator)({ lon: options.center.longitude, lat: options.center.latitude }); outputPoint = outputPoint diff --git a/dist/utils.js.map b/dist/utils.js.map index 5077e2f..0d3ff2e 100644 --- a/dist/utils.js.map +++ b/dist/utils.js.map @@ -1 +1 @@ -{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AACvC,qDAAuD;AAEvD,qCAAgC;AAChC,2CAAgD;AAChD,yCAAkD;AAElD,SAAgB,aAAa,CAC3B,QAA0B,EAC1B,EAA0B,EAC1B,UAAqC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AAG,WAAW,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CACxE,CAAC;KACH;IAED,WAAW,GAAG,WAAW,CAAC,GAAG,CAAC,WAAsB,CAAC,CAAC;IAEtD,WAAW,GAAG,IAAI,iBAAO,CACvB,IAAA,kBAAK,EAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC1B,IAAA,kBAAK,EAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAC3B,CAAC;IAEF,IAAM,cAAc,GAAG,IAAA,sBAAQ,EAAC,WAAW,CAAC,CAAC;IAC7C,OAAO,CAAC,cAAc,CAAC,GAAG,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;AAClD,CAAC;AA3CD,oDA2CC"} \ No newline at end of file diff --git a/docs/functions/convertSVG.html b/docs/functions/convertSVG.html index 0401dcc..ec7205c 100644 --- a/docs/functions/convertSVG.html +++ b/docs/functions/convertSVG.html @@ -1 +1 @@ -convertSVG | svg-plotter

Function convertSVG

+convertSVG | svg-plotter

Function convertSVG

diff --git a/docs/functions/getSVGMetadata.html b/docs/functions/getSVGMetadata.html index c9468de..417023c 100644 --- a/docs/functions/getSVGMetadata.html +++ b/docs/functions/getSVGMetadata.html @@ -1 +1 @@ -getSVGMetadata | svg-plotter

Function getSVGMetadata

  • Parameters

    • parsedSVG: INode

    Returns SVGMetaData

+getSVGMetadata | svg-plotter

Function getSVGMetadata

  • Parameters

    • parsedSVG: INode

    Returns SVGMetaData

diff --git a/docs/interfaces/convertsvgoutput.html b/docs/interfaces/convertsvgoutput.html index 368c3df..4ffcb3b 100644 --- a/docs/interfaces/convertsvgoutput.html +++ b/docs/interfaces/convertsvgoutput.html @@ -1,3 +1,3 @@ -ConvertSVGOutput | svg-plotter

Interface ConvertSVGOutput

interface ConvertSVGOutput {
    errors: string[];
    geojson: FeatureCollection<Geometry, {
        [name: string]: any;
    }>;
}

Properties

errors +ConvertSVGOutput | svg-plotter

Interface ConvertSVGOutput

interface ConvertSVGOutput {
    errors: string[];
    geojson: FeatureCollection<Geometry, {
        [name: string]: any;
    }>;
}

Properties

Properties

errors: string[]
geojson: FeatureCollection<Geometry, {
    [name: string]: any;
}>
+

Properties

errors: string[]
geojson: FeatureCollection<Geometry, {
    [name: string]: any;
}>
diff --git a/src/utils.ts b/src/utils.ts index 36624c1..5d981d8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -52,8 +52,8 @@ export function svgPointToCoordinate( // Normalize point to [0,1] range const aspect = svgMeta.width / svgMeta.height; let outputPoint = new Vector2( - (point1.x - svgMeta.x) / (svgMeta.width * aspect), - (point1.y - svgMeta.y) / svgMeta.height, + (point1.x - svgMeta.x) / svgMeta.width, + (point1.y - svgMeta.y) / (svgMeta.height * aspect), ); // Scale, rotate, and offset point const scale = options.width / EARTH_CIRCUMFERENCE; diff --git a/tests/svg-plotter.spec.ts b/tests/svg-plotter.spec.ts index 09e2ec2..077f709 100644 --- a/tests/svg-plotter.spec.ts +++ b/tests/svg-plotter.spec.ts @@ -65,7 +65,10 @@ describe('svg-plotter', () => { expect(errors).to.be.empty; const expectedSVGType = ['rect', 'rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'path']; geojson.features.forEach((f, i) => { - expect(f.properties.svgType).to.equal(expectedSVGType[i]); + expect(f.properties).to.not.be.null; + if (f.properties) { + expect(f.properties.svgType).to.equal(expectedSVGType[i]); + } }); }); @@ -79,7 +82,7 @@ describe('svg-plotter', () => { }); it('should return a list of errors that include all skipped geometry.', () => { - const { geojson, errors } = convertSVG(SVG_PATTERN); + const { errors } = convertSVG(SVG_PATTERN); expect(errors).to.include('Skipping unsupported node: pattern'); }); diff --git a/tests/transformers/polygon.spec.ts b/tests/transformers/polygon.spec.ts index e20c403..280ab61 100644 --- a/tests/transformers/polygon.spec.ts +++ b/tests/transformers/polygon.spec.ts @@ -25,17 +25,17 @@ describe('transformer: polygon', () => { if (polygonFeature.geometry.type == "Polygon") { expect(polygonFeature.geometry.coordinates).to.deep.equal([ [ - [-122.39999999999999, -72.73278609432643], - [-116.64, -80.73800862798672], - [-99.36000000000001, -80.73800862798672], - [-110.88, -83.22814054417216], - [-105.12000000000002, -85.10173601678947], - [-122.39999999999999, -84.21070904403568], - [-139.68, -85.10173601678947], - [-133.92, -83.22814054417216], - [-145.44000000000003, -80.73800862798672], - [-128.16, -80.73800862798672], - [-122.39999999999999, -72.73278609432643] + [-108, -44.92996307231136], + [-100.80000000000001, -61.81964504535566], + [-79.19999999999999, -61.81964504535566], + [-93.60000000000001, -67.90729697116636], + [-86.4, -74.74627295233269], + [-108, -70.46268063408844], + [-129.60000000000002, -74.74627295233269], + [-122.39999999999999, -67.90729697116636], + [-136.79999999999998, -61.81964504535566], + [-115.20000000000002, -61.81964504535566], + [-108, -44.92996307231136], ] ]); } diff --git a/tests/transformers/polyline.spec.ts b/tests/transformers/polyline.spec.ts index 27a0bfc..15e1e9c 100644 --- a/tests/transformers/polyline.spec.ts +++ b/tests/transformers/polyline.spec.ts @@ -24,15 +24,15 @@ describe('transformer: polyline', () => { expect(polylineFeature.geometry.type).to.equal("LineString"); if (polylineFeature.geometry.type == "LineString") { expect(polylineFeature.geometry.coordinates).to.deep.equal([ - [-110.88, -17.711014416582245], - [-105.12000000000002, -33.841220320476765], - [-99.36000000000001, -26.05283495188394], - [-93.60000000000001, -47.422140992876095], - [-87.84, -40.97989806962015], - [-82.08, -58.22628219768537], - [-76.32000000000001, -53.16258159476075], - [-70.56, -66.51326044311186], - [-64.80000000000001, -62.658000452319406], + [-93.60000000000001, 21.105820224194197], + [-86.4, 7.181124828276247], + [-79.19999999999999, 14.25075373529648], + [-72, -7.181124828276273], + [-64.80000000000001, 0], + [-57.599999999999994, -21.105820224194215], + [-50.400000000000006, -14.2507537352965], + [-43.2, -33.841220320476765], + [-35.99999999999999, -27.658619791226744], ]); } });