feat: add antimeridian output option for dateline-crossing routes - #19
Merged
Conversation
mayurrawte
force-pushed
the
feat/issue-9-antimeridian
branch
from
July 3, 2026 07:57
f50d6e9 to
8986583
Compare
Routes that cross the ±180° antimeridian (e.g. Yokohama -> LA) come back wrapped to [-180, 180], so a segment jumps from +179 to -179 and map renderers draw a straight streak across the whole map. Add an `antimeridian` option to `seaRoute` and `seaRouteMulti`: - 'unwrap' -> one continuous LineString, longitudes shifted by multiples of 360° so the line never jumps the dateline (may exceed ±180°). - 'split' -> a MultiLineString cut at ±180°, keeping every coordinate in range (RFC 7946-friendly). The default is unchanged (wrapped LineString), so this is non-breaking. Return types are narrowed by overload: 'split' yields a SeaRouteMultiFeature. The split routine works on unwrapped coordinates and handles vertices that sit exactly on the dateline (the bundled network normalizes ±180° vertices). New exports: Antimeridian, SeaRouteMultiFeature.
mayurrawte
force-pushed
the
feat/issue-9-antimeridian
branch
from
July 3, 2026 08:28
8986583 to
f5453aa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Routes crossing the ±180° antimeridian (e.g. Yokohama → LA) come back wrapped to
[-180, 180], so a segment jumps from+179to-179. Fed straight into MapLibre / Leaflet / Deck.gl, that draws as a straight streak across the whole map instead of across the Pacific. This was already solved for our own demo (examples/web-demo/src/geo.ts); this PR moves the capability into the library so downstream map consumers don't each rediscover it.What changed
New
antimeridianoption onseaRouteandseaRouteMulti:undefined— current behaviour, wrappedLineString(no breaking change).'unwrap'— one continuousLineString; longitudes shifted by multiples of 360° so consecutive points never jump the dateline (the demo's approach).'split'— aMultiLineStringcut at ±180°, keeping every coordinate within ±180° (RFC 7946-friendly), inserting the interpolated dateline point at both ends of each cut.Details:
src/lib/antimeridian.tswithunwrapCoords/splitAtAntimeridian.{ antimeridian: 'split' }returns the newSeaRouteMultiFeature(Feature<MultiLineString, …>); everything else still returnsSeaRouteFeature. So existing TS consumers see no type change.seaRouteMultiapplies the option once to the concatenated route (legs are computed as plain wrapped LineStrings so they still join cleanly).seaRouteAlternativescontinues to return wrappedLineStrings (documented).properties.lengthandbboxare computed from the geodesic path and are unaffected by the representation.Antimeridian,SeaRouteMultiFeature. README / DOCS / CHANGELOG updated.One subtlety worth noting
The bundled network normalizes
lon === 180vertices to-180, so a trans-Pacific route can pass through a vertex sitting exactly on the dateline.splitAtAntimeridianworks in unwrapped space and assigns each sub-line a 360°-panel offset, so boundary-coincident vertices are handled as crossings (and de-duplicated) rather than being dropped — verified against Yokohama → LA (vertex on 180) and Sydney → Vancouver (interpolated crossing at lat 0).Validation
All steps CI runs, from a clean tree:
npm cinpm run lint✅npm run format:check✅npm run build✅npm test✅ (50 tests; 6 new covering unwrap continuity, split cut points at ±180 with continuous latitude, all coords within ±180, non-crossing routes unchanged,seaRouteMultisplit, and alternatives stayingLineString)Also verified end-to-end against the built
dist(CJS + ESM) that unwrap removes all dateline jumps and split produces valid in-rangeMultiLineStringgeometry with length preserved.Closes #9