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

Polyline annotations have miter join #7714

Closed
andrewstay opened this issue Jan 13, 2017 · 9 comments
Closed

Polyline annotations have miter join #7714

andrewstay opened this issue Jan 13, 2017 · 9 comments
Assignees
Labels
annotations Annotations on iOS and macOS or markers on Android bug iOS Mapbox Maps SDK for iOS needs discussion
Milestone

Comments

@andrewstay
Copy link

Platform: iOS
Mapbox SDK version: ios-v3.4.0-beta.7

Steps to trigger behavior

  1. Instantiate MGLMapView
  2. Set a delegate
  3. Instantiate MGLPolyline as following:
            CLLocationCoordinate2D nw = //make coordinate
            CLLocationCoordinate2D ne =  //make coordinate
            CLLocationCoordinate2D se =  //make coordinate
            CLLocationCoordinate2D sw =  //make coordinate
            CLLocationCoordinate2D points[5] = {nw, ne, se, sw, nw};
            MGLPolyline *line = [MGLPolyline polylineWithCoordinates:points count:5];
  1. Add overlay to the map
  2. Return 20.0f for the line width in -[MGLMapViewDelegate mapView:lineWidthForPolylineAnnotation:]

Expected behavior

Line should be either smoothly joined or the join style should be somehow exposed by SDK to the client

Actual behavior

Bad line joining
screen shot 2017-01-13 at 12 05 55

@tobrun tobrun added the iOS Mapbox Maps SDK for iOS label Jan 13, 2017
@boundsj boundsj added annotations Annotations on iOS and macOS or markers on Android bug labels Jan 13, 2017
@boundsj boundsj added this to the ios-3.4.1 milestone Jan 13, 2017
@boundsj
Copy link
Contributor

boundsj commented Jan 13, 2017

Thanks @andrewstay. Can you say if there is a reason you are not using the new (in 3.4.0) runtime styling API? That API would allow you to fully control line joins, caps, etc.

@1ec5
Copy link
Contributor

1ec5 commented Jan 13, 2017

This seems to be a regression from v3.3.0. You can see the original behavior in #1771 (comment): not perfect in all cases, but better than what you’re seeing. See also #1734 (comment), which would’ve exposed more styling options for annotations.

As @boundsj notes, the runtime styling API provides many more styling options for polylines. That API should serve as a workaround for this issue, and indeed you may find that it better suits your needs than the annotation API.

/cc @incanus

@1ec5 1ec5 changed the title MGLPolyline does not join line properly Polyline annotations have miter join Jan 13, 2017
@boundsj boundsj added the bug label Jan 13, 2017
@jmkiley
Copy link
Contributor

jmkiley commented Jan 20, 2017

There also seems to be an issue with the way that line ends meet with MGLPolylineFeatures, but there is a possible workaround.

Here is the code that I used: https://gist.github.com/jmkiley/7296db34d52a51f5b1b2b4ebee1e903f

The corner looks fine initially, but the line overlap becomes visible once you zoom in:

screenshot 2017-01-20 11 16 16 screenshot 2017-01-20 11 16 41

The other corners render as expected for both MGLPolylineFeature and MGLPolyline:

screenshot 2017-01-20 11 21 50

One potential workaround is to use a MGLPolylineFeature with MGLLineCapButt, then have the line ends meet at a straight portion of the line.

screenshot 2017-01-20 14 13 56

@1ec5 1ec5 modified the milestones: ios-v3.5.0, ios-v3.4.1 Jan 24, 2017
@1ec5
Copy link
Contributor

1ec5 commented Jan 24, 2017

Thanks @jmkiley – apparently I misread the original issue description. It looks like we automatically produce a miter join at some zoom levels but fail to do so at other zoom levels, which is surprising. Postponing to v3.5.0, because a fix would need to happen in mbgl.

@jfirebaugh
Copy link
Contributor

cc @lbud @kkaefer, who were looking at line join issues recently.

@lbud
Copy link
Contributor

lbud commented Jan 31, 2017

From the core side, the failure to join endpoints here is not a bug. This is the behavior of a feature added as an MGLPolylineFeature and of its equivalent LineString added from a GeoJSON file: we don't join the beginning and end of a line, even if they are at the same point. However, if you add the same shape as an MGLPolygonFeature, or as a GeoJSON Polygon, styled as a line layer, it does join as expected, because polygons are interpreted to be closed.

Left: polygon; right: polyline:
image

I do find it strange that it joins smoothly when zoomed out. I assume this has to do with how we simplify GeoJSON. @mourner @jfirebaugh, I'm looking through this but can't tell for sure — would geojson-vt-cpp simplify a LineString with identical beginning and endpoints into a Polygon?

@incanus
Copy link
Contributor

incanus commented Jan 31, 2017

would geojson-vt-cpp simplify a LineString with identical beginning and endpoints into a Polygon?

No.

@jfirebaugh jfirebaugh removed this from the ios-v3.5.0 milestone Mar 10, 2017
@jfirebaugh
Copy link
Contributor

This behavior looks like a bug to me, and happens because the code decides whether or not to join the start and end point together not based on whether the feature is a LineString or Polygon in the source feature, but whether or not the geometry has coincident coordinates at the first and last position. But that condition can vary based on how the feature gets clipped across tile boundaries, which is why a LineString feature sometimes gets joined but sometimes not.

@jfirebaugh
Copy link
Contributor

To clarify: Polygon (MGLPolygon) features will always render joined, and that is the recommend way to get joinless lines. The bug here is that LineString (MGLPolyline) features are sometimes joined at coincident start/end coordinates, and the expected behavior is that they never are.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
annotations Annotations on iOS and macOS or markers on Android bug iOS Mapbox Maps SDK for iOS needs discussion
Projects
None yet
Development

No branches or pull requests

8 participants