Authored by Thomas Rasch

o Small changes on the search for a nasty bug

... ... @@ -49,7 +49,6 @@
@synthesize hasBoundingBox;
@synthesize enabled;
@synthesize position;
@synthesize layer;
@synthesize quadTreeNode;
+ (id)annotationWithMapView:(RMMapView *)aMapView coordinate:(CLLocationCoordinate2D)aCoordinate andTitle:(NSString *)aTitle
... ... @@ -66,7 +65,6 @@
self.coordinate = aCoordinate;
self.title = aTitle;
self.userInfo = nil;
self.layer = nil;
self.quadTreeNode = nil;
self.annotationType = nil;
... ... @@ -75,17 +73,19 @@
self.hasBoundingBox = NO;
self.enabled = YES;
layer = nil;
return self;
}
- (void)dealloc
{
[[self.mapView quadTree] removeAnnotation:self];
self.title = nil;
self.userInfo = nil;
self.mapView = nil;
self.layer = nil;
[[self.mapView quadTree] removeAnnotation:self];
self.quadTreeNode = nil;
self.mapView = nil;
self.annotationType = nil;
self.annotationIcon = nil;
... ... @@ -116,19 +116,27 @@
- (void)setPosition:(CGPoint)aPosition
{
position = aPosition;
if (layer) {
layer.position = aPosition;
}
if (layer) layer.position = aPosition;
}
- (RMMapLayer *)layer
{
return layer;
}
- (void)setLayer:(RMMapLayer *)aLayer
{
if (layer != aLayer) {
[layer removeFromSuperlayer]; [layer release];
layer = [aLayer retain];
if (layer.superlayer) [layer removeFromSuperlayer];
[layer release]; layer = nil;
}
if (aLayer) {
layer = aLayer;
[layer retain];
layer.annotation = self;
layer.position = self.position;
}
layer.position = self.position;
}
- (BOOL)isAnnotationWithinBounds:(CGRect)bounds
... ...
... ... @@ -56,6 +56,13 @@
return self;
}
- (void)dealloc
{
self.annotation = nil;
self.userInfo = nil;
[super dealloc];
}
/// return nil for certain animation keys to block core animation
- (id <CAAction>)actionForKey:(NSString *)key
{
... ... @@ -65,19 +72,4 @@
return [super actionForKey:key];
}
- (void)moveBy:(CGSize)delta
{
self.position = RMTranslateCGPointBy(self.position, delta);
}
- (void)zoomByFactor:(float)zoomFactor near:(CGPoint)pivot
{
// a empty layer has size=(0,0) which cause divide by 0 if scaled
if (self.bounds.size.width == 0.0 || self.bounds.size.height == 0.0)
return;
self.position = RMScaleCGPointAboutPoint(self.position, zoomFactor, pivot);
self.bounds = RMScaleCGRectAboutPoint(self.bounds, zoomFactor, pivot);
}
@end
... ...
... ... @@ -1352,7 +1352,7 @@
boundingBox.size.height += 2*boundingBoxBuffer;
NSArray *annotationsToCorrect = [quadTree annotationsInProjectedRect:boundingBox createClusterAnnotations:self.enableClustering withClusterSize:RMProjectedSizeMake(self.clusterMarkerSize.width * self.metersPerPixel, self.clusterMarkerSize.height * self.metersPerPixel) findGravityCenter:self.positionClusterMarkersAtTheGravityCenter];
NSMutableSet *previousVisibleAnnotations = [NSMutableSet setWithSet:visibleAnnotations];
NSMutableSet *previousVisibleAnnotations = [[NSMutableSet alloc] initWithSet:visibleAnnotations];
for (RMAnnotation *annotation in annotationsToCorrect)
{
... ... @@ -1375,10 +1375,12 @@
{
if (_delegateHasWillHideLayerForAnnotation) [delegate mapView:self willHideLayerForAnnotation:annotation];
annotation.layer = nil;
[visibleAnnotations removeObject:annotation];
if (_delegateHasDidHideLayerForAnnotation) [delegate mapView:self didHideLayerForAnnotation:annotation];
[visibleAnnotations removeObject:annotation];
}
[previousVisibleAnnotations release];
// RMLog(@"%d annotations on screen, %d total", [overlayView sublayersCount], [annotations count]);
} else
... ...
... ... @@ -76,7 +76,6 @@
- (void)dealloc
{
self.userInfo = nil;
self.label = nil;
self.textForegroundColor = nil;
self.textBackgroundColor = nil;
... ...
... ... @@ -390,16 +390,9 @@
}
}
//- (void)moveBy:(CGSize)delta
//{
// if (enableDragging) {
// [super moveBy:delta];
// }
//}
//
- (void)setPosition:(CGPoint)value
- (void)setPosition:(CGPoint)newPosition
{
if (CGPointEqualToPoint(value, super.position) && CGRectEqualToRect(self.bounds, previousBounds)) return;
if (CGPointEqualToPoint(newPosition, super.position) && CGRectEqualToRect(self.bounds, previousBounds)) return;
[self recalculateGeometry];
}
... ...
... ... @@ -63,7 +63,7 @@
- (void)dealloc
{
cachedClusterAnnotation.layer = nil; [cachedClusterAnnotation release]; cachedClusterAnnotation = nil;
[cachedClusterAnnotation release]; cachedClusterAnnotation = nil;
@synchronized (annotations) {
for (RMAnnotation *annotation in annotations)
... ... @@ -160,13 +160,13 @@
- (void)removeAnnotation:(RMAnnotation *)annotation
{
if (!annotation.quadTreeNode) return;
annotation.quadTreeNode = nil;
@synchronized (annotations) {
[annotations removeObject:annotation];
}
[self removeUpwardsAllCachedClusterAnnotations];
annotation.quadTreeNode = nil;
}
- (void)annotationDidChangeBoundingBox:(RMAnnotation *)annotation
... ... @@ -302,7 +302,7 @@
- (void)removeUpwardsAllCachedClusterAnnotations
{
if (parentNode) [parentNode removeUpwardsAllCachedClusterAnnotations];
cachedClusterAnnotation.layer = nil; [cachedClusterAnnotation release]; cachedClusterAnnotation = nil;
[cachedClusterAnnotation release]; cachedClusterAnnotation = nil;
}
@end
... ...
... ... @@ -13,6 +13,7 @@
#import "RMMarker.h"
#import "RMProjection.h"
#import "RMAnnotation.h"
#import "RMQuadTree.h"
@implementation MainViewController
... ... @@ -29,7 +30,7 @@
- (void)addMarkers
{
#define kNumberRows 1
#define kNumberRows 3
#define kNumberColumns 9
#define kSpacing 0.1
... ... @@ -73,6 +74,8 @@
{
[super viewDidLoad];
[mapView setDelegate:self];
mapView.enableClustering = YES;
mapView.positionClusterMarkersAtTheGravityCenter = NO;
mapView.tileSource = [[[RMOpenStreetMapSource alloc] init] autorelease];
center.latitude = 47.5635;
... ... @@ -133,9 +136,18 @@
- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation
{
RMMarker *marker = [[[RMMarker alloc] initWithUIImage:annotation.annotationIcon anchorPoint:annotation.anchorPoint] autorelease];
if (annotation.title)
[marker changeLabelUsingText:annotation.title];
RMMarker *marker = nil;
if ([annotation.annotationType isEqualToString:kRMClusterAnnotationTypeName]) {
marker = [[[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"marker-blue.png"] anchorPoint:annotation.anchorPoint] autorelease];
if (annotation.title)
[marker changeLabelUsingText:annotation.title];
} else {
marker = [[[RMMarker alloc] initWithUIImage:annotation.annotationIcon anchorPoint:annotation.anchorPoint] autorelease];
if (annotation.title)
[marker changeLabelUsingText:annotation.title];
}
return marker;
}
... ...