Fixed zooming so it zooms in on where you tap.
Showing
4 changed files
with
22 additions
and
14 deletions
@@ -106,6 +106,8 @@ enum { | @@ -106,6 +106,8 @@ enum { | ||
106 | 106 | ||
107 | - (void)moveBy: (CGSize) delta; | 107 | - (void)moveBy: (CGSize) delta; |
108 | - (void)zoomByFactor: (float) zoomFactor near:(CGPoint) center; | 108 | - (void)zoomByFactor: (float) zoomFactor near:(CGPoint) center; |
109 | + | ||
110 | +- (void)zoomInToNextNativeZoomAt:(CGPoint) pivot; | ||
109 | - (float)adjustZoomForBoundingMask:(float)zoomFactor; | 111 | - (float)adjustZoomForBoundingMask:(float)zoomFactor; |
110 | - (void)adjustMapPlacementWithScale:(float)aScale; | 112 | - (void)adjustMapPlacementWithScale:(float)aScale; |
111 | - (void)setZoomBounds:(float)aMinZoom maxZoom:(float)aMaxZoom; | 113 | - (void)setZoomBounds:(float)aMinZoom maxZoom:(float)aMaxZoom; |
@@ -281,6 +281,20 @@ | @@ -281,6 +281,20 @@ | ||
281 | } | 281 | } |
282 | } | 282 | } |
283 | 283 | ||
284 | +- (void)zoomInToNextNativeZoomAt:(CGPoint) pivot | ||
285 | +{ | ||
286 | + // Calculate rounded zoom | ||
287 | + float newZoom = roundf([self zoom] + 1); | ||
288 | + NSLog(@"zoom %f -> %f", [self zoom], newZoom); | ||
289 | + if (newZoom >= [self maxZoom]) | ||
290 | + return; | ||
291 | + else | ||
292 | + { | ||
293 | + float factor = exp2f(newZoom - [self zoom]); | ||
294 | + [self zoomByFactor:factor near:pivot]; | ||
295 | + } | ||
296 | +} | ||
297 | + | ||
284 | - (void) drawRect: (CGRect) aRect | 298 | - (void) drawRect: (CGRect) aRect |
285 | { | 299 | { |
286 | [renderer drawRect:aRect]; | 300 | [renderer drawRect:aRect]; |
@@ -57,7 +57,7 @@ typedef struct { | @@ -57,7 +57,7 @@ typedef struct { | ||
57 | - (void)zoomByFactor: (float) zoomFactor near:(CGPoint) aPoint; | 57 | - (void)zoomByFactor: (float) zoomFactor near:(CGPoint) aPoint; |
58 | - (CGPoint)latLongToPixel:(CLLocationCoordinate2D)latlong; | 58 | - (CGPoint)latLongToPixel:(CLLocationCoordinate2D)latlong; |
59 | - (CLLocationCoordinate2D)pixelToLatLong:(CGPoint)aPixel; | 59 | - (CLLocationCoordinate2D)pixelToLatLong:(CGPoint)aPixel; |
60 | -- (void)zoomInToNextNativeZoom; | 60 | +- (void)zoomInToNextNativeZoomAt:(CGPoint) pivot; |
61 | - (void)setZoom:(int)zoomInt; | 61 | - (void)setZoom:(int)zoomInt; |
62 | - (void)zoomWithLatLngBoundsNorthEast:(CLLocationCoordinate2D)ne SouthWest:(CLLocationCoordinate2D)se; | 62 | - (void)zoomWithLatLngBoundsNorthEast:(CLLocationCoordinate2D)ne SouthWest:(CLLocationCoordinate2D)se; |
63 | - (void)setZoomBounds:(float)aMinZoom maxZoom:(float)aMaxZoom; | 63 | - (void)setZoomBounds:(float)aMinZoom maxZoom:(float)aMaxZoom; |
@@ -288,12 +288,10 @@ | @@ -288,12 +288,10 @@ | ||
288 | } | 288 | } |
289 | } | 289 | } |
290 | 290 | ||
291 | + // Calculate the gesture. | ||
291 | lastGesture = [self getGestureDetails:[event allTouches]]; | 292 | lastGesture = [self getGestureDetails:[event allTouches]]; |
292 | - | ||
293 | - // NSLog(@"touchesEnded %d ... lastgesture at %f, %f", [[event allTouches] count], lastGesture.center.x, lastGesture.center.y); | ||
294 | - | ||
295 | - // NSLog(@"Assemble."); | ||
296 | 293 | ||
294 | + // If there are no more fingers on the screen, resume any slow operations. | ||
297 | if (lastGesture.numTouches == 0) | 295 | if (lastGesture.numTouches == 0) |
298 | { | 296 | { |
299 | [self unRegisterPausedDraggingDispatcher]; | 297 | [self unRegisterPausedDraggingDispatcher]; |
@@ -303,13 +301,11 @@ | @@ -303,13 +301,11 @@ | ||
303 | 301 | ||
304 | if (touch.tapCount == 2) | 302 | if (touch.tapCount == 2) |
305 | { | 303 | { |
306 | -// [contents printDebuggingInformation]; | ||
307 | - | ||
308 | if (delegateHasDoubleTapOnMap) { | 304 | if (delegateHasDoubleTapOnMap) { |
309 | [delegate doubleTapOnMap: self At: lastGesture.center]; | 305 | [delegate doubleTapOnMap: self At: lastGesture.center]; |
310 | } else { | 306 | } else { |
311 | // Default behaviour matches built in maps.app | 307 | // Default behaviour matches built in maps.app |
312 | - [self zoomInToNextNativeZoom]; | 308 | + [self zoomInToNextNativeZoomAt: [touch locationInView:self]]; |
313 | } | 309 | } |
314 | } | 310 | } |
315 | 311 | ||
@@ -374,13 +370,9 @@ | @@ -374,13 +370,9 @@ | ||
374 | 370 | ||
375 | #pragma mark Auto Zoom | 371 | #pragma mark Auto Zoom |
376 | 372 | ||
377 | - | ||
378 | -- (void)zoomInToNextNativeZoom | 373 | +- (void)zoomInToNextNativeZoomAt: (CGPoint) point |
379 | { | 374 | { |
380 | - | ||
381 | - // Calculate rounded zoom | ||
382 | - float newZoom = roundf([contents zoom] + 1); | ||
383 | - [contents setZoom:newZoom];// Contents limits zooms which are too high | 375 | + [contents zoomInToNextNativeZoomAt:point]; |
384 | } | 376 | } |
385 | 377 | ||
386 | 378 |
-
Please register or login to post a comment