@@ -5,11 +5,12 @@ @interface AkClusterElementBuilder ()
55
66@property NSMutableDictionary * markerStyles;
77@property (nonatomic ) UIImage *markerImage;
8- @property (nonatomic ) UIColor *markerColor;
8+ @property (nonatomic ) NTColor *markerColor;
99@property (nonatomic ) UIColor *textColor;
1010@property (nonatomic ) NSUInteger markerSize;
1111@property (nonatomic ) NSUInteger textSize;
1212@property (nonatomic ) NSString * shape;
13+ @property (nonatomic ) UIFont* font;
1314
1415@end
1516@implementation AkClusterElementBuilder : NTClusterElementBuilder
@@ -25,21 +26,25 @@ -(id)init {
2526- (void ) setBitmap : (UIImage *)value {
2627 self.markerImage = value;
2728}
28- - (void ) setColor : (UIColor *)value {
29+ - (void ) setColor : (NTColor *)value {
2930 self.markerColor = value;
3031 }
31- - (void ) setTextColor : (UIColor *)value {
32- self.textColor = value;
33- }
32+ // - (void) setTextColor: (UIColor *)value{
33+ // self.textColor = value;
34+ // }
3435- (void ) setSize : (NSUInteger )value {
3536 self.markerSize = value;
3637}
37- - (void ) setTextSize : (NSUInteger )value {
38- self.textSize = value;
39- }
40- - (void ) setShape : (NSString *)value {
41- self.shape = value;
42- }
38+ // - (void) setTextSize: (NSUInteger)value{
39+ // self.textSize = value;
40+ // }
41+ // - (void) setShape: (NSString *)value {
42+ // self.shape = value;
43+ // }
44+
45+ // - (void) setFont: (UIFont *)value {
46+ // self.font = value;
47+ // }
4348
4449
4550
@@ -63,20 +68,34 @@ -(NTVectorElement*)buildClusterElement:(NTMapPos *)mapPos elements:(NTVectorElem
6368 self.markerImage = [UIImage imageNamed: @" marker_black.png" ];
6469 }
6570
66- UIGraphicsBeginImageContext (self.markerImage .size );
71+ CGSize size = self.markerImage .size ;
72+ UIGraphicsBeginImageContext (size);
6773 [self .markerImage drawAtPoint: CGPointMake (0 , 0 )];
74+
6875
69- CGRect rect = CGRectMake (0 , 15 , self.markerImage .size .width , self.markerImage .size .height );
70- if (self.textColor ) {
71- [self .textColor set ];
72- } else {
73- [[UIColor whiteColor ] set ];
74- }
7576
7677 NSMutableParagraphStyle * style = [[NSParagraphStyle defaultParagraphStyle ] mutableCopy ];
7778 [style setAlignment: NSTextAlignmentCenter];
7879
79- NSDictionary * attr = [NSDictionary dictionaryWithObject: style forKey: NSParagraphStyleAttributeName ];
80+ NSMutableDictionary * attr = [NSMutableDictionary dictionaryWithObject: style forKey: NSParagraphStyleAttributeName ];
81+ UIFont* font;
82+ if (self.font ) {
83+ font = [self .font fontWithSize: self .textSize];
84+ } else {
85+ font = [UIFont systemFontOfSize: self .textSize];
86+ }
87+ UIColor* color = [UIColor whiteColor ];
88+ if (self.textColor ) {
89+ color = self.textColor ;
90+ }
91+ [attr setObject: color forKey: NSForegroundColorAttributeName ];
92+ [attr setObject: font forKey: NSFontAttributeName ];
93+
94+ CGSize textSize = [styleKey sizeWithFont: font
95+ constrainedToSize: size
96+ lineBreakMode: (NSLineBreakByWordWrapping)];
97+
98+ CGRect rect = CGRectMake (0 , size.height /2 - textSize.height /2 , size.width , size.height );
8099 [styleKey drawInRect: CGRectIntegral (rect) withAttributes: attr];
81100
82101 UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext ();
@@ -92,7 +111,7 @@ -(NTVectorElement*)buildClusterElement:(NTMapPos *)mapPos elements:(NTVectorElem
92111 [styleBuilder setSize: self .markerSize];
93112
94113 if (self.markerColor != nil ) {
95- [styleBuilder setColor: [CartoAdditionsUtils toNTColor: self .markerColor] ];
114+ [styleBuilder setColor: self .markerColor];
96115 }
97116 markerStyle = [styleBuilder buildStyle ];
98117 } else {
@@ -104,7 +123,7 @@ -(NTVectorElement*)buildClusterElement:(NTMapPos *)mapPos elements:(NTVectorElem
104123 [styleBuilder setPlacementPriority: (int )[elements size ]];
105124
106125 if (self.markerColor != nil ) {
107- [styleBuilder setColor: [CartoAdditionsUtils toNTColor: self .markerColor] ];
126+ [styleBuilder setColor: self .markerColor];
108127 }
109128 markerStyle = [styleBuilder buildStyle ];
110129 }
0 commit comments