Authored by Thomas Rasch

o Synchronize marker movement with the map scroll view (addresses #7)

... ... @@ -65,12 +65,12 @@
}
/// return nil for certain animation keys to block core animation
- (id <CAAction>)actionForKey:(NSString *)key
{
if ([key isEqualToString:@"position"] || [key isEqualToString:@"bounds"])
return nil;
else
return [super actionForKey:key];
}
//- (id <CAAction>)actionForKey:(NSString *)key
//{
// if ([key isEqualToString:@"position"] || [key isEqualToString:@"bounds"])
// return nil;
// else
// return [super actionForKey:key];
//}
@end
... ...
... ... @@ -66,7 +66,7 @@
- (void)createMapView;
- (void)correctPositionOfAllAnnotations;
- (void)correctPositionOfAllAnnotationsIncludingInvisibles:(BOOL)correctAllLayers;
- (void)correctPositionOfAllAnnotationsIncludingInvisibles:(BOOL)correctAllLayers wasZoom:(BOOL)wasZoom;
@end
... ... @@ -100,6 +100,7 @@
float _lastZoom;
CGPoint _lastContentOffset, _accumulatedDelta;
BOOL _mapScrollViewIsZooming;
}
@synthesize decelerationMode;
... ... @@ -949,6 +950,8 @@
[mapScrollView removeObserver:self forKeyPath:@"contentOffset"];
[mapScrollView removeFromSuperview]; [mapScrollView release]; mapScrollView = nil;
_mapScrollViewIsZooming = NO;
int tileSideLength = [[self tileSource] tileSideLength];
CGSize contentSize = CGSizeMake(tileSideLength, tileSideLength); // zoom level 1
... ... @@ -1028,10 +1031,17 @@
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view
{
_mapScrollViewIsZooming = YES;
if (_delegateHasBeforeMapZoom)
[delegate beforeMapZoom:self];
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
_mapScrollViewIsZooming = NO;
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
[self correctPositionOfAllAnnotations];
... ... @@ -1189,12 +1199,15 @@
}
else
{
[self correctPositionOfAllAnnotations];
if (_mapScrollViewIsZooming)
[self correctPositionOfAllAnnotationsIncludingInvisibles:NO wasZoom:YES];
else
[self correctPositionOfAllAnnotations];
}
}
else
{
[self correctPositionOfAllAnnotationsIncludingInvisibles:NO];
[self correctPositionOfAllAnnotationsIncludingInvisibles:NO wasZoom:YES];
_lastZoom = zoom;
}
... ... @@ -1513,11 +1526,21 @@
// RMLog(@"Change annotation at {%f,%f} in mapView {%f,%f}", annotation.position.x, annotation.position.y, mapScrollView.contentSize.width, mapScrollView.contentSize.height);
}
- (void)correctPositionOfAllAnnotationsIncludingInvisibles:(BOOL)correctAllAnnotations
- (void)correctPositionOfAllAnnotationsIncludingInvisibles:(BOOL)correctAllAnnotations wasZoom:(BOOL)wasZoom
{
// Prevent blurry movements
[CATransaction begin];
[CATransaction setAnimationDuration:0];
// Synchronize marker movement with the map scroll view
if (wasZoom && !mapScrollView.isZooming)
{
[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[CATransaction setAnimationDuration:0.30];
}
else
{
[CATransaction setAnimationDuration:0.0];
}
_accumulatedDelta.x = 0.0;
_accumulatedDelta.y = 0.0;
... ... @@ -1549,8 +1572,6 @@
for (RMAnnotation *annotation in annotationsToCorrect)
{
[self correctScreenPosition:annotation];
if (annotation.layer == nil && _delegateHasLayerForAnnotation)
annotation.layer = [delegate mapView:self layerForAnnotation:annotation];
if (annotation.layer == nil)
... ... @@ -1563,6 +1584,8 @@
[visibleAnnotations addObject:annotation];
}
[self correctScreenPosition:annotation];
[previousVisibleAnnotations removeObject:annotation];
}
... ... @@ -1643,7 +1666,7 @@
- (void)correctPositionOfAllAnnotations
{
[self correctPositionOfAllAnnotationsIncludingInvisibles:YES];
[self correctPositionOfAllAnnotationsIncludingInvisibles:YES wasZoom:NO];
}
- (NSArray *)annotations
... ... @@ -1691,7 +1714,7 @@
}
}
[self correctPositionOfAllAnnotationsIncludingInvisibles:YES];
[self correctPositionOfAllAnnotationsIncludingInvisibles:YES wasZoom:NO];
}
- (void)removeAnnotation:(RMAnnotation *)annotation
... ...
... ... @@ -45,6 +45,8 @@ typedef enum {
@property (nonatomic, readonly) RMQuadTreeNode *southWest;
@property (nonatomic, readonly) RMQuadTreeNode *southEast;
@property (nonatomic, readonly) RMAnnotation *cachedClusterAnnotation;
// Operations on this node and all subnodes
@property (nonatomic, readonly) NSArray *enclosedAnnotations;
@property (nonatomic, readonly) NSUInteger countEnclosedAnnotations;
... ...
... ... @@ -34,7 +34,7 @@
@synthesize nodeType;
@synthesize boundingBox, northWestBoundingBox, northEastBoundingBox, southWestBoundingBox, southEastBoundingBox;
@synthesize parentNode, northWest, northEast, southWest, southEast;
@synthesize parentNode, northWest, northEast, southWest, southEast, cachedClusterAnnotation;
- (id)initWithMapView:(RMMapView *)aMapView forParent:(RMQuadTreeNode *)aParentNode inBoundingBox:(RMProjectedRect)aBoundingBox
{
... ... @@ -263,6 +263,11 @@
return unclusteredAnnotations;
}
- (RMAnnotation *)cachedClusterAnnotation
{
return cachedClusterAnnotation;
}
- (void)addAnnotationsInBoundingBox:(RMProjectedRect)aBoundingBox toMutableArray:(NSMutableArray *)someArray createClusterAnnotations:(BOOL)createClusterAnnotations withClusterSize:(RMProjectedSize)clusterSize findGravityCenter:(BOOL)findGravityCenter
{
if (createClusterAnnotations)
... ... @@ -316,7 +321,11 @@
clusterMarkerPosition = RMProjectedPointMake(boundingBox.origin.x + halfWidth, boundingBox.origin.y + (boundingBox.size.height / 2.0));
}
cachedClusterAnnotation = [[RMAnnotation alloc] initWithMapView:mapView coordinate:[[mapView projection] projectedPointToCoordinate:clusterMarkerPosition] andTitle:[NSString stringWithFormat:@"%d", enclosedAnnotationsCount]];
CLLocationCoordinate2D clusterMarkerCoordinate = [[mapView projection] projectedPointToCoordinate:clusterMarkerPosition];
cachedClusterAnnotation = [[RMAnnotation alloc] initWithMapView:mapView
coordinate:clusterMarkerCoordinate
andTitle:[NSString stringWithFormat:@"%d", enclosedAnnotationsCount]];
cachedClusterAnnotation.annotationType = kRMClusterAnnotationTypeName;
cachedClusterAnnotation.userInfo = self;
}
... ...