2011年12月20日 星期二

iOS_於XCode4.2 Empty Application建立ESRI iOS開發環境

如果使用XCode4.2版在建立新專案的時,就不會出現ArcGIS的template,所以可能要自己建立相關的環境(或許過一陣子就有template可以用),既然要建立環境當然就是從Empty Application開始最有意義。

步驟:
1. 建立Empty Application專案

2. 取個名字,將該專案建立起來。

3. 加入ArcGIS library(於專案Build Phases內的Under the Link Binary with Libraries按“+”鍵),ArcGIS library並不在預設之內所以要點選“Add Other...”(預設位置:${HOME} /Library/SDKs/ArcGIS/iOS.sdk/usr/local/lib)。預設${HOME} /Library/是隱藏的資料夾,必須在command line輸入“chflags nohidden ~/Library/”,完成後${HOME} /Library/其實叫做“資源庫”。

4. 因為ArcGIS的library有使用到一些預設的framework與library,所以空專案必須要將其內容都加進去。(資料來源)
********************************************************
CoreGraphics.framework
CoreLocation.framework
Foundation.framework
QuartzCore.framework
UIKit.framework
CoreText.framework (dependency introduced at v1.8)
libstdc++.dylib (dependency introduced at v1.8)
MediaPlayer.framework (dependency introduced at v2.0)
MobileCoreServices.framework (dependency introduced at v2.0)
libz.dylib (dependency introduced at v2.1)
Security.framework (dependency introduced at v2.1)
********************************************************
連同上一步驟加上去的共12項。

5. 設定Build Setting(搜尋Other Linker Flags增加-all_load與-ObjC)

6. 設定Build Setting(搜尋User Header Search輸入$(HOME)/Library/SDKs/ArcGIS/iOS.sdk/usr/local/include/**)

7. 都設定完成後,就可以先執行一下,看是否有跳出錯誤。

8. 接下來就可以測試是否可以正確接到ESRI的Map Service
h檔

#import
#import "ArcGIS.h"
#define kTiledMapServiceURL @"http://your url/ArcGIS/rest/services/MapServer"

@interface AppDelegate:UIViewController {
AGSMapView *_mapView;
}
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, retain) AGSMapView *mapView;
@end


m檔

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize mapView = _mapView;

-(void) initApp
{
CGRect appRect = [[UIScreen mainScreen] applicationFrame];
_mapView = [[AGSMapView alloc] initWithFrame:appRect];
[self.window addSubview:_mapView];

AGSTiledMapServiceLayer *tiledLayer = [[AGSTiledMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kTiledMapServiceURL]];
[self.mapView addMapLayer:tiledLayer withName:@"Tiled Layer"];

[tiledLayer release];

AGSSpatialReference *sr = [AGSSpatialReference spatialReferenceWithWKID:102443];
double xmin, ymin, xmax, ymax;
xmin = 281082;
ymin = 2739078;
xmax = 341217;
ymax = 2791975;

// zoom to the United States
AGSEnvelope *env = [AGSEnvelope envelopeWithXmin:xmin ymin:ymin xmax:xmax ymax:ymax spatialReference:sr];
[self.mapView zoomToEnvelope:env animated:YES];
}

-(void)dealloc
{
[_mapView release];
[_window release];
[super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self initApp];
[self.window makeKeyAndVisible];
return YES;
}

9. 都完成後,可以執行看看效果。


如此我們就可以從一個完全空白的專案到一個TiledMapService讀進來。

沒有留言:

張貼留言