From 11f7e8d113fea3d494faef475b3c97e5bc8ebc2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Musia=C5=82owski?= Date: Mon, 12 Dec 2022 15:35:27 +0100 Subject: [PATCH 1/2] Fixed mapline series in non-TopoJSON maps. --- ts/Series/Map/MapPoint.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ts/Series/Map/MapPoint.ts b/ts/Series/Map/MapPoint.ts index 9335d90c5d5..6208728ad4f 100644 --- a/ts/Series/Map/MapPoint.ts +++ b/ts/Series/Map/MapPoint.ts @@ -19,7 +19,7 @@ import type { GeoJSONGeometryMultiPoint } from '../../Maps/GeoJSON'; import type MapPointOptions from './MapPointOptions'; import type MapSeries from './MapSeries'; -import type { MapBounds } from '../../Maps/MapViewOptions'; +import type { LonLatArray, MapBounds } from '../../Maps/MapViewOptions'; import type PointerEvent from '../../Core/PointerEvent'; import type { PointShortOptions } from '../../Core/Series/PointOptions'; import type Projection from '../../Maps/Projection'; @@ -93,10 +93,33 @@ class MapPoint extends ScatterSeries.prototype.pointClass { ): SVGPath { if (!point.projectedPath) { if (projection && point.geometry) { + const mapView = point.series.chart.mapView; // Always true when given GeoJSON coordinates projection.hasCoordinates = true; + // Change lat/lon to projected units in 'mapline' series on non + // topoJSON charts #17086 + if (point.geometry.type === 'LineString' && + !projection.hasGeoProjection) { + + let projectedCoords: LonLatArray[] = []; + const coordinates = point.geometry.coordinates; + + coordinates.forEach((coords): void => { + const newCoords = mapView && + mapView.lonLatToProjectedUnits({ + lon: coords[0], + lat: coords[1] + }); + + if (newCoords) { + projectedCoords.push([newCoords.x, newCoords.y]); + } + }); + + point.geometry.coordinates = projectedCoords; + } point.projectedPath = projection.path(point.geometry); // SVG path given directly in point options From b3006dfca7b2b2ddba94e8d1ae32fe28c3358abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Musia=C5=82owski?= Date: Mon, 12 Dec 2022 15:42:11 +0100 Subject: [PATCH 2/2] Added unit tests for mapline. --- samples/unit-tests/maps/mappoint/demo.js | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/samples/unit-tests/maps/mappoint/demo.js b/samples/unit-tests/maps/mappoint/demo.js index 01f6af9d389..b24298e14d2 100644 --- a/samples/unit-tests/maps/mappoint/demo.js +++ b/samples/unit-tests/maps/mappoint/demo.js @@ -60,6 +60,36 @@ QUnit.test('MapPoint with LineWidth', function (assert) { 'The proj4 library was loaded correctly from the chart.proj4 property' ); + const data = [ + [-0.1275, 51.507222], + [-1.893611, 52.483056] + ]; + + chart.series[1].update({ + type: 'mapline', + data: [{ + geometry: { + type: 'LineString', + coordinates: data, + color: 'red' + } + }] + }); + + const projectedData = data.map(coords => { + const { x, y } = chart.mapView.lonLatToProjectedUnits({ + lon: coords[0], + lat: coords[1] + }); + return [x, y]; + }); + + assert.deepEqual( + chart.series[1].data[0].geometry.coordinates, + projectedData, + 'Mapline series should have correct position on non TopoJSON chart.' + ); + } finally { window.proj4 = proj4Script; TestUtilities.lolexUninstall(clock);