Permalink
Browse files

added the line scaling back in from an earlier revision. Set the path…

…'s .scaleLineWidth = NO to maintain the path's on screen pixel width no matter the map's scale. scaleLineWidth = YES will give you fat lines when you zoom way in.
  • Loading branch information...
slaing committed May 6, 2009
1 parent f37773a commit 43425940bee983a0c26cde7bd95eff2ecc80202f
Showing with 24 additions and 10 deletions.
  1. +1 −3 MapView/Map/RMPath.h
  2. +23 −7 MapView/Map/RMPath.m
View
@@ -73,6 +73,7 @@
@property CGPathDrawingMode drawingMode;
@property float lineWidth;
+@property BOOL scaleLineWidth;
@property (nonatomic, assign) RMProjectedPoint origin;
@property (readwrite, assign) UIColor *lineColor;
@property (readwrite, assign) UIColor *fillColor;
@@ -86,8 +87,5 @@
/// There is no requirement that a path be closed.
- (void) closePath;
-//- (void) setPoints: (NSArray*) arr;
-
-//- (void) moveBy: (RMXYSize) delta;
@end
View
@@ -34,7 +34,7 @@
@implementation RMPath
-@synthesize origin;
+@synthesize origin, scaleLineWidth;
#define kDefaultLineWidth 100
@@ -81,15 +81,22 @@ -(void) dealloc
}
- (void) recalculateGeometry
-{
+{
float scale = [[contents mercatorToScreenProjection] metersPerPixel];
+
+ float scaledLineWidth = lineWidth;
+ if(!scaleLineWidth) {
+ renderedScale = [contents metersPerPixel];
+ scaledLineWidth *= renderedScale;
+ }
+
// The bounds are actually in mercators...
/// \bug if "bounds are actually in mercators", shouldn't be using a CGRect
CGRect boundsInMercators = CGPathGetBoundingBox(path);
- boundsInMercators.origin.x -= lineWidth;
- boundsInMercators.origin.y -= lineWidth;
- boundsInMercators.size.width += 2*lineWidth;
- boundsInMercators.size.height += 2*lineWidth;
+ boundsInMercators.origin.x -= scaledLineWidth;
+ boundsInMercators.origin.y -= scaledLineWidth;
+ boundsInMercators.size.width += 2*scaledLineWidth;
+ boundsInMercators.size.height += 2*scaledLineWidth;
CGRect pixelBounds = RMScaleCGRectAboutPoint(boundsInMercators, 1.0f / scale, CGPointZero);
@@ -156,12 +163,18 @@ - (void)drawInContext:(CGContextRef)theContext
float scale = 1.0f / [contents metersPerPixel];
+ float scaledLineWidth = lineWidth;
+ if(!scaleLineWidth) {
+ scaledLineWidth *= renderedScale;
+ }
+ NSLog(@"line width = %f, content scale = %f", scaledLineWidth, renderedScale);
+
CGContextScaleCTM(theContext, scale, scale);
CGContextBeginPath(theContext);
CGContextAddPath(theContext, path);
- CGContextSetLineWidth(theContext, lineWidth);
+ CGContextSetLineWidth(theContext, scaledLineWidth);
CGContextSetStrokeColorWithColor(theContext, [lineColor CGColor]);
CGContextSetFillColorWithColor(theContext, [fillColor CGColor]);
@@ -214,6 +227,7 @@ - (UIColor *)fillColor
{
return fillColor;
}
+
- (void)setFillColor:(UIColor *)aFillColor
{
if (fillColor != aFillColor) {
@@ -227,6 +241,7 @@ - (void)zoomByFactor: (float) zoomFactor near:(CGPoint) pivot
{
[super zoomByFactor:zoomFactor near:pivot];
+ // don't redraw if the path hasn't been scaled very much
float newMPP = [contents metersPerPixel];
if (newMPP / renderedScale >= 2.0f
|| newMPP / renderedScale <= 0.5f)
@@ -235,4 +250,5 @@ - (void)zoomByFactor: (float) zoomFactor near:(CGPoint) pivot
}
}
+
@end

0 comments on commit 4342594

Please sign in to comment.