Authored by BT Knorr

added support for Virtual Earth Tiles

//
// RMMercatorWebSource.h
// MapView
//
// Created by Brian Knorr on 9/19/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "RMTileSource.h"
@protocol AbstractMecatorWebSource
-(NSString*) tileURL: (RMTile) tile;
@end
@class RMFractalTileProjection;
@interface AbstractMecatorWebSource : NSObject <RMTileSource> {
RMFractalTileProjection *tileProjection;
}
@end
... ...
//
// RMMercatorWebSource.m
// MapView
//
// Created by Brian Knorr on 9/19/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "AbstractMecatorWebSource.h"
#import "RMTransform.h"
#import "RMTileImage.h"
#import "RMTileLoader.h"
#import "RMFractalTileProjection.h"
#import "RMTiledLayerController.h"
@implementation AbstractMecatorWebSource
-(id) init
{
if (![super init])
return nil;
RMMercatorRect bounds;
bounds.origin.x = -20037508.34;
bounds.origin.y = -20037508.34;
bounds.size.width = 20037508.34 * 2;
bounds.size.height = 20037508.34 * 2;
tileProjection = [[RMFractalTileProjection alloc] initWithBounds:bounds TileSideLength:256 MaxZoom:18];
return self;
}
-(void) dealloc
{
[tileProjection release];
[super dealloc];
}
-(RMTileImage *) tileImage: (RMTile)tile
{
RMTileImage* image = [RMTileImage imageWithTile: tile FromURL:[self tileURL:tile]];
// [cache addTile:tile WithImage:image];
return image;
}
-(RMFractalTileProjection*) tileProjection
{
return [[tileProjection retain] autorelease];
}
-(RMMercatorRect) bounds
{
return [tileProjection bounds];
}
//@synthesize cache;
@end
... ...
... ... @@ -6,23 +6,9 @@
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "RMTileSource.h"
#import "RMTile.h"
#import "AbstractMecatorWebSource.h"
@class RMTileImage;
@class RMFractalTileProjection;
@interface RMOpenStreetMapsSource : NSObject <RMTileSource> {
NSString *baseURL;
RMFractalTileProjection *tileProjection;
@interface RMOpenStreetMapsSource : AbstractMecatorWebSource <AbstractMecatorWebSource>{
}
-(RMTileImage *) tileImage: (RMTile)tile;
//-(TileImageSet*) tileImagesForScreen: (ScreenProjection*) screen;
//@property (readwrite, retain) TileCache *cache;
//@property (readonly) FractalTileProjection *tileProjection;
@end
... ...
... ... @@ -7,62 +7,12 @@
//
#import "RMOpenStreetMapsSource.h"
#import "RMProjection.h"
#import "RMTransform.h"
#import "RMTileImage.h"
#import "RMTileLoader.h"
#import "RMFractalTileProjection.h"
#import "RMTiledLayerController.h"
@implementation RMOpenStreetMapsSource
-(id) init
{
if (![super init])
return nil;
// trans = [[Transform alloc] initFrom:latlong To:google];
baseURL = @"http://a.tile.openstreetmap.org/";
RMMercatorRect bounds;
bounds.origin.x = -20037508.34;
bounds.origin.y = -20037508.34;
bounds.size.width = 20037508.34 * 2;
bounds.size.height = 20037508.34 * 2;
tileProjection = [[RMFractalTileProjection alloc] initWithBounds:bounds TileSideLength:256 MaxZoom:18];
return self;
}
-(void) dealloc
{
[tileProjection release];
[super dealloc];
}
-(NSString*) tileURL: (RMTile) tile
{
return [NSString stringWithFormat:@"http://tile.openstreetmap.org/%d/%d/%d.png", tile.zoom, tile.x, tile.y];
}
-(RMTileImage *) tileImage: (RMTile)tile
{
RMTileImage* image = [RMTileImage imageWithTile: tile FromURL:[self tileURL:tile]];
// [cache addTile:tile WithImage:image];
return image;
}
-(RMFractalTileProjection*) tileProjection
{
return [[tileProjection retain] autorelease];
}
-(RMMercatorRect) bounds
{
return [tileProjection bounds];
}
//@synthesize cache;
@end
... ...
//
// RMVirtualEarthURL.h
// MapView
//
// Created by Brian Knorr on 9/19/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "AbstractMecatorWebSource.h"
@interface RMVirtualEarthSource : AbstractMecatorWebSource <AbstractMecatorWebSource> {
}
-(NSString*) quadKeyForTile: (RMTile) tile;
-(NSString*) urlForQuadKey: (NSString*) quadKey;
@end
... ...
//
// RMVirtualEarthURL.m
// MapView
//
// Created by Brian Knorr on 9/19/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "RMVirtualEarthSource.h"
@implementation RMVirtualEarthSource
-(NSString*) tileURL: (RMTile) tile
{
NSString *quadKey = [self quadKeyForTile:tile];
return [self urlForQuadKey:quadKey];
}
-(NSString*) quadKeyForTile: (RMTile) tile
{
NSMutableString *quadKey = [NSMutableString string];
for (int i = tile.zoom; i > 0; i--)
{
int mask = 1 << (i - 1);
int cell = 0;
if ((tile.x & mask) != 0)
{
cell++;
}
if ((tile.y & mask) != 0)
{
cell += 2;
}
[quadKey appendString:[NSString stringWithFormat:@"%d", cell]];
}
return quadKey;
}
-(NSString*) urlForQuadKey: (NSString*) quadKey
{
NSString *mapType = @"r"; //type road
NSString *mapExtension = @".png"; //extension
//TODO what is the ?g= hanging off the end 1 or 15?
return [NSString stringWithFormat:@"http://%@%d.ortho.tiles.virtualearth.net/tiles/%@%@%@?g=15", mapType, 3, mapType, quadKey, mapExtension];
}
@end
... ...
... ... @@ -71,6 +71,8 @@
B83E66C30E80F053001663B6 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B83E65680E80E830001663B6 /* QuartzCore.framework */; };
B83E66C50E80F06D001663B6 /* libProj4.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B83E654F0E80E7A8001663B6 /* libProj4.a */; };
B83E67170E80F1CE001663B6 /* loading.png in Resources */ = {isa = PBXBuildFile; fileRef = B83E670F0E80F1B5001663B6 /* loading.png */; };
C7A967520E8412930031BA75 /* AbstractMecatorWebSource.m in Sources */ = {isa = PBXBuildFile; fileRef = C7A967510E8412930031BA75 /* AbstractMecatorWebSource.m */; };
C7A9675E0E84134B0031BA75 /* RMVirtualEarthSource.m in Sources */ = {isa = PBXBuildFile; fileRef = C7A9675D0E84134B0031BA75 /* RMVirtualEarthSource.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
... ... @@ -166,6 +168,10 @@
B83E65680E80E830001663B6 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
B83E670F0E80F1B5001663B6 /* loading.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = loading.png; path = ApplicationSupport/loading.png; sourceTree = "<group>"; };
B83E673E0E80F332001663B6 /* MapView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MapView.app; sourceTree = BUILT_PRODUCTS_DIR; };
C7A967500E8412930031BA75 /* AbstractMecatorWebSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractMecatorWebSource.h; sourceTree = "<group>"; };
C7A967510E8412930031BA75 /* AbstractMecatorWebSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AbstractMecatorWebSource.m; sourceTree = "<group>"; };
C7A9675C0E84134B0031BA75 /* RMVirtualEarthSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMVirtualEarthSource.h; sourceTree = "<group>"; };
C7A9675D0E84134B0031BA75 /* RMVirtualEarthSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMVirtualEarthSource.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
... ... @@ -384,8 +390,12 @@
isa = PBXGroup;
children = (
B83E64EC0E80E73F001663B6 /* RMTileSource.h */,
C7A967500E8412930031BA75 /* AbstractMecatorWebSource.h */,
C7A967510E8412930031BA75 /* AbstractMecatorWebSource.m */,
B83E64ED0E80E73F001663B6 /* RMOpenStreetMapsSource.h */,
B83E64EE0E80E73F001663B6 /* RMOpenStreetMapsSource.m */,
C7A9675C0E84134B0031BA75 /* RMVirtualEarthSource.h */,
C7A9675D0E84134B0031BA75 /* RMVirtualEarthSource.m */,
);
name = "Tile Source";
sourceTree = "<group>";
... ... @@ -536,6 +546,8 @@
1D60589B0D05DD56006BFB54 /* main.m in Sources */,
1D3623260D0F684500981E51 /* MapViewAppDelegate.m in Sources */,
28D7ACF80DDB3853001CB0EB /* MapViewViewController.m in Sources */,
C7A967520E8412930031BA75 /* AbstractMecatorWebSource.m in Sources */,
C7A9675E0E84134B0031BA75 /* RMVirtualEarthSource.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
... ...