Authored by Obrand69

Added RMMarkerManager class that handles all marker methods.

Changed the Controller example to reflect changes
... ... @@ -12,6 +12,8 @@
#import "RMFoundation.h"
#import "RMMarker.h"
#import "RMMarkerManager.h"
@implementation MapViewViewController
/*
... ... @@ -35,6 +37,7 @@
- (void)viewDidLoad {
[super viewDidLoad];
/* RMMarker *marker = [[RMMarker alloc] initWithKey:RMMarkerBlueKey];
RMMercatorRect loc = [[mapView contents] mercatorBounds];
... ... @@ -45,9 +48,13 @@
[[[mapView contents] overlay] addSublayer:marker];
NSLog(@"marker added to %f %f", loc.origin.x, loc.origin.y);*/
[mapView addDefaultMarkerAt:[[mapView contents] mapCenter]];
NSArray *markers = [mapView getMarkers];
RMMarkerManager *markerManager = [mapView markerManager];
[markerManager addDefaultMarkerAt:[[mapView contents] mapCenter]];
NSArray *markers = [markerManager getMarkers];
NSLog(@"Nb markers %d", [markers count]);
... ... @@ -59,18 +66,18 @@
{
RMXYPoint point = [aMarker location];
NSLog(@"Marker mercator location: X:%lf, Y:%lf", point.x, point.y);
CGPoint screenPoint = [mapView getMarkerScreenCoordinate: aMarker];
CGPoint screenPoint = [markerManager getMarkerScreenCoordinate: aMarker];
NSLog(@"Marker screen location: X:%lf, Y:%lf", screenPoint.x, screenPoint.y);
CLLocationCoordinate2D coordinates = [mapView getMarkerCoordinate2D: aMarker];
CLLocationCoordinate2D coordinates = [markerManager getMarkerCoordinate2D: aMarker];
NSLog(@"Marker Lat/Lon location: Lat:%lf, Lon:%lf", coordinates.latitude, coordinates.longitude);
[mapView removeMarker:aMarker];
[markerManager removeMarker:aMarker];
}
// Put the marker back
[mapView addDefaultMarkerAt:[[mapView contents] mapCenter]];
[markerManager addDefaultMarkerAt:[[mapView contents] mapCenter]];
markers = [mapView getMarkersForScreenBounds];
markers = [markerManager getMarkersForScreenBounds];
NSLog(@"Nb Markers in Screen: %d", [markers count]);
... ...
... ... @@ -124,16 +124,7 @@ enum {
- (void)zoomWithLatLngBoundsNorthEast:(CLLocationCoordinate2D)ne SouthWest:(CLLocationCoordinate2D)se;
- (void)zoomWithRMMercatorRectBounds:(RMXYRect)bounds;
- (void) addMarker: (RMMarker*)marker;
- (void) addMarker: (RMMarker*)marker AtLatLong:(CLLocationCoordinate2D)point;
- (void) addDefaultMarkerAt: (CLLocationCoordinate2D)point;
- (void) removeMarkers;
- (NSArray *)getMarkers;
- (void) removeMarker:(RMMarker *)marker;
- (CGPoint) getMarkerScreenCoordinate: (RMMarker *)marker;
- (CLLocationCoordinate2D) getMarkerCoordinate2D: (RMMarker *) marker;
- (NSArray *) getMarkersForScreenBounds;
- (RMXYPoint)latLongToPoint:(RMLatLong)aLatLong;
- (CLLocationCoordinate2DBounds) getScreenCoordinateBounds;
... ...
... ... @@ -561,72 +561,9 @@ static BOOL _performExpensiveOperations = YES;
// Move overlays stuff here - at the moment overlay stuff is above...
- (void) addMarker: (RMMarker*)marker
- (RMXYPoint)latLongToPoint:(RMLatLong)aLatLong
{
[overlay addSublayer:marker];
}
- (void) addMarker: (RMMarker*)marker AtLatLong:(CLLocationCoordinate2D)point
{
[marker setLocation:[projection latLongToPoint:point]];
[self addMarker: marker];
}
- (void) addDefaultMarkerAt: (CLLocationCoordinate2D)point
{
RMMarker *marker = [[RMMarker alloc] initWithKey:RMMarkerRedKey];
[self addMarker:marker AtLatLong:point];
[marker release];
}
- (void) removeMarkers
{
overlay.sublayers = [NSArray arrayWithObjects:nil];
}
- (NSArray *)getMarkers
{
return [overlay sublayers];
}
- (void) removeMarker:(RMMarker *)marker
{
[marker removeFromSuperlayer];
}
- (CGPoint) getMarkerScreenCoordinate: (RMMarker *)marker
{
return [mercatorToScreenProjection projectXYPoint:[marker location]];
}
- (CLLocationCoordinate2D) getMarkerCoordinate2D: (RMMarker *) marker
{
return [self pixelToLatLong:[self getMarkerScreenCoordinate:marker]];
}
- (NSArray *) getMarkersForScreenBounds
{
NSMutableArray *markers;
markers = [NSMutableArray array];
CGRect rect = [mercatorToScreenProjection screenBounds];
NSArray *allMarkers = [self getMarkers];
NSEnumerator *markerEnumerator = [allMarkers objectEnumerator];
RMMarker *aMarker;
while (aMarker = (RMMarker *)[markerEnumerator nextObject])
{
CGPoint markerCoord = [self getMarkerScreenCoordinate:aMarker];
if( ((markerCoord.x > rect.origin.x) && (markerCoord.y > rect.origin.y)) &&
((markerCoord.x < (rect.origin.x + rect.size.width)) && (markerCoord.y < (rect.origin.y + rect.size.height))))
{
[markers addObject:aMarker];
}
}
return markers;
return [projection latLongToPoint:aLatLong];
}
- (CLLocationCoordinate2DBounds) getScreenCoordinateBounds
... ...
... ... @@ -25,6 +25,7 @@ typedef struct {
@class RMMapContents;
@class RMMarker;
@class RMMarkerManager;
// This class is a wrapper around RMMapContents for the iphone.
// It implements event handling; but thats about it. All the interesting map
... ... @@ -32,6 +33,7 @@ typedef struct {
@interface RMMapView : UIView
{
RMMapContents *contents;
RMMarkerManager *markerManager;
id<RMMapViewDelegate> delegate;
BOOL enableDragging;
... ... @@ -43,6 +45,8 @@ typedef struct {
// property. The contents structure holds the actual map bits.
@property (readonly) RMMapContents *contents;
@property (retain, readonly) RMMarkerManager *markerManager;
// do not retain the delegate so you can let the corresponding controller implement the
// delegate without circular references
@property (assign) id<RMMapViewDelegate> delegate;
... ... @@ -59,16 +63,6 @@ typedef struct {
- (void)setZoomBounds:(float)aMinZoom maxZoom:(float)aMaxZoom;
- (void) addMarker: (RMMarker*)marker;
- (void) addMarker: (RMMarker*)marker AtLatLong:(CLLocationCoordinate2D)point;
- (void) addDefaultMarkerAt: (CLLocationCoordinate2D)point;
- (void) removeMarkers;
- (NSArray *) getMarkers;
- (void) removeMarker:(RMMarker *)marker;
- (CGPoint) getMarkerScreenCoordinate: (RMMarker *)marker;
- (CLLocationCoordinate2D) getMarkerCoordinate2D: (RMMarker *) marker;
- (NSArray *) getMarkersForScreenBounds;
- (CLLocationCoordinate2DBounds) getScreenCoordinateBounds;
... ...
... ... @@ -15,6 +15,8 @@
#import "RMMercatorToScreenProjection.h"
#import "RMMarker.h"
#import "RMMarkerManager.h"
@implementation RMMapView (Internal)
BOOL delegateHasBeforeMapMove;
BOOL delegateHasAfterMapMove;
... ... @@ -26,9 +28,12 @@
@implementation RMMapView
@synthesize markerManager;
-(void) initValues
{
contents = [[RMMapContents alloc] initForView:self];
markerManager = [[RMMarkerManager alloc] initWithContents:contents];
enableDragging = YES;
enableZoom = YES;
... ... @@ -330,50 +335,6 @@
}
#pragma mark Markers
- (void) addMarker: (RMMarker*)marker
{
[contents addMarker:marker];
}
- (void) addMarker: (RMMarker*)marker AtLatLong:(CLLocationCoordinate2D)point
{
[contents addMarker:marker AtLatLong:point];
}
- (void) addDefaultMarkerAt: (CLLocationCoordinate2D)point
{
[contents addDefaultMarkerAt:point];
}
- (void) removeMarkers
{
[contents removeMarkers];
}
- (NSArray *) getMarkers
{
return [contents getMarkers];
}
- (void) removeMarker: (RMMarker *)marker
{
[contents removeMarker:marker];
}
- (CGPoint) getMarkerScreenCoordinate: (RMMarker *)marker
{
return [contents getMarkerScreenCoordinate:marker];
}
- (CLLocationCoordinate2D) getMarkerCoordinate2D: (RMMarker *) marker
{
return [contents getMarkerCoordinate2D:marker];
}
- (NSArray *) getMarkersForScreenBounds
{
return [contents getMarkersForScreenBounds];
}
- (CLLocationCoordinate2DBounds) getScreenCoordinateBounds
{
... ...
//
// RMMarkerManager.h
// MapView
//
// Created by olivier on 11/5/08.
// Copyright 2008 NA. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "RMMapContents.h"
#import "RMMarker.h"
@class RMProjection;
@interface RMMarkerManager : NSObject {
RMMapContents *contents;
}
@property (retain, readwrite) RMMapContents *contents;
- (id)initWithContents:(RMMapContents *)mapContents;
- (void) addMarker: (RMMarker*)marker;
- (void) addMarker: (RMMarker*)marker AtLatLong:(CLLocationCoordinate2D)point;
- (void) addDefaultMarkerAt: (CLLocationCoordinate2D)point;
- (void) removeMarkers;
- (NSArray *)getMarkers;
- (void) removeMarker:(RMMarker *)marker;
- (CGPoint) getMarkerScreenCoordinate: (RMMarker *)marker;
- (CLLocationCoordinate2D) getMarkerCoordinate2D: (RMMarker *) marker;
- (NSArray *) getMarkersForScreenBounds;
@end
... ...
//
// RMMarkerManager.m
// MapView
//
// Created by olivier on 11/5/08.
// Copyright 2008 NA. All rights reserved.
//
#import "RMMarkerManager.h"
#import "RMMercatorToScreenProjection.h"
@implementation RMMarkerManager
@synthesize contents;
- (id)initWithContents:(RMMapContents *)mapContents
{
if (![super init])
return nil;
contents = mapContents;
return self;
}
- (void) addMarker: (RMMarker*)marker
{
[[contents overlay] addSublayer:marker];
}
- (void) addMarker: (RMMarker*)marker AtLatLong:(CLLocationCoordinate2D)point
{
[marker setLocation:[contents latLongToPoint:point]];
[self addMarker: marker];
}
- (void) addDefaultMarkerAt: (CLLocationCoordinate2D)point
{
RMMarker *marker = [[RMMarker alloc] initWithKey:RMMarkerRedKey];
[self addMarker:marker AtLatLong:point];
[marker release];
}
- (void) removeMarkers
{
[[contents overlay] setSublayers:[NSArray arrayWithObjects:nil]];
}
- (NSArray *)getMarkers
{
return [[contents overlay] sublayers];
}
- (void) removeMarker:(RMMarker *)marker
{
[marker removeFromSuperlayer];
}
- (CGPoint) getMarkerScreenCoordinate: (RMMarker *)marker
{
return [[contents mercatorToScreenProjection] projectXYPoint:[marker location]];
}
- (CLLocationCoordinate2D) getMarkerCoordinate2D: (RMMarker *) marker
{
return [contents pixelToLatLong:[self getMarkerScreenCoordinate:marker]];
}
- (NSArray *) getMarkersForScreenBounds
{
NSMutableArray *markers;
markers = [NSMutableArray array];
CGRect rect = [[contents mercatorToScreenProjection] screenBounds];
NSArray *allMarkers = [self getMarkers];
NSEnumerator *markerEnumerator = [allMarkers objectEnumerator];
RMMarker *aMarker;
while (aMarker = (RMMarker *)[markerEnumerator nextObject])
{
CGPoint markerCoord = [self getMarkerScreenCoordinate:aMarker];
if( ((markerCoord.x > rect.origin.x) && (markerCoord.y > rect.origin.y)) &&
((markerCoord.x < (rect.origin.x + rect.size.width)) && (markerCoord.y < (rect.origin.y + rect.size.height))))
{
[markers addObject:aMarker];
}
}
return markers;
}
@end
... ...
... ... @@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
090C948D0EC23FCD003AEE25 /* RMMarkerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 090C948C0EC23FCD003AEE25 /* RMMarkerManager.m */; };
126692A10EB75C0A00E002D5 /* RMConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 126692A00EB75C0A00E002D5 /* RMConfiguration.m */; };
126693040EB76C0B00E002D5 /* RMConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = 126692A00EB75C0A00E002D5 /* RMConfiguration.m */; };
1296F5610EB8743500FF25E0 /* RMMarkerStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = 1296F5600EB8743500FF25E0 /* RMMarkerStyle.m */; };
... ... @@ -134,6 +135,8 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
090C948B0EC23FCD003AEE25 /* RMMarkerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMMarkerManager.h; sourceTree = "<group>"; };
090C948C0EC23FCD003AEE25 /* RMMarkerManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMMarkerManager.m; sourceTree = "<group>"; };
1266929F0EB75C0A00E002D5 /* RMConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMConfiguration.h; sourceTree = "<group>"; };
126692A00EB75C0A00E002D5 /* RMConfiguration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMConfiguration.m; sourceTree = "<group>"; };
1296F55F0EB8743500FF25E0 /* RMMarkerStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMMarkerStyle.h; sourceTree = "<group>"; };
... ... @@ -517,6 +520,8 @@
B8C9740D0E8A196E007D16AD /* Map */ = {
isa = PBXGroup;
children = (
090C948B0EC23FCD003AEE25 /* RMMarkerManager.h */,
090C948C0EC23FCD003AEE25 /* RMMarkerManager.m */,
B8C9740E0E8A198F007D16AD /* README.txt */,
B8C974690E8A1A50007D16AD /* RMMapView.h */,
B8C9746A0E8A1A50007D16AD /* RMMapView.m */,
... ... @@ -709,6 +714,7 @@
126692A10EB75C0A00E002D5 /* RMConfiguration.m in Sources */,
1296F5610EB8743500FF25E0 /* RMMarkerStyle.m in Sources */,
1296F5640EB8745300FF25E0 /* RMMarkerStyles.m in Sources */,
090C948D0EC23FCD003AEE25 /* RMMarkerManager.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
... ...