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

Polyline segments visibly overlap with alpha < 1 #1771

Closed
tomtaylor opened this issue Jun 22, 2015 · 28 comments
Closed

Polyline segments visibly overlap with alpha < 1 #1771

tomtaylor opened this issue Jun 22, 2015 · 28 comments
Labels
archived Archived because of inactivity bug Core The cross-platform C++ core, aka mbgl

Comments

@tomtaylor
Copy link

If you draw a MGLPolyline with an alpha < 1, the colour multiplies where segments overlap and it looks a little strange.

2015-06-22 at 21 17

@1ec5 1ec5 added the iOS Mapbox Maps SDK for iOS label Jun 22, 2015
@1ec5
Copy link
Contributor

1ec5 commented Jun 22, 2015

Compounding the effect, each line segment appears to have a round line cap and a square line cap.

@incanus
Copy link
Contributor

incanus commented Jun 23, 2015

Ah, at first I thought this was a factor of line joins, which place a dot at the junction, but it does look like caps instead.

Related: #1734

@tomtaylor
Copy link
Author

@incanus: Does this look like a relatively easy fix? It's one of two outstanding bugs that are preventing me shipping an app on MapboxGL (modifying the logo and attribution buttons being the other), and it'd be amazing if they could get rolled into the next release. Even just an ETA would be helpful - thanks! Let me know if there's a better channel for this.

@incanus incanus added the bug label Jul 1, 2015
@incanus
Copy link
Contributor

incanus commented Jul 1, 2015

@jfirebaugh @ansis Do you have a sense how tough this fix is?

@incanus
Copy link
Contributor

incanus commented Jul 1, 2015

I think we can experiment with the line joins/caps here to fix this without adverse effects. I will check it out.

@ansis
Copy link
Contributor

ansis commented Jul 1, 2015

@incanus see mapbox/mapbox-gl-js#794 (comment)

The quickest workaround is to use "line-join": "miter", which is the default line join type.

@incanus incanus self-assigned this Jul 1, 2015
@incanus incanus added this to the iOS Beta 3 milestone Jul 1, 2015
@incanus
Copy link
Contributor

incanus commented Jul 1, 2015

Test line is 0.5 alpha, 10.0 line width, [UIColor blueColor].

Line join for polyline annotations is set here:

// apply line layout properties to bucket
if (shapeStyle.is<LineProperties>()) {
shapeBucket->layout.set(PropertyKey::LineJoin, ConstantFunction<JoinType>(JoinType::Round));
}

Current (round):

ios simulator screen shot jul 1 2015 11 11 47 am

Reverting to the default of miter looks like this:

ios simulator screen shot jul 1 2015 11 13 52 am

So, the join problems are fixed, but the line is jagged, especially at sharp turns. This was the main reason I used round in the first place.

Just for completeness, here's bevel:

ios simulator screen shot jul 1 2015 11 17 08 am

Looks better, but still problematic on sharp corners.

Lastly, flipbevel, whatever that is:

ios simulator screen shot jul 1 2015 11 17 30 am

@incanus
Copy link
Contributor

incanus commented Jul 1, 2015

Experimenting with line-miter-limit.

@ansis
Copy link
Contributor

ansis commented Jul 1, 2015

hmm, it looks like there are some tessellation bugs.

flipbevel is just for internal use. Bevels are drawn two different ways depending on the sharpness of the corner.

@incanus
Copy link
Contributor

incanus commented Jul 1, 2015

@tomtaylor Based on this, it doesn't appear to be a trivial fix. Would it help if we work a bit on #1734 and expose settings like the line join, so you can choose based on your data? Maybe you won't have sharp corners and a miter join would look ok?

@incanus
Copy link
Contributor

incanus commented Jul 1, 2015

Here's a good patch for testing this by the way, using the default test shape of the hike up in northern Washington:

diff --git a/ios/app/MBXViewController.mm b/ios/app/MBXViewController.mm
index 0024582..a19f8bd 100644
--- a/ios/app/MBXViewController.mm
+++ b/ios/app/MBXViewController.mm
@@ -347,12 +347,12 @@ mbgl::Settings_NSUserDefaults *settings = nullptr;

 - (CGFloat)mapView:(__unused MGLMapView *)mapView alphaForShapeAnnotation:(MGLShape *)annotation
 {
-    return ([annotation isKindOfClass:[MGLPolygon class]] ? 0.5 : 1.0);
+    return ([annotation isKindOfClass:[MGLPolygon class]] ? 0.5 : 0.5);
 }

 - (UIColor *)mapView:(__unused MGLMapView *)mapView strokeColorForShapeAnnotation:(MGLShape *)annotation
 {
-    return ([annotation isKindOfClass:[MGLPolyline class]] ? [UIColor purpleColor] : [UIColor blackColor]);
+    return ([annotation isKindOfClass:[MGLPolyline class]] ? [UIColor blueColor] : [UIColor blackColor]);
 }

 - (UIColor *)mapView:(__unused MGLMapView *)mapView fillColorForPolygonAnnotation:(__unused MGLPolygon *)annotation
@@ -360,6 +360,11 @@ mbgl::Settings_NSUserDefaults *settings = nullptr;
     return (annotation.pointCount > 3 ? [UIColor greenColor] : [UIColor redColor]);
 }

+- (CGFloat)mapView:(__unused MGLMapView * __nonnull)mapView lineWidthForPolylineAnnotation:(__unused MGLPolyline * __nonnull)annotation
+{
+    return 10;
+}
+
 - (void)mapView:(__unused MGLMapView *)mapView didChangeUserTrackingMode:(MGLUserTrackingMode)mode animated:(__unused BOOL)animated
 {
     UIImage *newButtonImage;
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp
index fa06a42..64d81a3 100644
--- a/src/mbgl/map/map_context.cpp
+++ b/src/mbgl/map/map_context.cpp
@@ -213,7 +213,8 @@ void MapContext::updateAnnotationTiles(const std::unordered_set<TileID, TileID::

             // apply line layout properties to bucket
             if (shapeStyle.is<LineProperties>()) {
-                shapeBucket->layout.set(PropertyKey::LineJoin, ConstantFunction<JoinType>(JoinType::Round));
+                shapeBucket->layout.set(PropertyKey::LineJoin, ConstantFunction<JoinType>(JoinType::Miter));
+                shapeBucket->layout.set(PropertyKey::LineMiterLimit, ConstantFunction<float>(10));
             }

             // connect layer to bucket

@mb12
Copy link

mb12 commented Jul 1, 2015

@ansis and @incanus Tesselation bug/line smudginess is very similar to what I've seen on Android devices (consistently reproducible on Samsung Nexus S). I am referring to the following issue. Lines on some Android device show the kind of smudginess that is included in the screenshots above. Smudginess gets worse upon pan/scroll.

#1702

@tomtaylor
Copy link
Author

Hi @incanus and co, thanks a lot for looking at this. Yeah, I think I'm unlikely to have sharp corners or overlaps, so exposing some more options would help enough that I could get this out the door. Much appreciated.

@incanus
Copy link
Contributor

incanus commented Jul 6, 2015

@tomtaylor We are looking at this directly in #1839 and are hoping to roll it into the next dev build, ideally today, with the milestone build later this week.

@tomtaylor
Copy link
Author

@incanus great, thanks!

@incanus incanus assigned ansis and unassigned incanus Jul 7, 2015
@incanus
Copy link
Contributor

incanus commented Jul 7, 2015

@tomtaylor If I were to roll a custom build for you, would you be able to try it out? What are you using for install method? #1839 is looking pretty good in our testing.

@tomtaylor
Copy link
Author

@incanus sure thing. I'm using CocoaPods, currently pointing at the podspec on master. If you could provide me with a different podspec URL, I could try that?

@incanus incanus assigned incanus and unassigned ansis Jul 8, 2015
@incanus
Copy link
Contributor

incanus commented Jul 8, 2015

@tomtaylor Give this one a shot:

https://raw.githubusercontent.com/mapbox/mapbox-gl-native/1771-shape-tolerance/ios/MapboxGL.podspec

@tomtaylor
Copy link
Author

@incanus that looks identical to me - no changes from the original issue. Are you sure that's pointing to the correct build?

@incanus
Copy link
Contributor

incanus commented Jul 8, 2015

Oh, shoot, I forget to combine the simplification changes (included) with #1839 (not included). Sorry to waste your time — one sec.

@incanus
Copy link
Contributor

incanus commented Jul 8, 2015

Ok @tomtaylor, trash your Pods and pod update with the same URL and it should grab a different build. This one has the line join improvements from #1839 and a tweak to the polygon simplification as well to make them less pronounced.

@tomtaylor
Copy link
Author

Thanks, that works. (I had to flush ~/Library/Caches/CocoaPods too, just FYI.)

It's almost perfect, but there's a couple of little join glitches still. Much better than it was. They usually disappear when you zoom in 1 or 2 levels. Maybe increase the simplification a bit further?

2015-07-08 at 17 42

2015-07-08 at 17 44

@incanus
Copy link
Contributor

incanus commented Jul 8, 2015

I'm wary to tweak the simplification for the specific case in light of affecting the general case. I also don't really want to expose simplification settings to the user as this gets complex.

FWIW 888ae5e and 03c4ed7 just landed in master, so tonight's regular build will have the same effect as the custom build from #1771 (comment).

@tomtaylor
Copy link
Author

Sure, understood. Thanks a lot - when the sprite customisation has landed I'll be able to ship this app.

@incanus
Copy link
Contributor

incanus commented Jul 8, 2015

That just got merged — expect a build shortly.

@incanus
Copy link
Contributor

incanus commented Jul 8, 2015

Going to move this off of the b3 milestone as we've made improvements here. We'll keep working on this — the end goal is zero overlap.

@incanus incanus removed this from the iOS Beta 3 milestone Jul 8, 2015
@picciano
Copy link

This seems mostly resolved, but we are still seeing the occasional overlap, especially in angles < 90°.

simulator screen shot sep 29 2015 11 12 33 am

@incanus incanus added the P2 label Nov 4, 2015
@incanus incanus removed their assignment Aug 15, 2016
@friedbunny friedbunny added Core The cross-platform C++ core, aka mbgl and removed iOS Mapbox Maps SDK for iOS labels Jan 20, 2017
@stale stale bot added the archived Archived because of inactivity label Nov 15, 2018
@stale
Copy link

stale bot commented Nov 24, 2018

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

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

No branches or pull requests

8 participants