added support for Virtual Earth Tiles
Showing
7 changed files
with
162 additions
and
66 deletions
MapView/Classes/AbstractMecatorWebSource.h
0 → 100644
1 | +// | ||
2 | +// RMMercatorWebSource.h | ||
3 | +// MapView | ||
4 | +// | ||
5 | +// Created by Brian Knorr on 9/19/08. | ||
6 | +// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
7 | +// | ||
8 | + | ||
9 | +#import "RMTileSource.h" | ||
10 | + | ||
11 | +@protocol AbstractMecatorWebSource | ||
12 | + | ||
13 | +-(NSString*) tileURL: (RMTile) tile; | ||
14 | + | ||
15 | +@end | ||
16 | + | ||
17 | +@class RMFractalTileProjection; | ||
18 | + | ||
19 | +@interface AbstractMecatorWebSource : NSObject <RMTileSource> { | ||
20 | + RMFractalTileProjection *tileProjection; | ||
21 | +} | ||
22 | + | ||
23 | +@end |
MapView/Classes/AbstractMecatorWebSource.m
0 → 100644
1 | +// | ||
2 | +// RMMercatorWebSource.m | ||
3 | +// MapView | ||
4 | +// | ||
5 | +// Created by Brian Knorr on 9/19/08. | ||
6 | +// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
7 | +// | ||
8 | + | ||
9 | +#import "AbstractMecatorWebSource.h" | ||
10 | +#import "RMTransform.h" | ||
11 | +#import "RMTileImage.h" | ||
12 | +#import "RMTileLoader.h" | ||
13 | +#import "RMFractalTileProjection.h" | ||
14 | +#import "RMTiledLayerController.h" | ||
15 | + | ||
16 | +@implementation AbstractMecatorWebSource | ||
17 | + | ||
18 | +-(id) init | ||
19 | +{ | ||
20 | + if (![super init]) | ||
21 | + return nil; | ||
22 | + | ||
23 | + RMMercatorRect bounds; | ||
24 | + bounds.origin.x = -20037508.34; | ||
25 | + bounds.origin.y = -20037508.34; | ||
26 | + bounds.size.width = 20037508.34 * 2; | ||
27 | + bounds.size.height = 20037508.34 * 2; | ||
28 | + tileProjection = [[RMFractalTileProjection alloc] initWithBounds:bounds TileSideLength:256 MaxZoom:18]; | ||
29 | + | ||
30 | + return self; | ||
31 | +} | ||
32 | + | ||
33 | +-(void) dealloc | ||
34 | +{ | ||
35 | + [tileProjection release]; | ||
36 | + [super dealloc]; | ||
37 | +} | ||
38 | + | ||
39 | +-(RMTileImage *) tileImage: (RMTile)tile | ||
40 | +{ | ||
41 | + RMTileImage* image = [RMTileImage imageWithTile: tile FromURL:[self tileURL:tile]]; | ||
42 | + // [cache addTile:tile WithImage:image]; | ||
43 | + return image; | ||
44 | +} | ||
45 | + | ||
46 | +-(RMFractalTileProjection*) tileProjection | ||
47 | +{ | ||
48 | + return [[tileProjection retain] autorelease]; | ||
49 | +} | ||
50 | + | ||
51 | +-(RMMercatorRect) bounds | ||
52 | +{ | ||
53 | + return [tileProjection bounds]; | ||
54 | +} | ||
55 | + | ||
56 | +//@synthesize cache; | ||
57 | + | ||
58 | +@end | ||
59 | + |
@@ -6,23 +6,9 @@ | @@ -6,23 +6,9 @@ | ||
6 | // Copyright 2008 __MyCompanyName__. All rights reserved. | 6 | // Copyright 2008 __MyCompanyName__. All rights reserved. |
7 | // | 7 | // |
8 | 8 | ||
9 | -#import <Foundation/Foundation.h> | ||
10 | -#import "RMTileSource.h" | ||
11 | -#import "RMTile.h" | 9 | +#import "AbstractMecatorWebSource.h" |
12 | 10 | ||
13 | -@class RMTileImage; | ||
14 | -@class RMFractalTileProjection; | ||
15 | - | ||
16 | -@interface RMOpenStreetMapsSource : NSObject <RMTileSource> { | ||
17 | - NSString *baseURL; | ||
18 | - RMFractalTileProjection *tileProjection; | 11 | +@interface RMOpenStreetMapsSource : AbstractMecatorWebSource <AbstractMecatorWebSource>{ |
19 | } | 12 | } |
20 | 13 | ||
21 | --(RMTileImage *) tileImage: (RMTile)tile; | ||
22 | - | ||
23 | -//-(TileImageSet*) tileImagesForScreen: (ScreenProjection*) screen; | ||
24 | - | ||
25 | -//@property (readwrite, retain) TileCache *cache; | ||
26 | -//@property (readonly) FractalTileProjection *tileProjection; | ||
27 | - | ||
28 | @end | 14 | @end |
@@ -7,62 +7,12 @@ | @@ -7,62 +7,12 @@ | ||
7 | // | 7 | // |
8 | 8 | ||
9 | #import "RMOpenStreetMapsSource.h" | 9 | #import "RMOpenStreetMapsSource.h" |
10 | -#import "RMProjection.h" | ||
11 | -#import "RMTransform.h" | ||
12 | -#import "RMTileImage.h" | ||
13 | -#import "RMTileLoader.h" | ||
14 | -#import "RMFractalTileProjection.h" | ||
15 | -#import "RMTiledLayerController.h" | ||
16 | 10 | ||
17 | @implementation RMOpenStreetMapsSource | 11 | @implementation RMOpenStreetMapsSource |
18 | 12 | ||
19 | --(id) init | ||
20 | -{ | ||
21 | - if (![super init]) | ||
22 | - return nil; | ||
23 | - | ||
24 | -// trans = [[Transform alloc] initFrom:latlong To:google]; | ||
25 | - | ||
26 | - baseURL = @"http://a.tile.openstreetmap.org/"; | ||
27 | - | ||
28 | - RMMercatorRect bounds; | ||
29 | - bounds.origin.x = -20037508.34; | ||
30 | - bounds.origin.y = -20037508.34; | ||
31 | - bounds.size.width = 20037508.34 * 2; | ||
32 | - bounds.size.height = 20037508.34 * 2; | ||
33 | - tileProjection = [[RMFractalTileProjection alloc] initWithBounds:bounds TileSideLength:256 MaxZoom:18]; | ||
34 | - | ||
35 | - return self; | ||
36 | -} | ||
37 | - | ||
38 | --(void) dealloc | ||
39 | -{ | ||
40 | - [tileProjection release]; | ||
41 | - [super dealloc]; | ||
42 | -} | ||
43 | - | ||
44 | -(NSString*) tileURL: (RMTile) tile | 13 | -(NSString*) tileURL: (RMTile) tile |
45 | { | 14 | { |
46 | return [NSString stringWithFormat:@"http://tile.openstreetmap.org/%d/%d/%d.png", tile.zoom, tile.x, tile.y]; | 15 | return [NSString stringWithFormat:@"http://tile.openstreetmap.org/%d/%d/%d.png", tile.zoom, tile.x, tile.y]; |
47 | } | 16 | } |
48 | 17 | ||
49 | --(RMTileImage *) tileImage: (RMTile)tile | ||
50 | -{ | ||
51 | - RMTileImage* image = [RMTileImage imageWithTile: tile FromURL:[self tileURL:tile]]; | ||
52 | -// [cache addTile:tile WithImage:image]; | ||
53 | - return image; | ||
54 | -} | ||
55 | - | ||
56 | --(RMFractalTileProjection*) tileProjection | ||
57 | -{ | ||
58 | - return [[tileProjection retain] autorelease]; | ||
59 | -} | ||
60 | - | ||
61 | --(RMMercatorRect) bounds | ||
62 | -{ | ||
63 | - return [tileProjection bounds]; | ||
64 | -} | ||
65 | - | ||
66 | -//@synthesize cache; | ||
67 | - | ||
68 | @end | 18 | @end |
MapView/Classes/RMVirtualEarthSource.h
0 → 100644
1 | +// | ||
2 | +// RMVirtualEarthURL.h | ||
3 | +// MapView | ||
4 | +// | ||
5 | +// Created by Brian Knorr on 9/19/08. | ||
6 | +// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
7 | +// | ||
8 | + | ||
9 | +#import "AbstractMecatorWebSource.h" | ||
10 | + | ||
11 | +@interface RMVirtualEarthSource : AbstractMecatorWebSource <AbstractMecatorWebSource> { | ||
12 | +} | ||
13 | + | ||
14 | +-(NSString*) quadKeyForTile: (RMTile) tile; | ||
15 | +-(NSString*) urlForQuadKey: (NSString*) quadKey; | ||
16 | + | ||
17 | +@end |
MapView/Classes/RMVirtualEarthSource.m
0 → 100644
1 | +// | ||
2 | +// RMVirtualEarthURL.m | ||
3 | +// MapView | ||
4 | +// | ||
5 | +// Created by Brian Knorr on 9/19/08. | ||
6 | +// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
7 | +// | ||
8 | + | ||
9 | +#import "RMVirtualEarthSource.h" | ||
10 | + | ||
11 | + | ||
12 | +@implementation RMVirtualEarthSource | ||
13 | + | ||
14 | +-(NSString*) tileURL: (RMTile) tile | ||
15 | +{ | ||
16 | + NSString *quadKey = [self quadKeyForTile:tile]; | ||
17 | + return [self urlForQuadKey:quadKey]; | ||
18 | +} | ||
19 | + | ||
20 | +-(NSString*) quadKeyForTile: (RMTile) tile | ||
21 | +{ | ||
22 | + NSMutableString *quadKey = [NSMutableString string]; | ||
23 | + for (int i = tile.zoom; i > 0; i--) | ||
24 | + { | ||
25 | + int mask = 1 << (i - 1); | ||
26 | + int cell = 0; | ||
27 | + if ((tile.x & mask) != 0) | ||
28 | + { | ||
29 | + cell++; | ||
30 | + } | ||
31 | + if ((tile.y & mask) != 0) | ||
32 | + { | ||
33 | + cell += 2; | ||
34 | + } | ||
35 | + [quadKey appendString:[NSString stringWithFormat:@"%d", cell]]; | ||
36 | + } | ||
37 | + return quadKey; | ||
38 | +} | ||
39 | + | ||
40 | +-(NSString*) urlForQuadKey: (NSString*) quadKey | ||
41 | +{ | ||
42 | + NSString *mapType = @"r"; //type road | ||
43 | + NSString *mapExtension = @".png"; //extension | ||
44 | + | ||
45 | + //TODO what is the ?g= hanging off the end 1 or 15? | ||
46 | + return [NSString stringWithFormat:@"http://%@%d.ortho.tiles.virtualearth.net/tiles/%@%@%@?g=15", mapType, 3, mapType, quadKey, mapExtension]; | ||
47 | +} | ||
48 | + | ||
49 | +@end |
@@ -71,6 +71,8 @@ | @@ -71,6 +71,8 @@ | ||
71 | B83E66C30E80F053001663B6 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B83E65680E80E830001663B6 /* QuartzCore.framework */; }; | 71 | B83E66C30E80F053001663B6 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B83E65680E80E830001663B6 /* QuartzCore.framework */; }; |
72 | B83E66C50E80F06D001663B6 /* libProj4.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B83E654F0E80E7A8001663B6 /* libProj4.a */; }; | 72 | B83E66C50E80F06D001663B6 /* libProj4.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B83E654F0E80E7A8001663B6 /* libProj4.a */; }; |
73 | B83E67170E80F1CE001663B6 /* loading.png in Resources */ = {isa = PBXBuildFile; fileRef = B83E670F0E80F1B5001663B6 /* loading.png */; }; | 73 | B83E67170E80F1CE001663B6 /* loading.png in Resources */ = {isa = PBXBuildFile; fileRef = B83E670F0E80F1B5001663B6 /* loading.png */; }; |
74 | + C7A967520E8412930031BA75 /* AbstractMecatorWebSource.m in Sources */ = {isa = PBXBuildFile; fileRef = C7A967510E8412930031BA75 /* AbstractMecatorWebSource.m */; }; | ||
75 | + C7A9675E0E84134B0031BA75 /* RMVirtualEarthSource.m in Sources */ = {isa = PBXBuildFile; fileRef = C7A9675D0E84134B0031BA75 /* RMVirtualEarthSource.m */; }; | ||
74 | /* End PBXBuildFile section */ | 76 | /* End PBXBuildFile section */ |
75 | 77 | ||
76 | /* Begin PBXContainerItemProxy section */ | 78 | /* Begin PBXContainerItemProxy section */ |
@@ -166,6 +168,10 @@ | @@ -166,6 +168,10 @@ | ||
166 | B83E65680E80E830001663B6 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; | 168 | B83E65680E80E830001663B6 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; |
167 | B83E670F0E80F1B5001663B6 /* loading.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = loading.png; path = ApplicationSupport/loading.png; sourceTree = "<group>"; }; | 169 | B83E670F0E80F1B5001663B6 /* loading.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = loading.png; path = ApplicationSupport/loading.png; sourceTree = "<group>"; }; |
168 | B83E673E0E80F332001663B6 /* MapView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MapView.app; sourceTree = BUILT_PRODUCTS_DIR; }; | 170 | B83E673E0E80F332001663B6 /* MapView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MapView.app; sourceTree = BUILT_PRODUCTS_DIR; }; |
171 | + C7A967500E8412930031BA75 /* AbstractMecatorWebSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractMecatorWebSource.h; sourceTree = "<group>"; }; | ||
172 | + C7A967510E8412930031BA75 /* AbstractMecatorWebSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AbstractMecatorWebSource.m; sourceTree = "<group>"; }; | ||
173 | + C7A9675C0E84134B0031BA75 /* RMVirtualEarthSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMVirtualEarthSource.h; sourceTree = "<group>"; }; | ||
174 | + C7A9675D0E84134B0031BA75 /* RMVirtualEarthSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMVirtualEarthSource.m; sourceTree = "<group>"; }; | ||
169 | /* End PBXFileReference section */ | 175 | /* End PBXFileReference section */ |
170 | 176 | ||
171 | /* Begin PBXFrameworksBuildPhase section */ | 177 | /* Begin PBXFrameworksBuildPhase section */ |
@@ -384,8 +390,12 @@ | @@ -384,8 +390,12 @@ | ||
384 | isa = PBXGroup; | 390 | isa = PBXGroup; |
385 | children = ( | 391 | children = ( |
386 | B83E64EC0E80E73F001663B6 /* RMTileSource.h */, | 392 | B83E64EC0E80E73F001663B6 /* RMTileSource.h */, |
393 | + C7A967500E8412930031BA75 /* AbstractMecatorWebSource.h */, | ||
394 | + C7A967510E8412930031BA75 /* AbstractMecatorWebSource.m */, | ||
387 | B83E64ED0E80E73F001663B6 /* RMOpenStreetMapsSource.h */, | 395 | B83E64ED0E80E73F001663B6 /* RMOpenStreetMapsSource.h */, |
388 | B83E64EE0E80E73F001663B6 /* RMOpenStreetMapsSource.m */, | 396 | B83E64EE0E80E73F001663B6 /* RMOpenStreetMapsSource.m */, |
397 | + C7A9675C0E84134B0031BA75 /* RMVirtualEarthSource.h */, | ||
398 | + C7A9675D0E84134B0031BA75 /* RMVirtualEarthSource.m */, | ||
389 | ); | 399 | ); |
390 | name = "Tile Source"; | 400 | name = "Tile Source"; |
391 | sourceTree = "<group>"; | 401 | sourceTree = "<group>"; |
@@ -536,6 +546,8 @@ | @@ -536,6 +546,8 @@ | ||
536 | 1D60589B0D05DD56006BFB54 /* main.m in Sources */, | 546 | 1D60589B0D05DD56006BFB54 /* main.m in Sources */, |
537 | 1D3623260D0F684500981E51 /* MapViewAppDelegate.m in Sources */, | 547 | 1D3623260D0F684500981E51 /* MapViewAppDelegate.m in Sources */, |
538 | 28D7ACF80DDB3853001CB0EB /* MapViewViewController.m in Sources */, | 548 | 28D7ACF80DDB3853001CB0EB /* MapViewViewController.m in Sources */, |
549 | + C7A967520E8412930031BA75 /* AbstractMecatorWebSource.m in Sources */, | ||
550 | + C7A9675E0E84134B0031BA75 /* RMVirtualEarthSource.m in Sources */, | ||
539 | ); | 551 | ); |
540 | runOnlyForDeploymentPostprocessing = 0; | 552 | runOnlyForDeploymentPostprocessing = 0; |
541 | }; | 553 | }; |
-
Please register or login to post a comment