/MapView/Map/RMVirtualEarthSource.m
Objective C | 143 lines | 101 code | 15 blank | 27 comment | 9 complexity | 8a45022da0818614dc8b3eee04e6aa4f MD5 | raw file
1// 2// RMVirtualEarthURL.m 3// 4// Copyright (c) 2008-2009, Route-Me Contributors 5// All rights reserved. 6// 7// Redistribution and use in source and binary forms, with or without 8// modification, are permitted provided that the following conditions are met: 9// 10// * Redistributions of source code must retain the above copyright notice, this 11// list of conditions and the following disclaimer. 12// * Redistributions in binary form must reproduce the above copyright notice, 13// this list of conditions and the following disclaimer in the documentation 14// and/or other materials provided with the distribution. 15// 16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26// POSSIBILITY OF SUCH DAMAGE. 27 28#import "RMVirtualEarthSource.h" 29 30 31@implementation RMVirtualEarthSource 32- (id) init 33{ 34 return [self initWithHybridThemeUsingAccessKey:@""]; 35} 36 37- (id) initWithAerialThemeUsingAccessKey:(NSString *)developerAccessKey 38{ 39 RMLog(@"please see comments in RMVirtualEarthSource.h"); 40 NSAssert(([developerAccessKey length] > 0), @"Virtual Earth access key must be non-empty"); 41 if (self = [super init]) 42 { 43 [self setMaxZoom:18]; 44 [self setMinZoom:1]; 45 46 maptypeFlag = @"a"; 47 accessKey = developerAccessKey; 48 _shortName = @"Microsoft Virtual Earth satellite"; 49 } 50 return self; 51} 52 53- (id) initWithRoadThemeUsingAccessKey:(NSString *)developerAccessKey 54{ 55 RMLog(@"please see comments in RMVirtualEarthSource.h"); 56 NSAssert(([developerAccessKey length] > 0), @"Virtual Earth access key must be non-empty"); 57 if (self = [super init]) 58 { 59 [self setMaxZoom:18]; 60 [self setMinZoom:1]; 61 62 maptypeFlag = @"r"; 63 accessKey = developerAccessKey; 64 _shortName = @"Microsoft Virtual Earth roads"; 65 } 66 return self; 67} 68- (id) initWithHybridThemeUsingAccessKey:(NSString *)developerAccessKey 69{ 70 RMLog(@"please see comments in RMVirtualEarthSource.h"); 71 NSAssert(([developerAccessKey length] > 0), @"Virtual Earth access key must be non-empty"); 72 if (self = [super init]) 73 { 74 [self setMaxZoom:18]; 75 [self setMinZoom:1]; 76 77 maptypeFlag = @"h"; 78 accessKey = developerAccessKey; 79 _shortName = @"Microsoft Virtual Earth hybrid"; 80 } 81 return self; 82} 83 84-(NSString*) tileURL: (RMTile) tile 85{ 86 NSString *quadKey = [self quadKeyForTile:tile]; 87 return [self urlForQuadKey:quadKey]; 88} 89 90-(NSString*) quadKeyForTile: (RMTile) tile 91{ 92 NSAssert4(((tile.zoom >= self.minZoom) && (tile.zoom <= self.maxZoom)), 93 @"%@ tried to retrieve tile with zoomLevel %d, outside source's defined range %f to %f", 94 self, tile.zoom, self.minZoom, self.maxZoom); 95 NSMutableString *quadKey = [NSMutableString string]; 96 for (int i = tile.zoom; i > 0; i--) 97 { 98 int mask = 1 << (i - 1); 99 int cell = 0; 100 if ((tile.x & mask) != 0) 101 { 102 cell++; 103 } 104 if ((tile.y & mask) != 0) 105 { 106 cell += 2; 107 } 108 [quadKey appendString:[NSString stringWithFormat:@"%d", cell]]; 109 } 110 return quadKey; 111} 112 113-(NSString*) urlForQuadKey: (NSString*) quadKey 114{ 115 NSString *mapExtension = @".png"; //extension 116 117 //TODO what is the ?g= hanging off the end 1 or 15? 118 return [NSString stringWithFormat:@"http://%@%d.ortho.tiles.virtualearth.net/tiles/%@%@%@?g=15", maptypeFlag, 3, maptypeFlag, quadKey, mapExtension]; 119} 120 121-(NSString*) uniqueTilecacheKey 122{ 123 return [NSString stringWithFormat:@"MicrosoftVirtualEarth%@", maptypeFlag]; 124} 125 126-(NSString *)shortName 127{ 128 return _shortName; 129} 130-(NSString *)longDescription 131{ 132 return @"Microsoft Virtual Earth. All data © Microsoft or their licensees."; 133} 134-(NSString *)shortAttribution 135{ 136 return @"© Microsoft Virtual Earth"; 137} 138-(NSString *)longAttribution 139{ 140 return @"Map data © Microsoft Virtual Earth."; 141} 142 143@end