Skip to content
Browse files

Updated RMPath to add line cap/join and shadow options

  • Loading branch information...
1 parent e3657ac commit 0070fcf0c7c2b3235bea5b06bef128b511f2b242 @michaeltyson michaeltyson committed Mar 21, 2012
Showing with 85 additions and 38 deletions.
  1. +9 −27 MapView/Map/RMPath.h
  2. +71 −7 MapView/Map/RMPath.m
  3. +5 −4 samples/MapTestbed/Classes/MapTestbedAppDelegate.m
View
36 MapView/Map/RMPath.h
@@ -34,30 +34,7 @@
@class RMMapContents;
@class RMMapView;
-@interface RMPath : RMMapLayer <RMMovingMapLayer> {
- RMProjectedPoint projectedLocation;
-
- UIColor *lineColor;
- UIColor *fillColor;
- float lineWidth;
- BOOL scaleLineWidth;
-
- CGFloat *_lineDashLengths;
- CGFloat *_scaledLineDashLengths;
- size_t _lineDashCount;
- CGFloat lineDashPhase;
- BOOL scaleLineDash;
-
- BOOL enableDragging;
- BOOL enableRotation;
-
- CGMutablePathRef path;
-
- RMMapContents *mapContents;
-
- CGRect originalContentsRect;
- BOOL redrawPending;
-}
+@interface RMPath : RMMapLayer <RMMovingMapLayer>
- (id) initWithContents: (RMMapContents*)aContents;
- (id) initForMap: (RMMapView*)map;
@@ -71,11 +48,16 @@
- (void) addLineToLatLong: (RMLatLong) point;
- (void) closePath;
+@property (nonatomic, assign) CGLineCap lineCap;
+@property (nonatomic, assign) CGLineJoin lineJoin;
@property (nonatomic, assign) float lineWidth;
@property (nonatomic, assign) BOOL scaleLineWidth;
-@property (nonatomic, readwrite, assign) NSArray *lineDashLengths;
-@property CGFloat lineDashPhase;
-@property BOOL scaleLineDash;
+@property (nonatomic, assign) CGFloat shadowBlur;
+@property (nonatomic, assign) CGSize shadowOffset;
+@property (nonatomic, retain) UIColor *shadowColor;
+@property (nonatomic, assign) NSArray *lineDashLengths;
+@property (nonatomic, assign) CGFloat lineDashPhase;
+@property (nonatomic, assign) BOOL scaleLineDash;
@property (nonatomic, assign) RMProjectedPoint projectedLocation;
@property (assign) BOOL enableDragging;
@property (assign) BOOL enableRotation;
View
78 MapView/Map/RMPath.m
@@ -33,13 +33,28 @@
#import "RMProjection.h"
#import "RMNotifications.h"
-@interface RMPath ()
+@interface RMPath () {
+ RMProjectedPoint projectedLocation;
+
+ CGFloat *_lineDashLengths;
+ CGFloat *_scaledLineDashLengths;
+ size_t _lineDashCount;
+ CGFloat lineDashPhase;
+
+ CGMutablePathRef path;
+
+ RMMapContents *mapContents;
+
+ CGRect originalContentsRect;
+ BOOL redrawPending;
+}
+
- (void)addPointToXY:(RMProjectedPoint) point withDrawing:(BOOL)isDrawing;
- (void)recalculateGeometry;
@end
@implementation RMPath
-@synthesize lineWidth, lineColor, fillColor, scaleLineWidth, lineDashPhase, lineDashLengths, scaleLineDash, projectedLocation, enableDragging, enableRotation;
+@synthesize lineCap, lineJoin, lineWidth, lineColor, fillColor, scaleLineWidth, shadowBlur, shadowOffset, shadowColor, lineDashPhase, lineDashLengths, scaleLineDash, projectedLocation, enableDragging, enableRotation;
@dynamic CGPath, projectedBounds;
- (id) initWithContents: (RMMapContents*)aContents {
@@ -51,6 +66,8 @@ - (id) initWithContents: (RMMapContents*)aContents {
// Defaults
lineWidth = 4.0;
+ lineCap = kCGLineCapRound;
+ lineJoin = kCGLineJoinRound;
scaleLineWidth = NO;
enableDragging = YES;
enableRotation = YES;
@@ -60,6 +77,9 @@ - (id) initWithContents: (RMMapContents*)aContents {
_lineDashLengths = NULL;
_scaledLineDashLengths = NULL;
lineDashPhase = 0.0;
+ shadowBlur = 0.0;
+ shadowOffset = CGSizeMake(0, 0);
+ self.shadowColor = [UIColor clearColor];
self.masksToBounds = YES;
@@ -88,8 +108,10 @@ - (id) initForMap: (RMMapView*)map withCoordinates:(const CLLocationCoordinate2D
-(void) dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
CGPathRelease(path);
- self.lineColor = nil;
- self.fillColor = nil;
+ [lineColor release];
+ [fillColor release];
+ [shadowColor release];
+ if ( _lineDashLengths ) free(_lineDashLengths);
[super dealloc];
}
@@ -169,6 +191,20 @@ - (void) setLineDashLengths:(NSArray *)lengths {
}
}
+-(void)setLineCap:(CGLineCap)theLineCap {
+ if ( theLineCap != lineCap ) {
+ lineCap = theLineCap;
+ [self setNeedsDisplay];
+ }
+}
+
+-(void)setLineJoin:(CGLineJoin)theLineJoin {
+ if ( theLineJoin != lineJoin ) {
+ lineJoin = theLineJoin;
+ [self setNeedsDisplay];
+ }
+}
+
- (void)setLineColor:(UIColor *)aLineColor {
if (lineColor != aLineColor) {
[lineColor release];
@@ -185,6 +221,29 @@ - (void)setFillColor:(UIColor *)aFillColor {
}
}
+-(void)setShadowBlur:(CGFloat)theShadowBlur {
+ if ( shadowBlur != theShadowBlur ) {
+ shadowBlur = theShadowBlur;
+ [self setNeedsDisplay];
+ }
+}
+
+-(void)setShadowOffset:(CGSize)theShadowOffset {
+ if ( !CGSizeEqualToSize(shadowOffset, theShadowOffset) ) {
+ shadowOffset = theShadowOffset;
+ [self setNeedsDisplay];
+ }
+}
+
+-(void)setShadowColor:(UIColor *)theShadowColor {
+ if ( ![shadowColor isEqual:theShadowColor] ) {
+ [theShadowColor retain];
+ [shadowColor release];
+ shadowColor = theShadowColor;
+ [self setNeedsDisplay];
+ }
+}
+
- (void)moveBy: (CGSize) delta {
if(enableDragging){
[super moveBy:delta];
@@ -217,7 +276,6 @@ - (void)addPointToXY:(RMProjectedPoint) point withDrawing:(BOOL)isDrawing {
- (void)recalculateGeometry {
RMMercatorToScreenProjection *projection = [mapContents mercatorToScreenProjection];
- const float outset = 100.0f;
float scaledLineWidth = lineWidth;
if ( !scaleLineWidth ) {
@@ -240,6 +298,8 @@ - (void)recalculateGeometry {
CGRect screenBounds = [mapContents screenBounds];
CGPoint myPosition = [projection projectXYPoint: projectedLocation];
CGRect clippedBounds = pixelBounds;
+ CGFloat outset = MAX(screenBounds.size.width, screenBounds.size.height);
+
clippedBounds.origin.x += myPosition.x; clippedBounds.origin.y += myPosition.y;
clippedBounds = CGRectIntersection(clippedBounds, CGRectInset(screenBounds, -outset, -outset));
clippedBounds.origin.x -= myPosition.x; clippedBounds.origin.y -= myPosition.y;
@@ -311,8 +371,8 @@ - (void)drawInContext:(CGContextRef)theContext {
CGContextAddPath(theContext, path);
CGContextSetLineWidth(theContext, scaledLineWidth);
- CGContextSetLineCap(theContext, kCGLineCapRound);
- CGContextSetLineJoin(theContext, kCGLineJoinRound);
+ CGContextSetLineCap(theContext, lineCap);
+ CGContextSetLineJoin(theContext, lineJoin);
if(_lineDashLengths){
CGContextSetLineDash(theContext, lineDashPhase, dashLengths, _lineDashCount);
}
@@ -321,6 +381,10 @@ - (void)drawInContext:(CGContextRef)theContext {
CGContextSetStrokeColorWithColor(theContext, [lineColor CGColor]);
}
+ if ( ![shadowColor isEqual:[UIColor clearColor]] ) {
+ CGContextSetShadowWithColor(theContext, shadowOffset, shadowBlur, [shadowColor CGColor]);
+ }
+
if ( fillColor ) {
CGContextSetFillColorWithColor(theContext, [fillColor CGColor]);
}
View
9 samples/MapTestbed/Classes/MapTestbedAppDelegate.m
@@ -75,8 +75,10 @@ - (void)performTest
testPath = [[RMPath alloc] initWithContents:mapContents];
[testPath setLineColor:[UIColor greenColor]];
[testPath setFillColor:[UIColor clearColor]];
- [testPath setLineWidth:40.0f];
- [testPath setDrawingMode:kCGPathStroke];
+ [testPath setLineWidth:4.0f];
+ [testPath setShadowColor:[UIColor colorWithWhite:0.0 alpha:0.8]];
+ [testPath setShadowBlur:4.0];
+ [testPath setShadowOffset:CGSizeMake(0, 4)];
[testPath addLineToLatLong:one];
[testPath addLineToLatLong:two];
[testPath addLineToLatLong:three];
@@ -108,8 +110,7 @@ - (void)performTest
testRegion = [[RMPath alloc] initWithContents:mapContents];
[testRegion setFillColor:[UIColor colorWithRed: 0.1 green:0.1 blue: 0.8 alpha: 0.5 ]];
[testRegion setLineColor:[UIColor blueColor]];
- [testRegion setLineWidth:20.0f];
- [testRegion setDrawingMode:kCGPathFillStroke];
+ [testRegion setLineWidth:2.0f];
[testRegion addLineToLatLong:r1];
[testRegion addLineToLatLong:r2];
[testRegion addLineToLatLong:r3];

0 comments on commit 0070fcf

Please sign in to comment.
Something went wrong with that request. Please try again.