Skip to content

Commit 1ac4a01

Browse files
committed
added some files
1 parent ef467c9 commit 1ac4a01

File tree

15 files changed

+629
-0
lines changed

15 files changed

+629
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// EPAnnotationArray.h
3+
// iOSMapExtension
4+
//
5+
// Created by epacces on 5/6/13.
6+
// Copyright (c) 2013 it.reply. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import <MapKit/MapKit.h>
11+
12+
@interface EPAnnotationArray : NSObject <NSFastEnumeration> {
13+
NSMutableArray *_annotationArray;
14+
}
15+
16+
- (void)addAnnotation:(id <MKAnnotation>)annotation;
17+
- (void)addAnnotations:(NSArray *)annotations;
18+
19+
- (NSArray *)allAnnotations;
20+
21+
- (void)removeAnnotation:(id <MKAnnotation>)annotation;
22+
- (void)removeAnnotations:(NSArray *)annotations;
23+
- (void)removeAllAnnotations;
24+
25+
- (void)removeAnnotationsConformsToProtocol:(Protocol *)protocol;
26+
- (void)removeAnnotationsConformsToProtocols:(NSArray *)protocols;
27+
28+
- (NSArray *)annotationsConformsToProtocol:(Protocol *)protocol;
29+
- (NSArray *)annotationsConformsToProtocols:(NSArray *)protocols;
30+
31+
- (NSArray *)annotationsWithinRange:(CLLocationDistance)radius center:(CLLocationCoordinate2D)center;
32+
33+
- (NSUInteger)count;
34+
35+
@end
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//
2+
// EPAnnotationArray.m
3+
// iOSMapExtension
4+
//
5+
// Created by epacces on 5/6/13.
6+
// Copyright (c) 2013 it.reply. All rights reserved.
7+
//
8+
9+
#import "EPAnnotationArray.h"
10+
11+
@implementation EPAnnotationArray
12+
13+
- (id)init
14+
{
15+
if (self = [super init]) {
16+
_annotationArray = [[NSMutableArray alloc] initWithCapacity:1];
17+
}
18+
return self;
19+
}
20+
21+
- (void)addAnnotations:(NSArray *)annotations
22+
{
23+
for (id annotation in annotations)
24+
if (! [annotation conformsToProtocol:@protocol(MKAnnotation)])
25+
[NSException raise:NSInternalInconsistencyException format:@"annotations should contains only objs conforms to MKAnnotation protocol"];
26+
27+
[_annotationArray addObjectsFromArray:annotations];
28+
}
29+
30+
- (void)addAnnotation:(id <MKAnnotation>)annotation
31+
{
32+
if ( ! [annotation conformsToProtocol:@protocol(MKAnnotation)] )
33+
[NSException raise:NSInternalInconsistencyException format:@"annotation should respond to MKAnnotation protocol"];
34+
else
35+
[_annotationArray addObject:annotation];
36+
}
37+
38+
- (NSArray *)allAnnotations
39+
{
40+
return [_annotationArray copy];
41+
}
42+
43+
- (void)removeAllAnnotations
44+
{
45+
[_annotationArray removeAllObjects];
46+
}
47+
48+
- (void)removeAnnotationsConformsToProtocol:(Protocol *)protocol
49+
{
50+
NSPredicate *predicate = [NSPredicate predicateWithBlock: ^BOOL(id evaluatedObject, NSDictionary *bindings ) {
51+
return [evaluatedObject conformsToProtocol:protocol];
52+
}];
53+
[_annotationArray filterUsingPredicate:predicate];
54+
}
55+
56+
57+
- (void)removeAnnotationsConformsToProtocols:(NSArray *)protocols
58+
{
59+
for (Protocol *p in protocols) {
60+
[self removeAnnotationsConformsToProtocol:p];
61+
}
62+
}
63+
64+
- (NSArray *)annotationsConformsToProtocol:(Protocol *)protocol
65+
{
66+
NSPredicate *predicate = [NSPredicate predicateWithBlock: ^BOOL(id evaluatedObject, NSDictionary *bindings ) {
67+
return ![evaluatedObject conformsToProtocol:protocol];
68+
}];
69+
return [_annotationArray filteredArrayUsingPredicate:predicate];
70+
}
71+
72+
- (NSArray *)annotationsConformsToProtocols:(NSArray *)protocols
73+
{
74+
NSMutableArray *filteredArray = [[NSMutableArray alloc] init];
75+
for (Protocol *p in protocols) {
76+
[filteredArray addObjectsFromArray:[self annotationsConformsToProtocol:p]];
77+
}
78+
return filteredArray;
79+
}
80+
81+
- (NSArray *)annotationsWithinRange:(CLLocationDistance)radius center:(CLLocationCoordinate2D)center
82+
{
83+
CLLocation *centerPosition = [[CLLocation alloc] initWithLatitude:center.latitude longitude:center.longitude];
84+
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id <MKAnnotation> evaluatedObject, NSDictionary *bindings ) {
85+
CLLocationCoordinate2D coordinate = [evaluatedObject coordinate];
86+
CLLocation *annotationPosition = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
87+
return [ annotationPosition distanceFromLocation:centerPosition ] <= radius;
88+
}];
89+
return [_annotationArray filteredArrayUsingPredicate:predicate];
90+
}
91+
92+
- (void)removeAnnotation:(id<MKAnnotation>)annotation
93+
{
94+
[_annotationArray removeObject:annotation];
95+
}
96+
97+
- (void)removeAnnotations:(NSArray *)annotations
98+
{
99+
[_annotationArray removeObjectsInArray:annotations];
100+
}
101+
102+
- (NSUInteger)count
103+
{
104+
return [_annotationArray count];
105+
}
106+
107+
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(__unsafe_unretained id [])buffer count:(NSUInteger)len
108+
{
109+
return [_annotationArray countByEnumeratingWithState:state objects:buffer count:len];
110+
}
111+
112+
@end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// Prefix header for all source files of the 'EPMapExtensions' target in the 'EPMapExtensions' project
3+
//
4+
5+
#ifdef __OBJC__
6+
#import <Foundation/Foundation.h>
7+
#import <MapKit/MapKit.h>
8+
#endif

EPMapExtensions/EPMapExtensions.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// EPMapExtensions.h
3+
// EPMapExtensions
4+
//
5+
// Created by epacces on 5/6/13.
6+
// Copyright (c) 2013 it.reply. All rights reserved.
7+
//
8+
9+
#import "EPMapViewDecorator.h"
10+
#import "EPMapView.h"
11+
#import "EPUserPosition.h"
12+
#import "EPAnnotationArray.h"
13+
#import "EPMapViewDelegate.h"

EPMapExtensions/EPMapView.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//
2+
// EPMapView.h
3+
// iOSMapExtension
4+
//
5+
// Created by epacces on 5/6/13.
6+
// Copyright (c) 2013 it.reply. All rights reserved.
7+
//
8+
9+
#import <MapKit/MapKit.h>
10+
11+
/**
12+
`EPMapView` inherits from `MKMapView` and adds some services to it such as, e.g., getting a centered region with respect to annotations.
13+
*/
14+
15+
@interface EPMapView : MKMapView
16+
17+
///---------------------------------------------
18+
/// @name Creating maps
19+
///---------------------------------------------
20+
21+
/**
22+
Creates a map view
23+
@param mapView The map view to initialize
24+
*/
25+
26+
- (id)initWithMapView:(MKMapView *)mapView;
27+
28+
29+
///---------------------------------------------
30+
/// @name Getting centered regions
31+
///---------------------------------------------
32+
33+
/**
34+
Computes the centered region with respect to all annotations presented in the map
35+
*/
36+
37+
- (MKCoordinateRegion)centeredRegion;
38+
39+
/**
40+
Computes the centered region with respect to all annotations presented in the map conforming to a given protocol
41+
@param protocol The protocol used to filter annotations
42+
*/
43+
44+
- (MKCoordinateRegion)centeredRegionForAnnotationConformingToProtocol:(Protocol *)protocol;
45+
46+
/**
47+
Computes the centered region with respect to all annotations presented in the map conforming to an array of protocols
48+
@param protocols The array of protocols to filter annotations
49+
*/
50+
51+
- (MKCoordinateRegion)centeredRegionForAnnotationConformingToProtocols:(NSArray *)protocols;
52+
53+
///---------------------------------------------
54+
/// @name Getting visible annotations
55+
///---------------------------------------------
56+
57+
/**
58+
Computes the number of visible annotations displayed over the visible region of the map
59+
*/
60+
61+
- (NSUInteger)visibleAnnotations;
62+
63+
/**
64+
Computes the number of visible annotations displayed over the visible region of the map conforming to a given protocol
65+
@param protocol The protocol used to filter annotations
66+
*/
67+
68+
- (NSUInteger)visibleAnnotationsConformingToProtocol:(Protocol *)protocol;
69+
70+
/**
71+
Computes the number of visible annotations displayed over the visible region of the map conforming to a set of protocols
72+
@param protocols The array of protocols to filter annotations
73+
*/
74+
75+
- (NSUInteger)visibleAnnotationsConformingToProtocols:(NSArray *)protocols;
76+
77+
///---------------------------------------------
78+
/// @name Resetting annotation
79+
///---------------------------------------------
80+
81+
/**
82+
Removes all the annotations added into the map
83+
*/
84+
85+
- (void)removeAllAnnotations;
86+
87+
@end

0 commit comments

Comments
 (0)