Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Shape overlays are unable to cross antimeridian #4974

Closed
1ec5 opened this issue May 9, 2016 · 10 comments
Closed

Shape overlays are unable to cross antimeridian #4974

1ec5 opened this issue May 9, 2016 · 10 comments
Assignees
Labels
bug Core The cross-platform C++ core, aka mbgl
Milestone

Comments

@1ec5
Copy link
Contributor

1ec5 commented May 9, 2016

A polyline that straddles the antimeridian ends up taking the long way around the globe:

CLLocationCoordinate2D coords[2] = {
    CLLocationCoordinate2DMake(0, -170),
    CLLocationCoordinate2DMake(0, 170),
};
MGLPolyline *polyline = [MGLPolyline polylineWithCoordinates:coords count:sizeof(coords) / sizeof(coords[0])];
[mapView addOverlay:polyline];

mapbox

The corresponding MapKit code does straddle the antimeridian:

mapkit

Also reproduces with polygons.

This is a very old bug that has reproduced in the iOS SDK since shape annotations were first implemented in #1655, but I was unable to find a ticket that adequately addresses it. The diagnosis in #3879 (comment) probably applies here, even though point annotations are apparently unaffected as of #4285.

/cc @jfirebaugh @tobrun @bleege

@1ec5 1ec5 added bug Core The cross-platform C++ core, aka mbgl labels May 9, 2016
@bleege
Copy link
Contributor

bleege commented May 9, 2016

Confirming that this also impacts the Android SDK as the corresponding code produces a similar screenshot.

// Android Binding Code
List<LatLng> points = Arrays.asList(new LatLng(0, -170), new LatLng(0, 170));
mapboxMap.addPolyline(new PolylineOptions().addAll(points));

This translates to the Core GL level by MapboxMap.addPolyline() calling MapView.addPolyline() which in turn calls addShapeAnnotations() in Core GL to do the rendering.

android-antimeridian-polyline

@tmcw
Copy link
Contributor

tmcw commented May 12, 2016

Can you do

CLLocationCoordinate2D coords[2] = {
    CLLocationCoordinate2DMake(0, -170),
    CLLocationCoordinate2DMake(0, -190),
};
MGLPolyline *polyline = [MGLPolyline polylineWithCoordinates:coords count:sizeof(coords) / sizeof(coords[0])];
[mapView addOverlay:polyline];

MapKit may be doing some kind of guessing/snapping here but Mapbox GL JS certainly doesn't - much like GeoJSON that crosses the antimeridian, the only unambiguous way to represent this geometry is with coordinates >180 or <-180

@sgillies
Copy link

sgillies commented May 12, 2016

@tmcw latest revision to the GeoJSON draft says

In representing features that cross the antimeridian, interoperability is improved by modifying their geometry. Any geometry that crosses the antimeridian SHOULD be represented by cutting it in two such that neither part's representation crosses the antimeridian.

https://github.com/geojson/draft-geojson/blob/master/middle.mkd#antimeridian-cutting

@1ec5
Copy link
Contributor Author

1ec5 commented May 12, 2016

If we were to require the use of longitudes beyond ±180° in order to add such features, I think that would be fine from a developer standpoint. Ideally, we'd handle the job of partitioning the feature along the antimeridian for the developer.

@tbernas
Copy link

tbernas commented Aug 3, 2016

@1ec5 Do we have an update on a fix to this issue? We've seen this issue materialize with actual storm tracks in our development environment. See attached.
img_8181
img_8180

@incanus
Copy link
Contributor

incanus commented Aug 4, 2016

Is a possible workaround to:

  1. See if start and end longitude are within 90 degrees of each other.
  2. See if they straddle the -180/180 antemeridian.
  3. If so, swap pairs west-to-east if needed.

@1ec5
Copy link
Contributor Author

1ec5 commented Aug 5, 2016

Step 3 doesn't look sound. If I'm not mistaken, you'd get the same result as the current behavior.

@mourner
Copy link
Member

mourner commented Aug 18, 2016

The right workaround will be too add or subtract 360 to longitudes that are "too far" away, e.g. so that the example [-170,0], [170,0] above will become [190,0], [170,0] or [-190,0], [-170,0]. Combined with a fix in mapbox/geojson-vt-cpp#57, this should cover all use cases.

@boundsj
Copy link
Contributor

boundsj commented Aug 19, 2016

Closing this. The solution noted by @mourner along with the fix in geojson-vt-cpp works.

@boundsj boundsj closed this as completed Aug 19, 2016
@1ec5
Copy link
Contributor Author

1ec5 commented Dec 6, 2016

Noting that the workaround is no longer needed, now that mapbox/geojson-vt-cpp#57 has landed in #6088.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

No branches or pull requests

8 participants