Authored by devel-hb

added support for custom marker styles

@@ -97,5 +97,6 @@ @@ -97,5 +97,6 @@
97 - (void) addMarker: (RMMarker*)marker; 97 - (void) addMarker: (RMMarker*)marker;
98 - (void) addMarker: (RMMarker*)marker AtLatLong:(CLLocationCoordinate2D)point; 98 - (void) addMarker: (RMMarker*)marker AtLatLong:(CLLocationCoordinate2D)point;
99 - (void) addDefaultMarkerAt: (CLLocationCoordinate2D)point; 99 - (void) addDefaultMarkerAt: (CLLocationCoordinate2D)point;
  100 +- (void) removeMarkers;
100 101
101 @end 102 @end
@@ -382,4 +382,10 @@ static BOOL _performExpensiveOperations = YES; @@ -382,4 +382,10 @@ static BOOL _performExpensiveOperations = YES;
382 [self addMarker:marker AtLatLong:point]; 382 [self addMarker:marker AtLatLong:point];
383 [marker release]; 383 [marker release];
384 } 384 }
  385 +
  386 +- (void) removeMarkers
  387 +{
  388 + overlay.sublayers = [NSArray arrayWithObjects:nil];
  389 +}
  390 +
385 @end 391 @end
@@ -52,5 +52,6 @@ typedef struct { @@ -52,5 +52,6 @@ typedef struct {
52 - (void) addMarker: (RMMarker*)marker; 52 - (void) addMarker: (RMMarker*)marker;
53 - (void) addMarker: (RMMarker*)marker AtLatLong:(CLLocationCoordinate2D)point; 53 - (void) addMarker: (RMMarker*)marker AtLatLong:(CLLocationCoordinate2D)point;
54 - (void) addDefaultMarkerAt: (CLLocationCoordinate2D)point; 54 - (void) addDefaultMarkerAt: (CLLocationCoordinate2D)point;
  55 +- (void) removeMarkers;
55 56
56 @end 57 @end
@@ -300,4 +300,9 @@ @@ -300,4 +300,9 @@
300 [contents addDefaultMarkerAt:point]; 300 [contents addDefaultMarkerAt:point];
301 } 301 }
302 302
  303 +- (void) removeMarkers
  304 +{
  305 + [contents removeMarkers];
  306 +}
  307 +
303 @end 308 @end
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 #import "RMMapLayer.h" 10 #import "RMMapLayer.h"
11 #import "RMMercator.h" 11 #import "RMMercator.h"
12 12
13 -@class UIImage; 13 +@class RMMarkerStyle;
14 14
15 extern NSString * const RMMarkerBlueKey; 15 extern NSString * const RMMarkerBlueKey;
16 extern NSString * const RMMarkerRedKey; 16 extern NSString * const RMMarkerRedKey;
@@ -19,9 +19,14 @@ extern NSString * const RMMarkerRedKey; @@ -19,9 +19,14 @@ extern NSString * const RMMarkerRedKey;
19 RMMercatorPoint location; 19 RMMercatorPoint location;
20 } 20 }
21 21
22 -- (id) initWithKey: (NSString*) key; 22 ++ (RMMarker*) markerWithNamedStyle: (NSString*) styleName;
  23 +
  24 +- (id) initWithCGImage: (CGImageRef) image anchorPoint: (CGPoint) anchorPoint;
23 - (id) initWithCGImage: (CGImageRef) image; 25 - (id) initWithCGImage: (CGImageRef) image;
  26 +- (id) initWithKey: (NSString*) key;
24 - (id) initWithUIImage: (UIImage*) image; 27 - (id) initWithUIImage: (UIImage*) image;
  28 +- (id) initWithStyle: (RMMarkerStyle*) style;
  29 +- (id) initWithNamedStyle: (NSString*) styleName;
25 30
26 @property (assign, nonatomic) RMMercatorPoint location; 31 @property (assign, nonatomic) RMMercatorPoint location;
27 32
@@ -7,6 +7,8 @@ @@ -7,6 +7,8 @@
7 // 7 //
8 8
9 #import "RMMarker.h" 9 #import "RMMarker.h"
  10 +#import "RMMarkerStyle.h"
  11 +#import "RMMarkerStyles.h"
10 12
11 #import "RMPixel.h" 13 #import "RMPixel.h"
12 14
@@ -20,8 +22,18 @@ static CGImageRef _markerBlue = nil; @@ -20,8 +22,18 @@ static CGImageRef _markerBlue = nil;
20 22
21 @synthesize location; 23 @synthesize location;
22 24
  25 ++ (RMMarker*) markerWithNamedStyle: (NSString*) styleName
  26 +{
  27 + return [[[RMMarker alloc] initWithNamedStyle: styleName] autorelease];
  28 +}
  29 +
23 - (id) initWithCGImage: (CGImageRef) image 30 - (id) initWithCGImage: (CGImageRef) image
24 { 31 {
  32 + return [self initWithCGImage: image anchorPoint: CGPointMake(0.5, 1.0)];
  33 +}
  34 +
  35 +- (id) initWithCGImage: (CGImageRef) image anchorPoint: (CGPoint) _anchorPoint
  36 +{
25 if (![super init]) 37 if (![super init])
26 return nil; 38 return nil;
27 39
@@ -29,7 +41,7 @@ static CGImageRef _markerBlue = nil; @@ -29,7 +41,7 @@ static CGImageRef _markerBlue = nil;
29 41
30 self.bounds = CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image)); 42 self.bounds = CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image));
31 43
32 - self.anchorPoint = CGPointMake(0.5, 1.0); 44 + self.anchorPoint = _anchorPoint;
33 45
34 return self; 46 return self;
35 } 47 }
@@ -44,6 +56,22 @@ static CGImageRef _markerBlue = nil; @@ -44,6 +56,22 @@ static CGImageRef _markerBlue = nil;
44 return [self initWithCGImage:[RMMarker markerImage:key]]; 56 return [self initWithCGImage:[RMMarker markerImage:key]];
45 } 57 }
46 58
  59 +- (id) initWithStyle: (RMMarkerStyle*) style
  60 +{
  61 + return [self initWithCGImage: [style.markerIcon CGImage] anchorPoint: style.anchorPoint];
  62 +}
  63 +
  64 +- (id) initWithNamedStyle: (NSString*) styleName
  65 +{
  66 + RMMarkerStyle* style = [[RMMarkerStyles styles] styleNamed: styleName];
  67 +
  68 + if (style==nil) {
  69 + NSLog(@"problem creating marker: style '%@' not found", styleName);
  70 + return [self initWithCGImage: [RMMarker markerImage: RMMarkerRedKey]];
  71 + }
  72 + return [self initWithStyle: style];
  73 +}
  74 +
47 - (void)zoomByFactor: (float) zoomFactor Near:(CGPoint) center 75 - (void)zoomByFactor: (float) zoomFactor Near:(CGPoint) center
48 { 76 {
49 self.position = RMScaleCGPointAboutPoint(self.position, zoomFactor, center); 77 self.position = RMScaleCGPointAboutPoint(self.position, zoomFactor, center);
  1 +//
  2 +// RMMarkerStyle.h
  3 +// MapView
  4 +//
  5 +// Created by Hauke Brandes on 29.10.08.
  6 +// Copyright 2008 __MyCompanyName__. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +
  12 +@interface RMMarkerStyle : NSObject {
  13 +
  14 + UIImage* markerIcon;
  15 +
  16 + CGPoint anchorPoint;
  17 +
  18 +}
  19 +
  20 +@property (retain) UIImage* markerIcon;
  21 +@property (assign) CGPoint anchorPoint;
  22 +
  23 ++ (RMMarkerStyle*) markerStyleWithIcon: (UIImage*) image;
  24 +
  25 +- (RMMarkerStyle*) initWithIcon: (UIImage*) image;
  26 +- (void) dealloc;
  27 +
  28 +@end
  1 +//
  2 +// RMMarkerStyle.m
  3 +// MapView
  4 +//
  5 +// Created by Hauke Brandes on 29.10.08.
  6 +// Copyright 2008 __MyCompanyName__. All rights reserved.
  7 +//
  8 +
  9 +#import "RMMarkerStyle.h"
  10 +
  11 +
  12 +@implementation RMMarkerStyle
  13 +
  14 +@synthesize markerIcon;
  15 +@synthesize anchorPoint;
  16 +
  17 ++ (RMMarkerStyle*) markerStyleWithIcon: (UIImage*) image
  18 +{
  19 + return [[[RMMarkerStyle alloc] initWithIcon: image] autorelease];
  20 +}
  21 +
  22 +- (RMMarkerStyle*) initWithIcon: (UIImage*) _image
  23 +{
  24 + self = [super init];
  25 + if (self==nil) return nil;
  26 +
  27 + self.markerIcon = _image;
  28 + anchorPoint = CGPointMake(0.5, 1.0);
  29 +
  30 + return self;
  31 +}
  32 +
  33 +- (void) dealloc
  34 +{
  35 + [markerIcon release];
  36 + [super dealloc];
  37 +}
  38 +
  39 +@end
  1 +//
  2 +// RMMarkerStyles.h
  3 +// MapView
  4 +//
  5 +// Created by Hauke Brandes on 29.10.08.
  6 +// Copyright 2008 __MyCompanyName__. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +
  12 +@interface RMMarkerStyles : NSObject {
  13 +
  14 + NSMutableDictionary* styles;
  15 +
  16 +}
  17 +
  18 ++ (RMMarkerStyles*) styles;
  19 +
  20 +- (void) addStyle: (RMMarkerStyle*) style withName: (NSString*) name;
  21 +- (RMMarkerStyle*) styleNamed: (NSString*) name;
  22 +
  23 +@end
  1 +//
  2 +// RMMarkerStyles.m
  3 +// MapView
  4 +//
  5 +// Created by Hauke Brandes on 29.10.08.
  6 +// Copyright 2008 __MyCompanyName__. All rights reserved.
  7 +//
  8 +
  9 +#import "RMMarker.h"
  10 +#import "RMMarkerStyle.h"
  11 +
  12 +#import "RMMarkerStyles.h"
  13 +
  14 +
  15 +@implementation RMMarkerStyles
  16 +
  17 +
  18 +static RMMarkerStyles *sharedMarkerStyles = nil;
  19 +
  20 ++ (RMMarkerStyles*)styles
  21 +{
  22 + @synchronized(self) {
  23 + if (sharedMarkerStyles == nil) {
  24 + [[self alloc] init]; // assignment not done here
  25 + }
  26 + }
  27 + return sharedMarkerStyles;
  28 +}
  29 +
  30 +- (RMMarkerStyles*) init
  31 +{
  32 + self = [super init];
  33 + if (self==nil) return nil;
  34 +
  35 + styles = [[NSMutableDictionary dictionaryWithObjectsAndKeys:
  36 + [RMMarkerStyle markerStyleWithIcon: [UIImage imageWithCGImage: [RMMarker markerImage: RMMarkerBlueKey]]], RMMarkerBlueKey,
  37 + [RMMarkerStyle markerStyleWithIcon: [UIImage imageWithCGImage: [RMMarker markerImage: RMMarkerRedKey]]], RMMarkerRedKey,
  38 + nil
  39 + ] retain];
  40 +
  41 + return self;
  42 +}
  43 +
  44 ++ (id)allocWithZone:(NSZone *)zone
  45 +{
  46 + @synchronized(self) {
  47 + if (sharedMarkerStyles == nil) {
  48 + sharedMarkerStyles = [super allocWithZone:zone];
  49 + return sharedMarkerStyles; // assignment and return on first allocation
  50 + }
  51 + }
  52 + return nil; //on subsequent allocation attempts return nil
  53 +}
  54 +
  55 +- (id)copyWithZone:(NSZone *)zone
  56 +{
  57 + return self;
  58 +}
  59 +
  60 +- (id)retain
  61 +{
  62 + return self;
  63 +}
  64 +
  65 +- (unsigned)retainCount
  66 +{
  67 + return UINT_MAX; //denotes an object that cannot be released
  68 +}
  69 +
  70 +- (void)release
  71 +{
  72 + //do nothing
  73 +}
  74 +
  75 +- (id)autorelease
  76 +{
  77 + return self;
  78 +}
  79 +
  80 +- (void) addStyle: (RMMarkerStyle*) style withName: (NSString*) name
  81 +{
  82 + [styles setObject:style forKey:name];
  83 +}
  84 +
  85 +- (RMMarkerStyle*) styleNamed: (NSString*) name
  86 +{
  87 + return [styles objectForKey:name];
  88 +}
  89 +
  90 +
  91 +@end
@@ -9,6 +9,12 @@ @@ -9,6 +9,12 @@
9 /* Begin PBXBuildFile section */ 9 /* Begin PBXBuildFile section */
10 126692A10EB75C0A00E002D5 /* RMConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 126692A00EB75C0A00E002D5 /* RMConfiguration.m */; }; 10 126692A10EB75C0A00E002D5 /* RMConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 126692A00EB75C0A00E002D5 /* RMConfiguration.m */; };
11 126693040EB76C0B00E002D5 /* RMConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 126692A00EB75C0A00E002D5 /* RMConfiguration.m */; }; 11 126693040EB76C0B00E002D5 /* RMConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 126692A00EB75C0A00E002D5 /* RMConfiguration.m */; };
  12 + 1296F5610EB8743500FF25E0 /* RMMarkerStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = 1296F5600EB8743500FF25E0 /* RMMarkerStyle.m */; };
  13 + 1296F5640EB8745300FF25E0 /* RMMarkerStyles.m in Sources */ = {isa = PBXBuildFile; fileRef = 1296F5630EB8745300FF25E0 /* RMMarkerStyles.m */; };
  14 + 1296F56B0EB8849A00FF25E0 /* RMMarkerStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 1296F55F0EB8743500FF25E0 /* RMMarkerStyle.h */; };
  15 + 1296F56C0EB8849B00FF25E0 /* RMMarkerStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = 1296F5600EB8743500FF25E0 /* RMMarkerStyle.m */; };
  16 + 1296F56D0EB8849B00FF25E0 /* RMMarkerStyles.h in Headers */ = {isa = PBXBuildFile; fileRef = 1296F5620EB8745300FF25E0 /* RMMarkerStyles.h */; };
  17 + 1296F56E0EB8849C00FF25E0 /* RMMarkerStyles.m in Sources */ = {isa = PBXBuildFile; fileRef = 1296F5630EB8745300FF25E0 /* RMMarkerStyles.m */; };
12 1D3623260D0F684500981E51 /* MapViewAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* MapViewAppDelegate.m */; }; 18 1D3623260D0F684500981E51 /* MapViewAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* MapViewAppDelegate.m */; };
13 1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; }; 19 1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; };
14 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; 20 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
@@ -132,6 +138,10 @@ @@ -132,6 +138,10 @@
132 /* Begin PBXFileReference section */ 138 /* Begin PBXFileReference section */
133 1266929F0EB75C0A00E002D5 /* RMConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMConfiguration.h; sourceTree = "<group>"; }; 139 1266929F0EB75C0A00E002D5 /* RMConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMConfiguration.h; sourceTree = "<group>"; };
134 126692A00EB75C0A00E002D5 /* RMConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMConfiguration.m; sourceTree = "<group>"; }; 140 126692A00EB75C0A00E002D5 /* RMConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMConfiguration.m; sourceTree = "<group>"; };
  141 + 1296F55F0EB8743500FF25E0 /* RMMarkerStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMMarkerStyle.h; sourceTree = "<group>"; };
  142 + 1296F5600EB8743500FF25E0 /* RMMarkerStyle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMMarkerStyle.m; sourceTree = "<group>"; };
  143 + 1296F5620EB8745300FF25E0 /* RMMarkerStyles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMMarkerStyles.h; sourceTree = "<group>"; };
  144 + 1296F5630EB8745300FF25E0 /* RMMarkerStyles.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMMarkerStyles.m; sourceTree = "<group>"; };
135 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 145 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
136 1D3623240D0F684500981E51 /* MapViewAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapViewAppDelegate.h; sourceTree = "<group>"; }; 146 1D3623240D0F684500981E51 /* MapViewAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapViewAppDelegate.h; sourceTree = "<group>"; };
137 1D3623250D0F684500981E51 /* MapViewAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MapViewAppDelegate.m; sourceTree = "<group>"; }; 147 1D3623250D0F684500981E51 /* MapViewAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MapViewAppDelegate.m; sourceTree = "<group>"; };
@@ -501,6 +511,10 @@ @@ -501,6 +511,10 @@
501 B8FA92180E9315EC003A9FE6 /* RMLayerSet.m */, 511 B8FA92180E9315EC003A9FE6 /* RMLayerSet.m */,
502 B8F3FC620EA2E792004D8F85 /* RMMarker.h */, 512 B8F3FC620EA2E792004D8F85 /* RMMarker.h */,
503 B8F3FC630EA2E792004D8F85 /* RMMarker.m */, 513 B8F3FC630EA2E792004D8F85 /* RMMarker.m */,
  514 + 1296F55F0EB8743500FF25E0 /* RMMarkerStyle.h */,
  515 + 1296F5600EB8743500FF25E0 /* RMMarkerStyle.m */,
  516 + 1296F5620EB8745300FF25E0 /* RMMarkerStyles.h */,
  517 + 1296F5630EB8745300FF25E0 /* RMMarkerStyles.m */,
504 ); 518 );
505 name = Layers; 519 name = Layers;
506 sourceTree = "<group>"; 520 sourceTree = "<group>";
@@ -593,6 +607,8 @@ @@ -593,6 +607,8 @@
593 B8474B9F0EB40094006A0BC1 /* FMResultSet.h in Headers */, 607 B8474B9F0EB40094006A0BC1 /* FMResultSet.h in Headers */,
594 B8474BA20EB40094006A0BC1 /* RMTileCacheDAO.h in Headers */, 608 B8474BA20EB40094006A0BC1 /* RMTileCacheDAO.h in Headers */,
595 B8474BA40EB40094006A0BC1 /* RMDatabaseCache.h in Headers */, 609 B8474BA40EB40094006A0BC1 /* RMDatabaseCache.h in Headers */,
  610 + 1296F56B0EB8849A00FF25E0 /* RMMarkerStyle.h in Headers */,
  611 + 1296F56D0EB8849B00FF25E0 /* RMMarkerStyles.h in Headers */,
596 ); 612 );
597 runOnlyForDeploymentPostprocessing = 0; 613 runOnlyForDeploymentPostprocessing = 0;
598 }; 614 };
@@ -696,6 +712,8 @@ @@ -696,6 +712,8 @@
696 1D3623260D0F684500981E51 /* MapViewAppDelegate.m in Sources */, 712 1D3623260D0F684500981E51 /* MapViewAppDelegate.m in Sources */,
697 28D7ACF80DDB3853001CB0EB /* MapViewViewController.m in Sources */, 713 28D7ACF80DDB3853001CB0EB /* MapViewViewController.m in Sources */,
698 126692A10EB75C0A00E002D5 /* RMConfiguration.m in Sources */, 714 126692A10EB75C0A00E002D5 /* RMConfiguration.m in Sources */,
  715 + 1296F5610EB8743500FF25E0 /* RMMarkerStyle.m in Sources */,
  716 + 1296F5640EB8745300FF25E0 /* RMMarkerStyles.m in Sources */,
699 ); 717 );
700 runOnlyForDeploymentPostprocessing = 0; 718 runOnlyForDeploymentPostprocessing = 0;
701 }; 719 };
@@ -738,6 +756,8 @@ @@ -738,6 +756,8 @@
738 B8474BA30EB40094006A0BC1 /* RMTileCacheDAO.m in Sources */, 756 B8474BA30EB40094006A0BC1 /* RMTileCacheDAO.m in Sources */,
739 B8474BA50EB40094006A0BC1 /* RMDatabaseCache.m in Sources */, 757 B8474BA50EB40094006A0BC1 /* RMDatabaseCache.m in Sources */,
740 126693040EB76C0B00E002D5 /* RMConfiguration.m in Sources */, 758 126693040EB76C0B00E002D5 /* RMConfiguration.m in Sources */,
  759 + 1296F56C0EB8849B00FF25E0 /* RMMarkerStyle.m in Sources */,
  760 + 1296F56E0EB8849C00FF25E0 /* RMMarkerStyles.m in Sources */,
741 ); 761 );
742 runOnlyForDeploymentPostprocessing = 0; 762 runOnlyForDeploymentPostprocessing = 0;
743 }; 763 };