Skip to content

fix: Handle geojson features that cross antimeridian in computeBbox#7891

Open
camdecoster wants to merge 5 commits into
v4.0from
cam/4436/handle-geojson-antimeridian
Open

fix: Handle geojson features that cross antimeridian in computeBbox#7891
camdecoster wants to merge 5 commits into
v4.0from
cam/4436/handle-geojson-antimeridian

Conversation

@camdecoster

@camdecoster camdecoster commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

Update computeBbox to handle geojson features that cross the antimeridian.

Closes #4436.

Changes

  • Use d3-geo to get coords for features that cross the antimeridian instead of turn/bbox
  • Update computeBbox call sites
  • Add/update tests

Testing

  • Be on master
  • Load Plotly devtools
  • Paste the following snippet into the browser devtools console
    Plotly.newPlot(gd, [{
        type: 'choropleth',
        locations: ['RUS'],
        z: [1],
        colorscale: [[0, '#c33'], [1, '#c33']],
        showscale: false
    }], {
        geo: { fitbounds: 'locations', projection: { type: 'equirectangular' } },
        width: 700,
        height: 500,
        margin: { l: 0, r: 0, t: 0, b: 0 }
    });
  • Note that the plot spans the whole world
  • Switch to this branch
  • Run the snippet again
  • Note that the plot spans only Asia

Screenshots

Before After
image image

Notes

  • This has been a long-standing TODO (from 2019)
  • @turf/bbox doesn't handle geometry that spans the antimeridian and there's been no movement to fix that issue
  • This update uses a D3 utility (d3-geo.geoBounds, that does work with the antimeridian) to do the same thing (along with a turf utility used within @turf/bbox)
  • This could be considered a breaking change as some plots will show something different for the same config

@camdecoster camdecoster self-assigned this Jul 6, 2026
@camdecoster camdecoster added this to the v4.0.0 milestone Jul 6, 2026
@camdecoster camdecoster marked this pull request as ready for review July 6, 2026 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant