Authored by devel-hb

MapView supports delegate for move, zoom and doubleTap-Events

... ... @@ -11,6 +11,7 @@
#import "RMFoundation.h"
#import "RMLatLong.h"
#import "RMMapViewDelegate.h"
// iPhone-specific mapview stuff.
// Handles event handling, whatnot.
... ... @@ -30,9 +31,10 @@ typedef struct {
@interface RMMapView : UIView
{
RMMapContents *contents;
id<RMMapViewDelegate> delegate;
bool enableDragging;
bool enableZoom;
BOOL enableDragging;
BOOL enableZoom;
RMGestureDetails lastGesture;
}
... ... @@ -40,6 +42,10 @@ typedef struct {
// property. The contents structure holds the actual map bits.
@property (readonly) RMMapContents *contents;
// do not retain the delegate so you can let the corresponding controller implement the
// delegate without circular references
@property (assign) id<RMMapViewDelegate> delegate;
- (void)moveToLatLong: (CLLocationCoordinate2D)latlong;
- (void)moveToXYPoint: (RMXYPoint)aPoint;
... ...
... ... @@ -8,12 +8,21 @@
#import "RMMapView.h"
#import "RMMapContents.h"
#import "RMMapViewDelegate.h"
#import "RMTileLoader.h"
#import "RMMercatorToScreenProjection.h"
#import "RMMarker.h"
@implementation RMMapView (Internal)
BOOL delegateHasBeforeMapMove;
BOOL delegateHasAfterMapMove;
BOOL delegateHasBeforeMapZoomByFactor;
BOOL delegateHasAfterMapZoomByFactor;
BOOL delegateHasDoubleTapOnMap;
@end
@implementation RMMapView
-(void) initValues
... ... @@ -69,28 +78,58 @@
return [[contents retain] autorelease];
}
#pragma mark Delegate
@dynamic delegate;
- (void) setDelegate: (id<RMMapViewDelegate>) _delegate
{
if (delegate == _delegate) return;
delegate = _delegate;
delegateHasBeforeMapMove = [(NSObject*) delegate respondsToSelector: @selector(beforeMapMove:)];
delegateHasAfterMapMove = [(NSObject*) delegate respondsToSelector: @selector(afterMapMove:)];
delegateHasBeforeMapZoomByFactor = [(NSObject*) delegate respondsToSelector: @selector(beforeMapZoom: byFactor: near:)];
delegateHasAfterMapZoomByFactor = [(NSObject*) delegate respondsToSelector: @selector(afterMapZoom: byFactor: near:)];
delegateHasDoubleTapOnMap = [(NSObject*) delegate respondsToSelector: @selector(doubleTapOnMap:)];
NSLog(@"%d %d %d %d %d", delegateHasBeforeMapMove, delegateHasAfterMapMove, delegateHasBeforeMapZoomByFactor, delegateHasAfterMapZoomByFactor, delegateHasDoubleTapOnMap);
}
- (id<RMMapViewDelegate>) delegate
{
return delegate;
}
#pragma mark Movement
-(void) moveToXYPoint: (RMXYPoint) aPoint
{
// TODO Add delegate hooks
if (delegateHasBeforeMapMove) [delegate beforeMapMove: self];
[contents moveToXYPoint:aPoint];
if (delegateHasAfterMapMove) [delegate afterMapMove: self];
}
-(void) moveToLatLong: (CLLocationCoordinate2D) point
{
// TODO Add delegate hooks
if (delegateHasBeforeMapMove) [delegate beforeMapMove: self];
[contents moveToLatLong:point];
if (delegateHasAfterMapMove) [delegate afterMapMove: self];
}
- (void)moveBy: (CGSize) delta
{
// TODO Add delegate hooks
if (delegateHasBeforeMapMove) [delegate beforeMapMove: self];
[contents moveBy:delta];
if (delegateHasAfterMapMove) [delegate afterMapMove: self];
}
- (void)zoomByFactor: (float) zoomFactor near:(CGPoint) center
{
// TODO Add delegate hooks
if (delegateHasBeforeMapZoomByFactor) [delegate beforeMapZoom: self byFactor: zoomFactor near: center];
[contents zoomByFactor:zoomFactor near:center];
if (delegateHasAfterMapZoomByFactor) [delegate afterMapZoom: self byFactor: zoomFactor near: center];
}
#pragma mark Event handling
... ... @@ -212,30 +251,12 @@
//Double-tap detection (currently used for debugging pixelToLatLng() method)
if (touch.tapCount == 2)
{
/* NSLog(@"***************************************************");
NSLog(@"Begin double-tap pixel/LatLng translation debug test");
CGPoint pixel = [touch locationInView:self];
NSLog(@"Double-tap detected at: x=%f, y=%f", pixel.x, pixel.y);
CLLocationCoordinate2D touchLatLng = [self pixelToLatLong:pixel];
NSLog(@"Double-tap (x=%f, y=%f) is equivalent to: %f, %f", pixel.x, pixel.y, touchLatLng.latitude, touchLatLng.longitude);
RMXYPoint merc = [[contents mercatorToScreenProjection] projectScreenPointToXY:pixel];
NSLog(@"Which is mercator %f %f", merc.x, merc.y);
CLLocationCoordinate2D point;
point.latitude = touchLatLng.latitude;
point.longitude = touchLatLng.longitude;
CGPoint screenPoint = [self latLongToPixel:point];
NSLog(@"Converted LatLng to Pixel says we tapped at: x=%f, y=%f", screenPoint.x, screenPoint.y);
NSLog(@"***************************************************");
*/
// For consistancy with the built-in map app, I want to do something like this:
// [contents zoomInToNextNativeZoom];
if (delegateHasDoubleTapOnMap) {
[delegate doubleTapOnMap: self];
} else {
// TODO: default behaviour
// [contents zoomInToNextNativeZoom];
}
}
//***************************************************************************************
... ...
//
// RMMapViewDelegate.h
// MapView
//
// Created by Hauke Brandes on 31.10.08.
// Copyright 2008 Orbster GmbH. All rights reserved.
//
#import <UIKit/UIKit.h>
@class RMMapView;
@protocol RMMapViewDelegate
@optional
- (void) beforeMapMove: (RMMapView*) map;
- (void) afterMapMove: (RMMapView*) map ;
- (void) beforeMapZoom: (RMMapView*) map byFactor: (float) zoomFactor near:(CGPoint) center;
- (void) afterMapZoom: (RMMapView*) map byFactor: (float) zoomFactor near:(CGPoint) center;
- (void) doubleTapOnMap: (RMMapView*) map;
@end
... ...
... ... @@ -140,6 +140,7 @@
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>"; };
12F2031E0EBB65E9003D7B6B /* RMMapViewDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMMapViewDelegate.h; 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>"; };
... ... @@ -521,6 +522,7 @@
B8C9746A0E8A1A50007D16AD /* RMMapView.m */,
B8C974B60E8A280A007D16AD /* RMMapContents.h */,
B8C974B70E8A280A007D16AD /* RMMapContents.m */,
12F2031E0EBB65E9003D7B6B /* RMMapViewDelegate.h */,
B8C974B30E8A23C5007D16AD /* Coordinate Systems */,
B83E64E20E80E73F001663B6 /* Projections */,
B83E64EB0E80E73F001663B6 /* Tile Source */,
... ...