Skip to content

Commit

Permalink
Fix GeoJSON to cover 180th meridian quirk
Browse files Browse the repository at this point in the history
See mapbox/mapbox-gl-js#3250 (comment) and related thread for further info
  • Loading branch information
frederickobrien committed Dec 5, 2022
1 parent e31d8ff commit f6d4e20
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions data/books/convert-routes-to-geojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit f6d4e20

Please sign in to comment.