RMLayerSet.m
2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// RMLayerSet.m
// MapView
//
// Created by Joseph Gentle on 1/10/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "RMLayerSet.h"
#import "RMMapContents.h"
#import "RMMercatorToScreenProjection.h"
@implementation RMLayerSet
- (id)initForContents: (RMMapContents *)_contents
{
if (![super init])
return nil;
set = [[NSMutableArray alloc] init];
mapContents = _contents;
return self;
}
- (void)correctScreenPosition: (CALayer *)layer
{
if ([layer conformsToProtocol:@protocol(RMMovingMapLayer)])
{
// Kinda ugly.
CALayer<RMMovingMapLayer>* layer_with_proto = (CALayer<RMMovingMapLayer>*)layer;
RMMercatorPoint location = [layer_with_proto location];
layer_with_proto.position = [[mapContents mercatorToScreenProjection] projectMercatorPoint:location];
}
}
- (void)setSublayers: (NSArray*)array
{
for (CALayer *layer in array)
{
[self correctScreenPosition:layer];
}
[set removeAllObjects];
[set addObjectsFromArray:array];
[super setSublayers:array];
}
- (void)addSublayer:(CALayer *)layer
{
[self correctScreenPosition:layer];
[set addObject:layer];
[super addSublayer:layer];
}
- (void)insertSublayer:(CALayer *)layer above:(CALayer *)siblingLayer
{
[self correctScreenPosition:layer];
int index = [set indexOfObject:siblingLayer];
[set insertObject:layer atIndex:index + 1];
[super insertSublayer:layer above:siblingLayer];
}
- (void)insertSublayer:(CALayer *)layer below:(CALayer *)siblingLayer
{
[self correctScreenPosition:layer];
int index = [set indexOfObject:siblingLayer];
[set insertObject:layer atIndex:index];
[super insertSublayer:layer below:siblingLayer];
}
- (void)insertSublayer:(CALayer *)layer atIndex:(unsigned)index
{
[self correctScreenPosition:layer];
[set insertObject:layer atIndex:index];
// TODO: Fix this.
[super addSublayer:layer];
}
/*
- (void)insertSublayer:(RMMapLayer*) layer below:(RMMapLayer*)sibling;
- (void)insertSublayer:(RMMapLayer*) layer above:(RMMapLayer*)sibling;
- (void)removeSublayer:(RMMapLayer*) layer;
*/
- (void)moveToMercator: (RMMercatorPoint)mercator
{
// TODO: Me
}
- (void)moveBy: (CGSize) delta
{
for (id layer in set)
{
if ([layer respondsToSelector:@selector(moveBy:)])
[layer moveBy:delta];
// if layer moves on and offscreen...
}
}
- (void)zoomByFactor: (float) zoomFactor Near:(CGPoint) center
{
for (id layer in set)
{
if ([layer respondsToSelector:@selector(zoomByFactor:Near:)])
[layer zoomByFactor:zoomFactor Near:center];
}
}
@end