Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Updated RMPath to add line cap/join and shadow options #169

Merged
merged 1 commit into from

3 participants

@michaeltyson

In response to comment #165 (comment), cap/join and shadow added.

Note: drawing mode is selected automatically based on the presence of fill/stroke options.

@michaeltyson michaeltyson referenced this pull request
Merged

RMPath rewrite #165

@michaeltyson

BTW: This can be tested in the MapTestbed sample app.

@ns-1m

I got this problem running MapTestbed sample app. I just downloaded (i.e. git clone ...) route-me.

I am using Xcode 4.2 with iOS 5.0 SDK.

Here's the console log:

This GDB was configured as "x86_64-apple-darwin".Attaching to process 383.
2012-05-23 10:44:36.659 MapTestbed[383:207] logged method call: - initWithView:screenScale:
2012-05-23 10:44:36.683 MapTestbed[383:207] logged method call: - initWithView:tilesource:centerLatLon:zoomLevel:maxZoomLevel:minZoomLevel:backgroundImage:screenScale:
2012-05-23 10:44:36.698 MapTestbed[383:207] logged method call: -MapView at 0,0-320,460 performInitialSetup
2012-05-23 10:44:36.712 MapTestbed[383:207] initializing memory cache with capacity 32
2012-05-23 10:44:36.714 MapTestbed[383:207] Opening database at /Users/noli/Library/Application Support/iPhone Simulator/5.0/Applications/E88B523A-05BE-469F-B820-4700B40AF727/Documents/MapOpenStreetMap.sqlite
2012-05-23 10:44:38.354 MapTestbed[383:207] Map contents initialised. view: MapView at 0,0-320,460 tileSource renderer
2012-05-23 10:44:38.612 MapTestbed[383:207] testing paths
2012-05-23 10:44:38.669 MapTestbed[383:207] Origin is calculated at: 48.845289, 2.283988
2012-05-23 10:44:38.735 MapTestbed[383:207] -[RMPath setDrawingMode:]: unrecognized selector sent to instance 0x69bcef0
sharedlibrary apply-load-rules all
Current language: auto; currently objective-c
(gdb)

@tracyharton tracyharton merged commit f23ae7b into route-me:master
@agolovatuk agolovatuk referenced this pull request from a commit in agolovatuk/route-me
@agolovatuk agolovatuk Merge with route_me/route_me added fixed #168 #169, rotation fix from…
… Computer Ace touch_enhancements
81172ac
@jklimke jklimke referenced this pull request from a commit in jklimke/mapbox-ios-sdk
@incanus incanus fixes #169: allow re-add of annotations 25f3fdc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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];
Something went wrong with that request. Please try again.