joeltrew / gradientpathrenderer Goto Github PK
View Code? Open in Web Editor NEWRenders MKPolyline with a fancy multicoloured gradient fill
License: MIT License
Renders MKPolyline with a fancy multicoloured gradient fill
License: MIT License
I'm planning on upgrading this to swift 3 when I have a moment, but if anyone else wants to give it a go, feel free to pull request
Not drawing gradient
iOS 16 breaks some access control for the GradientPathRenderer. This is breaking
proposed fixed is to set the inits to public
Hi,
First, thanks for this awesome class to customize a MKPolyline.
I'm wondering if this is possible to add a gradient which depends of the altitude. Each points (lat/lng) of my polyline have an altitude value. The min altitude represents green color, the max altitude red color.
I don't find any information to do it. An idea ?
A rendering sample made with Google Map JS API
Thanks again.
When i re-write it use objecive-c, It doesn't work.
@implementation GradientPolylineRender
- (instancetype)initWithPolyline:(MKPolyline*)polyline colors:(NSMutableArray*)colors {
if (self = [super initWithOverlay:polyline]) {
self.polyline = polyline;
self.colors = [[NSMutableArray alloc] init];
for (int i = 0; i < colors.count; i++) {
[self.colors addObject:(id)[colors[i] CGColor]];
}
}
return self;
}
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
CGFloat baseWidth = self.lineWidth / zoomScale;
if (self.border) {
CGContextSetLineWidth(context , baseWidth * 2);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextAddPath(context, self.path);
if (self.borderColor) {
CGContextSetStrokeColorWithColor(context, self.borderColor.CGColor);
} else {
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
}
CGContextStrokePath(context);
}
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat locations[2] = {0, 1};
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)self.colors, locations);
CGContextSetLineWidth(context, baseWidth);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextAddPath(context, self.path);
CGContextSaveGState(context);
CGContextReplacePathWithStrokedPath(context);
CGContextClip(context);
CGRect boundingBox = CGPathGetBoundingBox(self.path);
CGPoint start = boundingBox.origin;
CGPoint end = CGPointMake(CGRectGetMaxX(boundingBox), CGRectGetMaxY(boundingBox));
CGContextDrawLinearGradient(context, gradient, start, end, kCGGradientDrawsBeforeStartLocation);
CGContextRestoreGState(context);
[super drawMapRect:mapRect zoomScale:zoomScale inContext:context];
}
- (void)createPath {
CGMutablePathRef path = CGPathCreateMutable();
BOOL pathIsEmpty = YES;
for (int i = 0; i < self.polyline.pointCount; i++) {
CGPoint point = CGPointMake(self.polyline.points[i].x, self.polyline.points[i].y);
if (pathIsEmpty) {
CGPathMoveToPoint(path, nil, point.x, point.y);
pathIsEmpty = NO;
} else {
CGPathAddLineToPoint(path, nil, point.x, point.y);
}
}
self.path = path;
}
self.colors have two color.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.