Authored by devel-hb

added support for custom marker styles

... ... @@ -97,5 +97,6 @@
- (void) addMarker: (RMMarker*)marker;
- (void) addMarker: (RMMarker*)marker AtLatLong:(CLLocationCoordinate2D)point;
- (void) addDefaultMarkerAt: (CLLocationCoordinate2D)point;
- (void) removeMarkers;
@end
... ...
... ... @@ -382,4 +382,10 @@ static BOOL _performExpensiveOperations = YES;
[self addMarker:marker AtLatLong:point];
[marker release];
}
- (void) removeMarkers
{
overlay.sublayers = [NSArray arrayWithObjects:nil];
}
@end
... ...
... ... @@ -52,5 +52,6 @@ typedef struct {
- (void) addMarker: (RMMarker*)marker;
- (void) addMarker: (RMMarker*)marker AtLatLong:(CLLocationCoordinate2D)point;
- (void) addDefaultMarkerAt: (CLLocationCoordinate2D)point;
- (void) removeMarkers;
@end
... ...
... ... @@ -300,4 +300,9 @@
[contents addDefaultMarkerAt:point];
}
- (void) removeMarkers
{
[contents removeMarkers];
}
@end
... ...
... ... @@ -10,7 +10,7 @@
#import "RMMapLayer.h"
#import "RMMercator.h"
@class UIImage;
@class RMMarkerStyle;
extern NSString * const RMMarkerBlueKey;
extern NSString * const RMMarkerRedKey;
... ... @@ -19,9 +19,14 @@ extern NSString * const RMMarkerRedKey;
RMMercatorPoint location;
}
- (id) initWithKey: (NSString*) key;
+ (RMMarker*) markerWithNamedStyle: (NSString*) styleName;
- (id) initWithCGImage: (CGImageRef) image anchorPoint: (CGPoint) anchorPoint;
- (id) initWithCGImage: (CGImageRef) image;
- (id) initWithKey: (NSString*) key;
- (id) initWithUIImage: (UIImage*) image;
- (id) initWithStyle: (RMMarkerStyle*) style;
- (id) initWithNamedStyle: (NSString*) styleName;
@property (assign, nonatomic) RMMercatorPoint location;
... ...
... ... @@ -7,6 +7,8 @@
//
#import "RMMarker.h"
#import "RMMarkerStyle.h"
#import "RMMarkerStyles.h"
#import "RMPixel.h"
... ... @@ -20,8 +22,18 @@ static CGImageRef _markerBlue = nil;
@synthesize location;
+ (RMMarker*) markerWithNamedStyle: (NSString*) styleName
{
return [[[RMMarker alloc] initWithNamedStyle: styleName] autorelease];
}
- (id) initWithCGImage: (CGImageRef) image
{
return [self initWithCGImage: image anchorPoint: CGPointMake(0.5, 1.0)];
}
- (id) initWithCGImage: (CGImageRef) image anchorPoint: (CGPoint) _anchorPoint
{
if (![super init])
return nil;
... ... @@ -29,7 +41,7 @@ static CGImageRef _markerBlue = nil;
self.bounds = CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image));
self.anchorPoint = CGPointMake(0.5, 1.0);
self.anchorPoint = _anchorPoint;
return self;
}
... ... @@ -44,6 +56,22 @@ static CGImageRef _markerBlue = nil;
return [self initWithCGImage:[RMMarker markerImage:key]];
}
- (id) initWithStyle: (RMMarkerStyle*) style
{
return [self initWithCGImage: [style.markerIcon CGImage] anchorPoint: style.anchorPoint];
}
- (id) initWithNamedStyle: (NSString*) styleName
{
RMMarkerStyle* style = [[RMMarkerStyles styles] styleNamed: styleName];
if (style==nil) {
NSLog(@"problem creating marker: style '%@' not found", styleName);
return [self initWithCGImage: [RMMarker markerImage: RMMarkerRedKey]];
}
return [self initWithStyle: style];
}
- (void)zoomByFactor: (float) zoomFactor Near:(CGPoint) center
{
self.position = RMScaleCGPointAboutPoint(self.position, zoomFactor, center);
... ...
//
// RMMarkerStyle.h
// MapView
//
// Created by Hauke Brandes on 29.10.08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface RMMarkerStyle : NSObject {
UIImage* markerIcon;
CGPoint anchorPoint;
}
@property (retain) UIImage* markerIcon;
@property (assign) CGPoint anchorPoint;
+ (RMMarkerStyle*) markerStyleWithIcon: (UIImage*) image;
- (RMMarkerStyle*) initWithIcon: (UIImage*) image;
- (void) dealloc;
@end
... ...
//
// RMMarkerStyle.m
// MapView
//
// Created by Hauke Brandes on 29.10.08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "RMMarkerStyle.h"
@implementation RMMarkerStyle
@synthesize markerIcon;
@synthesize anchorPoint;
+ (RMMarkerStyle*) markerStyleWithIcon: (UIImage*) image
{
return [[[RMMarkerStyle alloc] initWithIcon: image] autorelease];
}
- (RMMarkerStyle*) initWithIcon: (UIImage*) _image
{
self = [super init];
if (self==nil) return nil;
self.markerIcon = _image;
anchorPoint = CGPointMake(0.5, 1.0);
return self;
}
- (void) dealloc
{
[markerIcon release];
[super dealloc];
}
@end
... ...
//
// RMMarkerStyles.h
// MapView
//
// Created by Hauke Brandes on 29.10.08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface RMMarkerStyles : NSObject {
NSMutableDictionary* styles;
}
+ (RMMarkerStyles*) styles;
- (void) addStyle: (RMMarkerStyle*) style withName: (NSString*) name;
- (RMMarkerStyle*) styleNamed: (NSString*) name;
@end
... ...
//
// RMMarkerStyles.m
// MapView
//
// Created by Hauke Brandes on 29.10.08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "RMMarker.h"
#import "RMMarkerStyle.h"
#import "RMMarkerStyles.h"
@implementation RMMarkerStyles
static RMMarkerStyles *sharedMarkerStyles = nil;
+ (RMMarkerStyles*)styles
{
@synchronized(self) {
if (sharedMarkerStyles == nil) {
[[self alloc] init]; // assignment not done here
}
}
return sharedMarkerStyles;
}
- (RMMarkerStyles*) init
{
self = [super init];
if (self==nil) return nil;
styles = [[NSMutableDictionary dictionaryWithObjectsAndKeys:
[RMMarkerStyle markerStyleWithIcon: [UIImage imageWithCGImage: [RMMarker markerImage: RMMarkerBlueKey]]], RMMarkerBlueKey,
[RMMarkerStyle markerStyleWithIcon: [UIImage imageWithCGImage: [RMMarker markerImage: RMMarkerRedKey]]], RMMarkerRedKey,
nil
] retain];
return self;
}
+ (id)allocWithZone:(NSZone *)zone
{
@synchronized(self) {
if (sharedMarkerStyles == nil) {
sharedMarkerStyles = [super allocWithZone:zone];
return sharedMarkerStyles; // assignment and return on first allocation
}
}
return nil; //on subsequent allocation attempts return nil
}
- (id)copyWithZone:(NSZone *)zone
{
return self;
}
- (id)retain
{
return self;
}
- (unsigned)retainCount
{
return UINT_MAX; //denotes an object that cannot be released
}
- (void)release
{
//do nothing
}
- (id)autorelease
{
return self;
}
- (void) addStyle: (RMMarkerStyle*) style withName: (NSString*) name
{
[styles setObject:style forKey:name];
}
- (RMMarkerStyle*) styleNamed: (NSString*) name
{
return [styles objectForKey:name];
}
@end
... ...
... ... @@ -9,6 +9,12 @@
/* Begin PBXBuildFile section */
126692A10EB75C0A00E002D5 /* RMConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 126692A00EB75C0A00E002D5 /* RMConfiguration.m */; };
126693040EB76C0B00E002D5 /* RMConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 126692A00EB75C0A00E002D5 /* RMConfiguration.m */; };
1296F5610EB8743500FF25E0 /* RMMarkerStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = 1296F5600EB8743500FF25E0 /* RMMarkerStyle.m */; };
1296F5640EB8745300FF25E0 /* RMMarkerStyles.m in Sources */ = {isa = PBXBuildFile; fileRef = 1296F5630EB8745300FF25E0 /* RMMarkerStyles.m */; };
1296F56B0EB8849A00FF25E0 /* RMMarkerStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 1296F55F0EB8743500FF25E0 /* RMMarkerStyle.h */; };
1296F56C0EB8849B00FF25E0 /* RMMarkerStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = 1296F5600EB8743500FF25E0 /* RMMarkerStyle.m */; };
1296F56D0EB8849B00FF25E0 /* RMMarkerStyles.h in Headers */ = {isa = PBXBuildFile; fileRef = 1296F5620EB8745300FF25E0 /* RMMarkerStyles.h */; };
1296F56E0EB8849C00FF25E0 /* RMMarkerStyles.m in Sources */ = {isa = PBXBuildFile; fileRef = 1296F5630EB8745300FF25E0 /* RMMarkerStyles.m */; };
1D3623260D0F684500981E51 /* MapViewAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* MapViewAppDelegate.m */; };
1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; };
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
... ... @@ -132,6 +138,10 @@
/* Begin PBXFileReference section */
1266929F0EB75C0A00E002D5 /* RMConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMConfiguration.h; sourceTree = "<group>"; };
126692A00EB75C0A00E002D5 /* RMConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMConfiguration.m; sourceTree = "<group>"; };
1296F55F0EB8743500FF25E0 /* RMMarkerStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMMarkerStyle.h; sourceTree = "<group>"; };
1296F5600EB8743500FF25E0 /* RMMarkerStyle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMMarkerStyle.m; sourceTree = "<group>"; };
1296F5620EB8745300FF25E0 /* RMMarkerStyles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMMarkerStyles.h; sourceTree = "<group>"; };
1296F5630EB8745300FF25E0 /* RMMarkerStyles.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMMarkerStyles.m; sourceTree = "<group>"; };
1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
1D3623240D0F684500981E51 /* MapViewAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapViewAppDelegate.h; sourceTree = "<group>"; };
1D3623250D0F684500981E51 /* MapViewAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MapViewAppDelegate.m; sourceTree = "<group>"; };
... ... @@ -501,6 +511,10 @@
B8FA92180E9315EC003A9FE6 /* RMLayerSet.m */,
B8F3FC620EA2E792004D8F85 /* RMMarker.h */,
B8F3FC630EA2E792004D8F85 /* RMMarker.m */,
1296F55F0EB8743500FF25E0 /* RMMarkerStyle.h */,
1296F5600EB8743500FF25E0 /* RMMarkerStyle.m */,
1296F5620EB8745300FF25E0 /* RMMarkerStyles.h */,
1296F5630EB8745300FF25E0 /* RMMarkerStyles.m */,
);
name = Layers;
sourceTree = "<group>";
... ... @@ -593,6 +607,8 @@
B8474B9F0EB40094006A0BC1 /* FMResultSet.h in Headers */,
B8474BA20EB40094006A0BC1 /* RMTileCacheDAO.h in Headers */,
B8474BA40EB40094006A0BC1 /* RMDatabaseCache.h in Headers */,
1296F56B0EB8849A00FF25E0 /* RMMarkerStyle.h in Headers */,
1296F56D0EB8849B00FF25E0 /* RMMarkerStyles.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
... ... @@ -696,6 +712,8 @@
1D3623260D0F684500981E51 /* MapViewAppDelegate.m in Sources */,
28D7ACF80DDB3853001CB0EB /* MapViewViewController.m in Sources */,
126692A10EB75C0A00E002D5 /* RMConfiguration.m in Sources */,
1296F5610EB8743500FF25E0 /* RMMarkerStyle.m in Sources */,
1296F5640EB8745300FF25E0 /* RMMarkerStyles.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
... ... @@ -738,6 +756,8 @@
B8474BA30EB40094006A0BC1 /* RMTileCacheDAO.m in Sources */,
B8474BA50EB40094006A0BC1 /* RMDatabaseCache.m in Sources */,
126693040EB76C0B00E002D5 /* RMConfiguration.m in Sources */,
1296F56C0EB8849B00FF25E0 /* RMMarkerStyle.m in Sources */,
1296F56E0EB8849C00FF25E0 /* RMMarkerStyles.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
... ...