Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed gradient polyline not always fully drawn + stability issues #1960

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions lib/ios/AirMaps/AIRMapPolylineRenderer.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ - (void) addPoint:(CGPoint)point color:(UIColor*)color
@end

@implementation AIRMapPolylineRenderer {
NSMutableArray* _segments;
MKPolyline* _polyline;
NSArray<UIColor *> *_strokeColors;
MKMapSnapshot* _snapshot;
Expand Down Expand Up @@ -111,10 +110,10 @@ - (void) createPath
self.path = path;
}

- (void) createSegments
- (NSArray*) createSegments
{
_segments = [NSMutableArray new];
if (_polyline.pointCount <= 1) return;
NSMutableArray* segments = [NSMutableArray new];
if (_polyline.pointCount <= 1) return segments;
AIRMapPolylineRendererSegment* segment = nil;
for (NSUInteger i = 0, n = _polyline.pointCount; i < n; i++){
CGPoint point = [self pointForIndex:i];
Expand All @@ -123,7 +122,7 @@ - (void) createSegments

// Start new segment
segment = [[AIRMapPolylineRendererSegment alloc] initWithPoint:point color:color];
[_segments addObject:segment];
[segments addObject:segment];
}
else if (((color == nil) && (segment.endColor == nil)) ||
((color != nil) && [segment.startColor isEqual:color])) {
Expand All @@ -142,36 +141,36 @@ - (void) createSegments
// Add transition gradient
segment = [[AIRMapPolylineRendererSegment alloc] initWithPoint:segment.endPoint color:segment.endColor];
[segment addPoint:point color:color];
[_segments addObject:segment];
[segments addObject:segment];
}

// Start new segment
if (i < (n - 1)) {
segment = [[AIRMapPolylineRendererSegment alloc] initWithPoint:point color:color];
[_segments addObject:segment];
[segments addObject:segment];
}
}
}

// Close last segment in case this was forgotten
// Remove last segment in case it only contains a single path point
if ((segment != nil) && (segment.endColor == nil)) {
segment.endColor = segment.startColor;
[segments removeLastObject];
}

return segments;
}

- (void) setStrokeColors:(NSArray<UIColor *> *)strokeColors
{
if (_strokeColors != strokeColors) {
_strokeColors = strokeColors;
_segments = nil;
}
}

- (void) setStrokeColor:(UIColor *)strokeColor
{
if (super.strokeColor != strokeColor) {
super.strokeColor = strokeColor;
_segments = nil;
}
}

Expand All @@ -198,12 +197,9 @@ - (void) drawWithZoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)contex
}
CGContextSetLineDash(context, self.lineDashPhase, dashes, self.lineDashPattern.count);

if (_segments == nil) {
[self createSegments];
}

for (NSUInteger i = 0, n = _segments.count; i < n; i++) {
AIRMapPolylineRendererSegment* segment = _segments[i];
NSArray* segments = [self createSegments];
for (NSUInteger i = 0, n = segments.count; i < n; i++) {
AIRMapPolylineRendererSegment* segment = segments[i];

CGContextBeginPath(context);
CGContextAddPath(context, segment.path);
Expand Down