|
@@ -21,12 +21,13 @@ |
|
@@ -21,12 +21,13 @@ |
21
|
|
21
|
|
22
|
@implementation RMMapTiledLayerView
|
22
|
@implementation RMMapTiledLayerView
|
23
|
{
|
23
|
{
|
24
|
- RMMapView *mapView;
|
|
|
25
|
- id <RMTileSource> tileSource;
|
24
|
+ RMMapView *_mapView;
|
|
|
25
|
+ id <RMTileSource> _tileSource;
|
26
|
}
|
26
|
}
|
27
|
|
27
|
|
28
|
-@synthesize delegate;
|
|
|
29
|
-@synthesize useSnapshotRenderer;
|
28
|
+@synthesize delegate = _delegate;
|
|
|
29
|
+@synthesize useSnapshotRenderer = _useSnapshotRenderer;
|
|
|
30
|
+@synthesize tileSource = _tileSource;
|
30
|
|
31
|
|
31
|
+ (Class)layerClass
|
32
|
+ (Class)layerClass
|
32
|
{
|
33
|
{
|
|
@@ -43,8 +44,8 @@ |
|
@@ -43,8 +44,8 @@ |
43
|
if (!(self = [super initWithFrame:frame]))
|
44
|
if (!(self = [super initWithFrame:frame]))
|
44
|
return nil;
|
45
|
return nil;
|
45
|
|
46
|
|
46
|
- mapView = [aMapView retain];
|
|
|
47
|
- tileSource = [aTileSource retain];
|
47
|
+ _mapView = [aMapView retain];
|
|
|
48
|
+ _tileSource = [aTileSource retain];
|
48
|
|
49
|
|
49
|
self.userInteractionEnabled = YES;
|
50
|
self.userInteractionEnabled = YES;
|
50
|
self.multipleTouchEnabled = YES;
|
51
|
self.multipleTouchEnabled = YES;
|
|
@@ -53,8 +54,8 @@ |
|
@@ -53,8 +54,8 @@ |
53
|
self.useSnapshotRenderer = NO;
|
54
|
self.useSnapshotRenderer = NO;
|
54
|
|
55
|
|
55
|
CATiledLayer *tiledLayer = [self tiledLayer];
|
56
|
CATiledLayer *tiledLayer = [self tiledLayer];
|
56
|
- size_t levelsOf2xMagnification = mapView.tileSourcesContainer.maxZoom;
|
|
|
57
|
- if (mapView.adjustTilesForRetinaDisplay) levelsOf2xMagnification += 1;
|
57
|
+ size_t levelsOf2xMagnification = _mapView.tileSourcesContainer.maxZoom;
|
|
|
58
|
+ if (_mapView.adjustTilesForRetinaDisplay) levelsOf2xMagnification += 1;
|
58
|
tiledLayer.levelsOfDetail = levelsOf2xMagnification;
|
59
|
tiledLayer.levelsOfDetail = levelsOf2xMagnification;
|
59
|
tiledLayer.levelsOfDetailBias = levelsOf2xMagnification;
|
60
|
tiledLayer.levelsOfDetailBias = levelsOf2xMagnification;
|
60
|
|
61
|
|
|
@@ -85,10 +86,10 @@ |
|
@@ -85,10 +86,10 @@ |
85
|
|
86
|
|
86
|
- (void)dealloc
|
87
|
- (void)dealloc
|
87
|
{
|
88
|
{
|
88
|
- [tileSource cancelAllDownloads];
|
89
|
+ [_tileSource cancelAllDownloads];
|
89
|
self.layer.contents = nil;
|
90
|
self.layer.contents = nil;
|
90
|
- [tileSource release]; tileSource = nil;
|
|
|
91
|
- [mapView release]; mapView = nil;
|
91
|
+ [_tileSource release]; _tileSource = nil;
|
|
|
92
|
+ [_mapView release]; _mapView = nil;
|
92
|
[super dealloc];
|
93
|
[super dealloc];
|
93
|
}
|
94
|
}
|
94
|
|
95
|
|
|
@@ -109,7 +110,7 @@ |
|
@@ -109,7 +110,7 @@ |
109
|
|
110
|
|
110
|
if (self.useSnapshotRenderer)
|
111
|
if (self.useSnapshotRenderer)
|
111
|
{
|
112
|
{
|
112
|
- zoom = (short)ceilf(mapView.adjustedZoomForRetinaDisplay);
|
113
|
+ zoom = (short)ceilf(_mapView.adjustedZoomForRetinaDisplay);
|
113
|
CGFloat rectSize = bounds.size.width / powf(2.0, (float)zoom);
|
114
|
CGFloat rectSize = bounds.size.width / powf(2.0, (float)zoom);
|
114
|
|
115
|
|
115
|
int x1 = floor(rect.origin.x / rectSize),
|
116
|
int x1 = floor(rect.origin.x / rectSize),
|
|
@@ -119,7 +120,7 @@ |
|
@@ -119,7 +120,7 @@ |
119
|
|
120
|
|
120
|
// NSLog(@"Tiles from x1:%d, y1:%d to x2:%d, y2:%d @ zoom %d", x1, y1, x2, y2, zoom);
|
121
|
// NSLog(@"Tiles from x1:%d, y1:%d to x2:%d, y2:%d @ zoom %d", x1, y1, x2, y2, zoom);
|
121
|
|
122
|
|
122
|
- if (zoom >= tileSource.minZoom && zoom <= tileSource.maxZoom)
|
123
|
+ if (zoom >= _tileSource.minZoom && zoom <= _tileSource.maxZoom)
|
123
|
{
|
124
|
{
|
124
|
UIGraphicsPushContext(context);
|
125
|
UIGraphicsPushContext(context);
|
125
|
|
126
|
|
|
@@ -127,7 +128,7 @@ |
|
@@ -127,7 +128,7 @@ |
127
|
{
|
128
|
{
|
128
|
for (int y=y1; y<=y2; ++y)
|
129
|
for (int y=y1; y<=y2; ++y)
|
129
|
{
|
130
|
{
|
130
|
- UIImage *tileImage = [tileSource imageForTile:RMTileMake(x, y, zoom) inCache:[mapView tileCache]];
|
131
|
+ UIImage *tileImage = [_tileSource imageForTile:RMTileMake(x, y, zoom) inCache:[_mapView tileCache]];
|
131
|
[tileImage drawInRect:CGRectMake(x * rectSize, y * rectSize, rectSize, rectSize)];
|
132
|
[tileImage drawInRect:CGRectMake(x * rectSize, y * rectSize, rectSize, rectSize)];
|
132
|
}
|
133
|
}
|
133
|
}
|
134
|
}
|
|
@@ -146,12 +147,12 @@ |
|
@@ -146,12 +147,12 @@ |
146
|
|
147
|
|
147
|
UIImage *tileImage = nil;
|
148
|
UIImage *tileImage = nil;
|
148
|
|
149
|
|
149
|
- if (zoom >= tileSource.minZoom && zoom <= tileSource.maxZoom)
|
|
|
150
|
- tileImage = [tileSource imageForTile:RMTileMake(x, y, zoom) inCache:[mapView tileCache]];
|
150
|
+ if (zoom >= _tileSource.minZoom && zoom <= _tileSource.maxZoom)
|
|
|
151
|
+ tileImage = [_tileSource imageForTile:RMTileMake(x, y, zoom) inCache:[_mapView tileCache]];
|
151
|
|
152
|
|
152
|
if ( ! tileImage)
|
153
|
if ( ! tileImage)
|
153
|
{
|
154
|
{
|
154
|
- if (mapView.missingTilesDepth == 0)
|
155
|
+ if (_mapView.missingTilesDepth == 0)
|
155
|
{
|
156
|
{
|
156
|
tileImage = [RMTileImage errorTile];
|
157
|
tileImage = [RMTileImage errorTile];
|
157
|
}
|
158
|
}
|
|
@@ -160,14 +161,14 @@ |
|
@@ -160,14 +161,14 @@ |
160
|
NSUInteger currentTileDepth = 1, currentZoom = zoom - currentTileDepth;
|
161
|
NSUInteger currentTileDepth = 1, currentZoom = zoom - currentTileDepth;
|
161
|
|
162
|
|
162
|
// tries to return lower zoom level tiles if a tile cannot be found
|
163
|
// tries to return lower zoom level tiles if a tile cannot be found
|
163
|
- while ( !tileImage && currentZoom >= tileSource.minZoom && currentTileDepth <= mapView.missingTilesDepth)
|
164
|
+ while ( !tileImage && currentZoom >= _tileSource.minZoom && currentTileDepth <= _mapView.missingTilesDepth)
|
164
|
{
|
165
|
{
|
165
|
float nextX = x / powf(2.0, (float)currentTileDepth),
|
166
|
float nextX = x / powf(2.0, (float)currentTileDepth),
|
166
|
nextY = y / powf(2.0, (float)currentTileDepth);
|
167
|
nextY = y / powf(2.0, (float)currentTileDepth);
|
167
|
float nextTileX = floor(nextX),
|
168
|
float nextTileX = floor(nextX),
|
168
|
nextTileY = floor(nextY);
|
169
|
nextTileY = floor(nextY);
|
169
|
|
170
|
|
170
|
- tileImage = [tileSource imageForTile:RMTileMake((int)nextTileX, (int)nextTileY, currentZoom) inCache:[mapView tileCache]];
|
171
|
+ tileImage = [_tileSource imageForTile:RMTileMake((int)nextTileX, (int)nextTileY, currentZoom) inCache:[_mapView tileCache]];
|
171
|
|
172
|
|
172
|
if (tileImage)
|
173
|
if (tileImage)
|
173
|
{
|
174
|
{
|
|
@@ -192,7 +193,7 @@ |
|
@@ -192,7 +193,7 @@ |
192
|
}
|
193
|
}
|
193
|
}
|
194
|
}
|
194
|
|
195
|
|
195
|
- if (mapView.debugTiles)
|
196
|
+ if (_mapView.debugTiles)
|
196
|
{
|
197
|
{
|
197
|
UIGraphicsBeginImageContext(tileImage.size);
|
198
|
UIGraphicsBeginImageContext(tileImage.size);
|
198
|
|
199
|
|
|
@@ -238,34 +239,34 @@ |
|
@@ -238,34 +239,34 @@ |
238
|
|
239
|
|
239
|
- (void)handleSingleTap:(UIGestureRecognizer *)recognizer
|
240
|
- (void)handleSingleTap:(UIGestureRecognizer *)recognizer
|
240
|
{
|
241
|
{
|
241
|
- if ([delegate respondsToSelector:@selector(mapTiledLayerView:singleTapAtPoint:)])
|
|
|
242
|
- [delegate mapTiledLayerView:self singleTapAtPoint:[recognizer locationInView:mapView]];
|
242
|
+ if ([_delegate respondsToSelector:@selector(mapTiledLayerView:singleTapAtPoint:)])
|
|
|
243
|
+ [_delegate mapTiledLayerView:self singleTapAtPoint:[recognizer locationInView:_mapView]];
|
243
|
}
|
244
|
}
|
244
|
|
245
|
|
245
|
- (void)handleTwoFingerSingleTap:(UIGestureRecognizer *)recognizer
|
246
|
- (void)handleTwoFingerSingleTap:(UIGestureRecognizer *)recognizer
|
246
|
{
|
247
|
{
|
247
|
- if ([delegate respondsToSelector:@selector(mapTiledLayerView:twoFingerSingleTapAtPoint:)])
|
|
|
248
|
- [delegate mapTiledLayerView:self twoFingerSingleTapAtPoint:[recognizer locationInView:mapView]];
|
248
|
+ if ([_delegate respondsToSelector:@selector(mapTiledLayerView:twoFingerSingleTapAtPoint:)])
|
|
|
249
|
+ [_delegate mapTiledLayerView:self twoFingerSingleTapAtPoint:[recognizer locationInView:_mapView]];
|
249
|
}
|
250
|
}
|
250
|
|
251
|
|
251
|
- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer
|
252
|
- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer
|
252
|
{
|
253
|
{
|
253
|
if (recognizer.state != UIGestureRecognizerStateBegan) return;
|
254
|
if (recognizer.state != UIGestureRecognizerStateBegan) return;
|
254
|
|
255
|
|
255
|
- if ([delegate respondsToSelector:@selector(mapTiledLayerView:longPressAtPoint:)])
|
|
|
256
|
- [delegate mapTiledLayerView:self longPressAtPoint:[recognizer locationInView:mapView]];
|
256
|
+ if ([_delegate respondsToSelector:@selector(mapTiledLayerView:longPressAtPoint:)])
|
|
|
257
|
+ [_delegate mapTiledLayerView:self longPressAtPoint:[recognizer locationInView:_mapView]];
|
257
|
}
|
258
|
}
|
258
|
|
259
|
|
259
|
- (void)handleDoubleTap:(UIGestureRecognizer *)recognizer
|
260
|
- (void)handleDoubleTap:(UIGestureRecognizer *)recognizer
|
260
|
{
|
261
|
{
|
261
|
- if ([delegate respondsToSelector:@selector(mapTiledLayerView:doubleTapAtPoint:)])
|
|
|
262
|
- [delegate mapTiledLayerView:self doubleTapAtPoint:[recognizer locationInView:mapView]];
|
262
|
+ if ([_delegate respondsToSelector:@selector(mapTiledLayerView:doubleTapAtPoint:)])
|
|
|
263
|
+ [_delegate mapTiledLayerView:self doubleTapAtPoint:[recognizer locationInView:_mapView]];
|
263
|
}
|
264
|
}
|
264
|
|
265
|
|
265
|
- (void)handleTwoFingerDoubleTap:(UIGestureRecognizer *)recognizer
|
266
|
- (void)handleTwoFingerDoubleTap:(UIGestureRecognizer *)recognizer
|
266
|
{
|
267
|
{
|
267
|
- if ([delegate respondsToSelector:@selector(mapTiledLayerView:twoFingerDoubleTapAtPoint:)])
|
|
|
268
|
- [delegate mapTiledLayerView:self twoFingerDoubleTapAtPoint:[recognizer locationInView:mapView]];
|
268
|
+ if ([_delegate respondsToSelector:@selector(mapTiledLayerView:twoFingerDoubleTapAtPoint:)])
|
|
|
269
|
+ [_delegate mapTiledLayerView:self twoFingerDoubleTapAtPoint:[recognizer locationInView:_mapView]];
|
269
|
}
|
270
|
}
|
270
|
|
271
|
|
271
|
@end |
272
|
@end |