Giter VIP home page Giter VIP logo

gradientpathrenderer's People

Contributors

joeltrew avatar poszposz avatar rob1bouchet avatar tflhyl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gradientpathrenderer's Issues

Upgrade to Swift 3

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

Broken access control for iOS 16

iOS 16 breaks some access control for the GradientPathRenderer. This is breaking
proposed fixed is to set the inits to public

Color depends of altitude

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
sample

Thanks again.

Objective-C implementation

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.