Authored by Joseph G

Cleaned up the marker code.

... ... @@ -57,7 +57,7 @@
// Put the marker back
RMMarker *marker = [[RMMarker alloc]initWithKey:RMMarkerBlueKey];
[marker addTextLabel:@"Hello"];
[marker setTextLabel:@"Hello"];
[markerManager addMarker:marker AtLatLong:[[mapView contents] mapCenter]];
// [markerManager addDefaultMarkerAt:[[mapView contents] mapCenter]];
... ... @@ -85,8 +85,7 @@
// [markerManager addDefaultMarkerAt:coolPlace];
RMMarker *marker = [[RMMarker alloc]initWithKey:RMMarkerBlueKey];
[marker addTextLabel:@"Hello" atPosition:CGPointMake(15.0,15.0)];
[marker setTextLabel:@"Hello"];
[markerManager addMarker:marker AtLatLong:[[mapView contents] mapCenter]];
[marker release];
... ...
... ... @@ -64,6 +64,8 @@ enum {
RMMapRenderer *renderer;
NSUInteger boundingMask;
// These should probably not be here. Instead equivalent functions
// should just fetch them when needed from the tileosurce.
float minZoom, maxZoom;
id<RMTilesUpdateDelegate> tilesUpdateDelegate;
... ...
... ... @@ -308,8 +308,9 @@
[mercatorToTileProjection release];
mercatorToTileProjection = [[tileSource mercatorToTileProjection] retain];
[self setMinZoom:[newTileSource minZoom]];
[self setMaxZoom:[newTileSource maxZoom]];
// TODO: Fix the min / max zoom.
// [self setMinZoom:[newTileSource minZoom]];
// [self setMaxZoom:[newTileSource maxZoom]];
[imagesOnScreen setTileSource:tileSource];
... ...
... ... @@ -243,6 +243,7 @@
if ([[furthestLayerDown class]isSubclassOfClass: [RMMarker class]]) {
if ([furthestLayerDown respondsToSelector:@selector(touchesBegan:withEvent:)]) {
[furthestLayerDown performSelector:@selector(touchesBegan:withEvent:) withObject:touches withObject:event];
return;
}
}
... ... @@ -267,6 +268,7 @@
if ([[furthestLayerDown class]isSubclassOfClass: [RMMarker class]]) {
if ([furthestLayerDown respondsToSelector:@selector(touchesCancelled:withEvent:)]) {
[furthestLayerDown performSelector:@selector(touchesCancelled:withEvent:) withObject:touches withObject:event];
return;
}
}
... ... @@ -284,6 +286,7 @@
if ([[furthestLayerDown class]isSubclassOfClass: [RMMarker class]]) {
if ([furthestLayerDown respondsToSelector:@selector(touchesEnded:withEvent:)]) {
[furthestLayerDown performSelector:@selector(touchesEnded:withEvent:) withObject:touches withObject:event];
return;
}
}
... ... @@ -324,6 +327,18 @@
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[touches allObjects] objectAtIndex:0];
//Check if the touch hit a RMMarker subclass and if so, forward the touch event on
//so it can be handled there
id furthestLayerDown = [[[self contents] overlay] hitTest:[touch locationInView:self]];
if ([[furthestLayerDown class]isSubclassOfClass: [RMMarker class]]) {
if ([furthestLayerDown respondsToSelector:@selector(touchesMoved:withEvent:)]) {
[furthestLayerDown performSelector:@selector(touchesMoved:withEvent:) withObject:touches withObject:event];
return;
}
}
RMGestureDetails newGesture = [self getGestureDetails:[event allTouches]];
if (enableDragging && newGesture.numTouches == lastGesture.numTouches)
... ...
... ... @@ -18,6 +18,9 @@ extern NSString * const RMMarkerRedKey;
@interface RMMarker : RMMapLayer <RMMovingMapLayer> {
RMXYPoint location;
NSObject* data;
// A label which comes up when you tap the marker
UIView* label;
}
+ (RMMarker*) markerWithNamedStyle: (NSString*) styleName;
... ... @@ -30,8 +33,9 @@ extern NSString * const RMMarkerRedKey;
- (id) initWithUIImage: (UIImage*) image;
- (id) initWithStyle: (RMMarkerStyle*) style;
- (id) initWithNamedStyle: (NSString*) styleName;
- (void) addLabel: (UIView*)label;
- (void) addTextLabel: (NSString*)text atPosition:(CGPoint)position;
- (void) setLabel: (UIView*)aLabel;
- (void) setTextLabel: (NSString*)text;
- (void) dealloc;
... ... @@ -41,5 +45,4 @@ extern NSString * const RMMarkerRedKey;
// Call this with either RMMarkerBlue or RMMarkerRed for the key.
+ (CGImageRef) markerImage: (NSString *) key;
- (NSInteger) getPixelWidthForFont:(NSString *)aString font:(UIFont *)aFont;
@end
... ...
... ... @@ -39,11 +39,12 @@ static CGImageRef _markerBlue = nil;
return nil;
self.contents = (id)image;
self.bounds = CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image));
self.anchorPoint = _anchorPoint;
self.masksToBounds = NO;
label = nil;
return self;
}
... ... @@ -73,34 +74,50 @@ static CGImageRef _markerBlue = nil;
return [self initWithStyle: style];
}
- (void) addLabel: (UIView*)label
- (void) setLabel: (UIView*)aLabel
{
[label retain];
CALayer *layer = [label layer];
[self addSublayer:layer];
//[self insertSublayer:[label layer] above:self];
if (label != nil)
{
[[label layer] removeFromSuperlayer];
[label release];
}
if (aLabel != nil)
{
label = [aLabel retain];
[self addSublayer:[label layer]];
}
}
- (void) addTextLabel: (NSString*)text atPosition:(CGPoint)position
- (void) setTextLabel: (NSString*)text
{
NSInteger textWidth = [self getPixelWidthForFont:text font:[UIFont systemFontOfSize:12]];
NSLog(@"TEXT WIDTH: %d",textWidth);
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(position.x,position.y,textWidth, 20)];
CGSize textSize = [text sizeWithFont:[UIFont systemFontOfSize:15]];
CGRect frame = CGRectMake([self bounds].size.width / 2 - textSize.width / 2,
4,
textSize.width+4,
textSize.height+4);
[label setNumberOfLines:1];
[label setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor blackColor]];
[label setFont:[UIFont systemFontOfSize:12]];
[label setText:text];
frame.size = [text sizeWithFont:[UIFont systemFontOfSize:15]];
[self addLabel:label];
UILabel *aLabel = [[UILabel alloc] initWithFrame:frame];
// UITextField *aLabel = [[UITextField alloc] initWithFrame:frame];
// [aLabel setBorderStyle:UITextBorderStyleRoundedRect];
// [aLabel setNumberOfLines:1];
[aLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[aLabel setBackgroundColor:[UIColor clearColor]];
[aLabel setTextColor:[UIColor blackColor]];
[aLabel setFont:[UIFont systemFontOfSize:15]];
[aLabel setTextAlignment:UITextAlignmentCenter];
[aLabel setText:text];
// [aLabel setCenter:CGPointMake(,0)];
[self setLabel:aLabel];
[label release];
}
- (void) dealloc
{
[label release];
[data release];
[super dealloc];
}
... ... @@ -149,12 +166,10 @@ static CGImageRef _markerBlue = nil;
return nil;
}
- (NSInteger) getPixelWidthForFont:(NSString *)aString font:(UIFont *)aFont {
return [aString sizeWithFont:aFont].width;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[label setAlpha:1.0f - [label alpha]];
// [self setTextLabel:@"hello there"];
// NSLog(@"marker at %f %f m %f %f touchesEnded", self.position.x, self.position.y, location.x, location.y);
}
... ...
... ... @@ -40,6 +40,7 @@
kCGPathEOFillStroke */
CGPathDrawingMode drawingMode;
BOOL scaleLineWidth;
float renderedScale;
RMMapContents *contents;
... ...
... ... @@ -26,11 +26,13 @@
path = CGPathCreateMutable();
lineWidth = 10.0f;
lineWidth = 100.0f;
drawingMode = kCGPathFillStroke;
lineColor = [UIColor blueColor];
lineColor = [UIColor blackColor];
fillColor = [UIColor redColor];
self.masksToBounds = NO;
scaleLineWidth = YES;
// self.frame = CGRectMake(100, 100, 100, 100);
// [self setNeedsDisplayOnBoundsChange:YES];
... ... @@ -140,6 +142,7 @@
CGContextSetStrokeColorWithColor(theContext, [lineColor CGColor]);
CGContextSetFillColorWithColor(theContext, [fillColor CGColor]);
CGContextDrawPath(theContext, drawingMode);
CGContextClosePath(theContext);
}
- (void) closePath
... ... @@ -197,8 +200,8 @@
[super zoomByFactor:zoomFactor near:pivot];
float newScale = [contents scale];
if (newScale / renderedScale >= 1.2f
|| newScale / renderedScale <= 0.8f)
if (newScale / renderedScale >= 2.0f
|| newScale / renderedScale <= 0.4f)
{
[self setNeedsDisplay];
}
... ...