Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix/17086-mapline-in-non-topojson #18130

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions samples/unit-tests/maps/mappoint/demo.js
Expand Up @@ -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);
Expand Down
25 changes: 24 additions & 1 deletion ts/Series/Map/MapPoint.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down