forked from mapbox/mbxmapkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMBXMapKit.m
More file actions
653 lines (514 loc) · 22.8 KB
/
MBXMapKit.m
File metadata and controls
653 lines (514 loc) · 22.8 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
//
// MBXMapKit.m
// MBXMapKit
//
// Created by Justin R. Miller on 9/4/13.
// Copyright (c) 2013 MapBox. All rights reserved.
//
#import "MBXMapKit.h"
#pragma mark Constants -
#define kMBXMapViewCacheFolder @"MBXMapViewCache"
#define kMBXMapViewCacheInterval 60 * 60 * 24 * 7
typedef NS_ENUM(NSUInteger, MBXMapViewShowDefaultBaseLayerMode)
{
MBXMapViewShowDefaultBaseLayerNever,
MBXMapViewShowDefaultBaseLayerAlways,
MBXMapViewShowDefaultBaseLayerIfPartial,
};
#pragma mark - Private Interfaces -
@interface MBXMapViewTileOverlay : MKTileOverlay
@property (nonatomic, copy) NSDictionary *tileJSONDictionary;
@property (nonatomic, weak) MBXMapView *mapView;
@property (nonatomic) MKCoordinateRegion region;
@end
#pragma mark -
@interface MBXMapViewDelegate : NSProxy <MKMapViewDelegate>
@property (nonatomic, weak) id <MKMapViewDelegate>realDelegate;
@end
#pragma mark -
@interface MBXMapView ()
- (NSString *)cachePath;
@property (nonatomic) MBXMapViewShowDefaultBaseLayerMode showDefaultBaseLayerMode;
@property (nonatomic) MBXMapViewDelegate *ownedDelegate;
@property (nonatomic) NSURLSession *dataSession;
@property (nonatomic) NSURLSessionTask *metadataTask;
@property (nonatomic) MBXMapViewTileOverlay *tileOverlay;
@property (nonatomic) BOOL hasInitialCenterCoordinate;
@end
#pragma mark - MBXMapViewTileOverlay - Custom overlay fetching tiles from MapBox -
@implementation MBXMapViewTileOverlay
- (id)initWithTileJSONDictionary:(NSDictionary *)tileJSONDictionary mapView:(MBXMapView *)mapView
{
self = [super initWithURLTemplate:nil];
if (self)
{
_tileJSONDictionary = [tileJSONDictionary copy];
if ( ! _tileJSONDictionary)
{
// Dummy layer requested. Never show default tiles.
//
_region = MKCoordinateRegionForMapRect(MKMapRectWorld);
self.canReplaceMapContent = YES;
}
else
{
// Valid layer requested.
//
_mapView = mapView;
self.minimumZ = [_tileJSONDictionary[@"minzoom"] integerValue];
self.maximumZ = [_tileJSONDictionary[@"maxzoom"] integerValue];
_region = MKCoordinateRegionMake(CLLocationCoordinate2DMake(0, 0), MKCoordinateSpanMake(0, 0));
if (_mapView.showDefaultBaseLayerMode == MBXMapViewShowDefaultBaseLayerIfPartial)
{
// Show default tiles only if a partial overlay.
//
CLLocationCoordinate2D nw = CLLocationCoordinate2DMake(self.coordinate.latitude + (self.region.span.latitudeDelta / 2),
self.coordinate.longitude - (self.region.span.longitudeDelta / 2));
CLLocationCoordinate2D se = CLLocationCoordinate2DMake(self.coordinate.latitude - (self.region.span.latitudeDelta / 2),
self.coordinate.longitude + (self.region.span.longitudeDelta / 2));
self.canReplaceMapContent = (nw.longitude == -180 &&
se.latitude <= -85 &&
se.longitude == 180 &&
nw.latitude >= 85);
}
else if (_mapView.showDefaultBaseLayerMode == MBXMapViewShowDefaultBaseLayerNever)
{
// Don't show default tiles when told not to.
//
self.canReplaceMapContent = YES;
}
else
{
// Show default tiles per user request.
//
self.canReplaceMapContent = NO;
}
}
}
return self;
}
- (NSInteger)centerZoom
{
return [self.tileJSONDictionary[@"center"][2] integerValue];
}
- (MKCoordinateRegion)region
{
if ( ! _region.span.latitudeDelta || ! _region.span.longitudeDelta)
{
CLLocationCoordinate2D center = CLLocationCoordinate2DMake([self.tileJSONDictionary[@"center"][1] doubleValue], [self.tileJSONDictionary[@"center"][0] doubleValue]);
CLLocationCoordinate2D nw = CLLocationCoordinate2DMake([self.tileJSONDictionary[@"bounds"][3] doubleValue], [self.tileJSONDictionary[@"bounds"][0] doubleValue]);
CLLocationCoordinate2D se = CLLocationCoordinate2DMake([self.tileJSONDictionary[@"bounds"][1] doubleValue], [self.tileJSONDictionary[@"bounds"][2] doubleValue]);
MKCoordinateSpan span = MKCoordinateSpanMake((nw.latitude - se.latitude), (se.longitude - nw.longitude));
_region = MKCoordinateRegionMake(center, span);
}
return _region;
}
- (CLLocationCoordinate2D)coordinate
{
return self.region.center;
}
- (MKMapRect)boundingMapRect
{
MKMapPoint nwPoint = MKMapPointForCoordinate(CLLocationCoordinate2DMake(self.coordinate.latitude + (self.region.span.latitudeDelta / 2),
self.coordinate.longitude - (self.region.span.longitudeDelta / 2)));
MKMapPoint sePoint = MKMapPointForCoordinate(CLLocationCoordinate2DMake(self.coordinate.latitude - (self.region.span.latitudeDelta / 2),
self.coordinate.longitude + (self.region.span.longitudeDelta / 2)));
return MKMapRectMake(nwPoint.x, nwPoint.y, (sePoint.x - nwPoint.x), (sePoint.y - nwPoint.y)); // note this follows the iOS 'y' convention
}
- (NSURL *)URLForTilePath:(MKTileOverlayPath)path
{
return [NSURL URLWithString:[NSString stringWithFormat:@"https://%@.tiles.mapbox.com/v3/%@/%ld/%ld/%ld%@.png",
[@[ @"a", @"b", @"c", @"d" ] objectAtIndex:(rand() % 4)],
self.mapView.mapID,
(long)path.z,
(long)path.x,
(long)path.y,
(path.contentScaleFactor > 1.0 ? @"@2x" : @"")]];
}
- (void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *tileData, NSError *error))result
{
if ( ! self.mapView)
{
// Don't load any tiles if we are a dummy layer.
//
result(nil, nil);
}
else
{
NSData *cachedData;
// Try the caching delegate first.
//
if ([self.mapView.cachingDelegate respondsToSelector:@selector(mapView:loadCacheDataForMapID:tilePath:)])
cachedData = [self.mapView.cachingDelegate mapView:self.mapView loadCacheDataForMapID:self.mapView.mapID tilePath:path];
// Then, check our own disk cache.
//
if ( ! cachedData)
cachedData = [NSData dataWithContentsOfFile:[self cachePathForTilePath:path]];
if (cachedData)
{
result(cachedData, nil);
}
else
{
// Otherwise, fetch & cache for next time.
//
[[self.mapView.dataSession dataTaskWithURL:[self URLForTilePath:path] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
if (data)
{
// TODO: Possibly pay attention to HTTP response headers. Generally,
// though, we're going to assume that the dev knows what they want
// here given the possibility of no network access.
if ([self.mapView.cachingDelegate respondsToSelector:@selector(mapView:saveCacheData:forMapID:tilePath:)])
{
// Offer to the caching delegate first.
//
[self.mapView.cachingDelegate mapView:self.mapView saveCacheData:data forMapID:self.mapView.mapID tilePath:path];
}
else
{
// Cache to disk in folders sorted by mapID.
//
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void)
{
[data writeToFile:[self cachePathForTilePath:path] atomically:YES];
});
}
// Return the new tile data.
//
result(data, nil);
}
else
{
// Return the fetch error directly.
//
result(nil, error);
}
}] resume];
}
// sweep cache periodically
//
if (rand() % 1000 == 0)
{
[self sweepCache];
}
}
}
- (NSString *)cachePathForTilePath:(MKTileOverlayPath)path
{
return [NSString stringWithFormat:@"%@/%@/%ld_%ld_%ld%@.png",
[self.mapView cachePath],
self.mapView.mapID,
(long)path.z,
(long)path.x,
(long)path.y,
(path.contentScaleFactor > 1.0 ? @"@2x" : @"")];
}
- (void)sweepCache
{
if (self.mapView)
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void)
{
NSDirectoryEnumerator *cacheEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:[self.mapView cachePath]];
NSString *filename;
while ((filename = [cacheEnumerator nextObject]))
{
NSString *filePath = [NSString stringWithFormat:@"%@/%@", [self.mapView cachePath], filename];
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
if (attributes[NSFileType] == NSFileTypeRegular && [attributes[NSFileModificationDate] timeIntervalSinceDate:[NSDate date]] < -kMBXMapViewCacheInterval)
[[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
}
});
}
}
@end
#pragma mark - MBXMapViewDelegate - Proxying delegate that ensures tile renderer -
@implementation MBXMapViewDelegate
+ (id)new
{
return [[self alloc] init];
}
- (id)init
{
return self;
}
- (NSString *)description
{
return [NSString stringWithFormat:@"<MBXMapViewDelegate: %p, realDelegate: %p>", self, self.realDelegate];
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
{
if (selector == @selector(mapView:rendererForOverlay:))
return [[MBXMapViewDelegate class] methodSignatureForSelector:selector];
if ([self.realDelegate respondsToSelector:selector])
return [(NSObject *)self.realDelegate methodSignatureForSelector:selector];
return [[NSObject class] methodSignatureForSelector:selector];
}
- (void)forwardInvocation:(NSInvocation *)invocation
{
if (invocation.selector == @selector(respondsToSelector:))
{
[invocation invokeWithTarget:self];
}
else if ([self.realDelegate respondsToSelector:invocation.selector])
{
[invocation invokeWithTarget:self.realDelegate];
}
}
- (BOOL)respondsToSelector:(SEL)selector
{
if (selector == @selector(mapView:rendererForOverlay:))
return YES;
return ([self.realDelegate respondsToSelector:selector]);
}
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay
{
if ([self.realDelegate respondsToSelector:@selector(mapView:rendererForOverlay:)])
{
// If user-set delegate wants to provide a tile renderer, let it.
//
if ([overlay isKindOfClass:[MBXMapViewTileOverlay class]])
{
// If it fails at providing a renderer for our managed overlay, step in.
//
MKOverlayRenderer *renderer = [self.realDelegate mapView:mapView rendererForOverlay:overlay];
return (renderer ? renderer : [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay]);
}
else
{
// Let it provide a renderer for all user-set overlays.
//
return [self.realDelegate mapView:mapView rendererForOverlay:overlay];
}
}
else if ([overlay isKindOfClass:[MBXMapViewTileOverlay class]])
{
// Step in if the user-set delegate doens't try to provide a renderer.
//
return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
}
// We're not in the general renderer-providing business.
//
return nil;
}
@end
#pragma mark - MBXMapView - Map view with self-managing overlay & proxying delegate -
@implementation MBXMapView
- (void)MBXMapView_commonSetupWithMapID:(NSString *)mapID showDefaultBaseLayerMode:(MBXMapViewShowDefaultBaseLayerMode)mode
{
id existingDelegate;
if (self.delegate)
existingDelegate = self.delegate; // XIB
_ownedDelegate = [MBXMapViewDelegate new];
[super setDelegate:_ownedDelegate];
_ownedDelegate.realDelegate = existingDelegate;
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
sessionConfiguration.HTTPAdditionalHeaders = @{ @"User-Agent" : [self userAgentString] };
_dataSession = [NSURLSession sessionWithConfiguration:sessionConfiguration];
_cacheInterval = kMBXMapViewCacheInterval;
_showDefaultBaseLayerMode = mode;
if (_showDefaultBaseLayerMode == MBXMapViewShowDefaultBaseLayerNever || _showDefaultBaseLayerMode == MBXMapViewShowDefaultBaseLayerIfPartial)
{
// Add dummy overlay until we get TileJSON. Don't show default tiles just in case.
//
self.tileOverlay = [[MBXMapViewTileOverlay alloc] initWithTileJSONDictionary:nil mapView:self];
[self insertOverlay:self.tileOverlay atIndex:0];
}
[self setMapID:mapID];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
[self MBXMapView_commonSetupWithMapID:nil showDefaultBaseLayerMode:MBXMapViewShowDefaultBaseLayerAlways];
return self;
}
- (id)initWithFrame:(CGRect)frame mapID:(NSString *)mapID
{
self = [super initWithFrame:frame];
if (self)
[self MBXMapView_commonSetupWithMapID:mapID showDefaultBaseLayerMode:MBXMapViewShowDefaultBaseLayerIfPartial];
return self;
}
- (id)initWithFrame:(CGRect)frame mapID:(NSString *)mapID showDefaultBaseLayer:(BOOL)showDefaultBaseLayer
{
self = [super initWithFrame:frame];
if (self)
[self MBXMapView_commonSetupWithMapID:mapID showDefaultBaseLayerMode:(showDefaultBaseLayer ? MBXMapViewShowDefaultBaseLayerAlways : MBXMapViewShowDefaultBaseLayerNever)];
return self;
}
- (id)initWithCoder:(NSCoder *)decoder
{
self = [super initWithCoder:decoder];
if (self)
[self MBXMapView_commonSetupWithMapID:nil showDefaultBaseLayerMode:MBXMapViewShowDefaultBaseLayerNever];
return self;
}
- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate
{
self.hasInitialCenterCoordinate = YES;
[super setCenterCoordinate:centerCoordinate];
}
- (void)setRegion:(MKCoordinateRegion)region
{
self.hasInitialCenterCoordinate = YES;
[super setRegion:region];
}
- (void)setVisibleMapRect:(MKMapRect)visibleMapRect
{
self.hasInitialCenterCoordinate = YES;
[super setVisibleMapRect:visibleMapRect];
}
- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated
{
self.hasInitialCenterCoordinate = YES;
[super setCenterCoordinate:coordinate animated:animated];
}
- (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated
{
self.hasInitialCenterCoordinate = YES;
[super setRegion:region animated:animated];
}
- (void)setVisibleMapRect:(MKMapRect)mapRect animated:(BOOL)animate
{
self.hasInitialCenterCoordinate = YES;
[super setVisibleMapRect:mapRect animated:animate];
}
- (void)setVisibleMapRect:(MKMapRect)mapRect edgePadding:(UIEdgeInsets)insets animated:(BOOL)animate
{
self.hasInitialCenterCoordinate = YES;
[super setVisibleMapRect:mapRect edgePadding:insets animated:animate];
}
- (void)showAnnotations:(NSArray *)annotations animated:(BOOL)animated
{
self.hasInitialCenterCoordinate = YES;
[super showAnnotations:annotations animated:animated];
}
- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(NSUInteger)zoomLevel animated:(BOOL)animated
{
[self setRegion:MKCoordinateRegionMake(centerCoordinate, MKCoordinateSpanMake(0, 360 / pow(2, zoomLevel) * self.frame.size.width / 256)) animated:animated];
}
- (void)setMapID:(NSString *)mapID
{
if ( ! [_mapID isEqual:mapID])
{
_mapID = [mapID copy];
if (_mapID)
[self updateOverlay];
}
}
- (void)updateOverlay
{
[self.metadataTask cancel];
[[NSFileManager defaultManager] createDirectoryAtPath:[NSString stringWithFormat:@"%@/%@", self.cachePath, self.mapID]
withIntermediateDirectories:YES
attributes:nil
error:nil];
NSString *tileJSONCachePath = [NSString stringWithFormat:@"%@/%@/%@.json", self.cachePath, self.mapID, self.mapID];
NSURL *tileJSONURL = ([[NSFileManager defaultManager] fileExistsAtPath:tileJSONCachePath] ? [NSURL fileURLWithPath:tileJSONCachePath] : [NSURL URLWithString:[NSString stringWithFormat:@"https://a.tiles.mapbox.com/v3/%@.json", _mapID]]);
__weak __typeof(self)weakSelf = self;
self.metadataTask = [self.dataSession dataTaskWithURL:tileJSONURL
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
{
if (data)
{
NSError *parseError;
NSDictionary *tileJSONDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
if (tileJSONDictionary)
{
for (NSString *requiredKey in @[ @"id", @"minzoom", @"maxzoom", @"bounds", @"center" ])
{
if ( ! tileJSONDictionary[requiredKey])
{
NSLog(@"Invalid TileJSON for map ID %@ - retrying! (missing key '%@')", _mapID, requiredKey);
return [weakSelf updateOverlay];
}
}
[data writeToFile:tileJSONCachePath atomically:YES];
dispatch_sync(dispatch_get_main_queue(), ^(void)
{
// Remove existing overlay.
//
[self removeOverlay:self.tileOverlay];
// Add the real overlay. Obey the original default tiles request mode.
//
self.tileOverlay = [[MBXMapViewTileOverlay alloc] initWithTileJSONDictionary:tileJSONDictionary mapView:self];
[self.tileOverlay sweepCache];
[self insertOverlay:self.tileOverlay atIndex:0];
if ( ! self.hasInitialCenterCoordinate)
[self setCenterCoordinate:self.tileOverlay.coordinate zoomLevel:self.tileOverlay.centerZoom animated:NO];
});
}
else
{
NSLog(@"Error parsing TileJSON for map ID %@ - retrying! (%@)", _mapID, parseError);
[weakSelf updateOverlay];
}
}
else
{
NSLog(@"Error downloading TileJSON for map ID %@ - retrying! (%@)", _mapID, error);
[weakSelf updateOverlay];
}
}];
[self.metadataTask resume];
}
- (void)reloadRenderer
{
if ([self rendererForOverlay:self.tileOverlay])
{
NSInteger index = [self.overlays indexOfObject:self.tileOverlay];
[self removeOverlay:self.tileOverlay];
[self insertOverlay:self.tileOverlay atIndex:index];
}
}
- (void)setDelegate:(id<MKMapViewDelegate>)delegate
{
// MKMapView scans its delegate for implemented methods when set. Here we set the same
// delegate again to cause a re-scan of possible new methods in the user-set delegate.
// We also reload the managed overlay to give the new delegate a chance to supply its
// own tile renderer.
//
[super setDelegate:nil];
self.ownedDelegate.realDelegate = delegate;
[super setDelegate:self.ownedDelegate];
[self reloadRenderer];
}
- (NSString *)userAgentString
{
#if TARGET_OS_IPHONE
return [NSString stringWithFormat:@"MBXMapKit (%@/%@)", [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion]];
#else
return [NSString stringWithFormat:@"MBXMapKit (OS X/%@)", [[NSProcessInfo processInfo] operatingSystemVersionString]];
#endif
}
- (NSString *)systemPath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *path = ([paths count] ? paths[0] : NSTemporaryDirectory());
#if ! TARGET_OS_IPHONE
path = [NSString stringWithFormat:@"%@/%@", path, [[NSProcessInfo processInfo] processName]];
#endif
return path;
}
- (NSString *)cachePath
{
static NSString *_cachePath;
if ( ! _cachePath)
_cachePath = [NSString stringWithFormat:@"%@/%@", [self systemPath], kMBXMapViewCacheFolder];
return _cachePath;
}
- (void)setCacheInterval:(NSTimeInterval)cacheInterval
{
_cacheInterval = cacheInterval;
[self.tileOverlay sweepCache];
}
- (void)emptyCacheForMapID:(NSString *)mapID
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void)
{
[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", [self cachePath], mapID] error:nil];
});
}
@end