1、應用需求
ArcGIS Server伺服器增加、刪除服務,移動端能動態擷取服務列表;
2、移動端解決方案
2.1、擷取伺服器端服務列表URL地址
(1)開啟ArcGIS Server服務類別目錄
(2)點擊rest得到服務列表URL
(3)點擊rest可以看到服務列表的json串,這個url就是我們擷取服務列表的url
2.2 IOS讀取方法
(1)非同步呼叫服務
//服務URL
NSURL* url = [NSURL URLWithString:@"http://192.168.0.1/arcgis/rest/services?f=pjson"];
//self.currentJsonOp是 AGSJSONRequestOperation 對象self.currentJsonOp = [[[AGSJSONRequestOperation alloc]initWithURL:url]autorelease];
self.currentJsonOp.target = self;
self.currentJsonOp.action = @selector(operation:didSucceedWithResponse:);
self.currentJsonOp.errorAction = @selector(operation:didFailWithError:);
//self.queue 是 NSOperationQueue 對象
//Add operation to the queue to execute in
the background
[self.queue addOperation:self.currentJsonOp];
(2)處理調用結果,得到服務名稱
//成功處理,The webservice was invoked successfully.
- (void)operation:(NSOperation*)op didSucceedWithResponse:(NSDictionary*)weatherInfo{
//Print the response to see what the JSON
payload looks like.
NSLog(@"%@", weatherInfo);
NSLog(@"number is %d",weatherInfo.count);
if([weatherInfo objectForKey:@"services"]!=nil){
NSArray *servicesArray=[weatherInfo
objectForKey:@"services"];
NSLog(@"%@,lenth is %d", servicesArray,[servicesArraycount]);
for (int i=0; i<[servicesArraycount];i++)
{
NSDictionary *services=[servicesArrayobjectAtIndex:i];
//NSLog(@"%@", services);
NSString *name=[servicesobjectForKey:@"name"];
NSString *type=[servicesobjectForKey:@"type"];
NSLog(@"%@,%@",name,type);
}
}
}
//處理失敗,Error encountered while invoking webservice. Alert user
- (void)operation:(NSOperation*)op didFailWithError:(NSError *)error{
self.mapView.callout.hidden = YES;
UIAlertView* av = [[[UIAlertView alloc] initWithTitle:@"Sorry"
message:[error localizedDescription]
delegate:nil cancelButtonTitle:@"OK"
otherButtonTitles:nil] autorelease];
[av show];
}
這樣就動態得到了地圖服務的URL列表