From f6d4e20d4fa712bdaadc2ce4194664a9c97bd1a9 Mon Sep 17 00:00:00 2001 From: frederickobrien Date: Mon, 5 Dec 2022 02:26:53 +0000 Subject: [PATCH] Fix GeoJSON to cover 180th meridian quirk See https://github.com/mapbox/mapbox-gl-js/issues/3250#issuecomment-294887678 and related thread for further info --- data/books/convert-routes-to-geojson.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/data/books/convert-routes-to-geojson.ts b/data/books/convert-routes-to-geojson.ts index 2a8c4fc..3569af4 100644 --- a/data/books/convert-routes-to-geojson.ts +++ b/data/books/convert-routes-to-geojson.ts @@ -12,9 +12,20 @@ csvsInDir.forEach((file) => { .formatValueByType() .getJsonFromCsv(file); - const fullRoute = bookJson.map((entry) => { - const coords = [entry.Longitude, entry.Latitude]; - return coords; + const fullRoute = bookJson.map((entry, i) => { + if (i === 0) return [entry.Longitude, entry.Latitude]; + else { + const previousLongitude = bookJson[i - 1].Longitude; + const latitude = entry.Latitude; + const longitude = (entry.Longitude += + entry.Longitude - previousLongitude > 180 + ? -360 + : previousLongitude - entry.Longitude > 180 + ? 360 + : 0); + const coords = [longitude, latitude]; + return coords; + } }); const geoJson = {