HowTo:  Consume open source (WMS and WMTS) services with the ArcGIS Runtime SDK for iOS

相关信息
Article ID: 41542
Software:
ArcGIS API for iOS 1.0, 1.0 Update, 1.8, 2.0
ArcGIS Runtime SDK for iOS 10.1.1
Platforms: N/A

问题描述
The ArcGIS Runtime SDK for iOS meets OGC standards for web map services (WMS) and web map tiled services (WMTS). These services can be hosted on ArcGIS Server, or on open source servers like GeoServer.

Debugging these applications can be tricky. It is recommended to use a web debugger, either on a Mac or on a PC as a proxy. These applications work whether the testing is done on a physical iOS device or a simulator. Some examples are:

•
Charles - Web Debugging Proxy Application for Windows, Mac OS and Linux

•
Fiddler - Web Debugging Proxy (PC)

▪ ▪ Fiddler documentation:
Capture Traffic on a PC from an iOS Device
已邀请:

EsriSupport

赞同来自:

解决方案
WMS Provide the URL to the WMS service. This may vary depending on the server structure. Here are two examples of valid URLs: • This is an instance of GeoServer

NSURL *url = [NSURL URLWithString:@
"http://demo.opengeo.org/geoserver/wms"];
• This is an instance of ArcGIS Server


NSURL *url = [NSURL URLWithString:@
"http://sampleserver6.arcgisonl ... ot%3B];
• To add the WMS to the map, use these lines of code:


AGSWMSLayer *wmsLayer = [AGSWMSLayer wmsLayerWithURL:url];
[self.mapView addMapLayer:wmsLayer withName:@"AnyName"];
• The 'withName' refers to a relative name for the WMS layer. This is not the actual name, but a relative one used to keep track of the layer in case it is necessary to modify or retrieve it later.

• To add, or exclude, specific layers in a Map Service, it is necessary to specify the number of the layer of interest as an object in an array.

For example, if only the second layer in a Map Service is to be shown in the map, the Map Service is (0), the first layer is (1), and the second layer is (2):

wmsLayer.visibleLayers = [NSArray arrayWithObject:@"2"];

Sample WMS application file:

// ViewController.m
// MyFirstMapApp
// Copyright (c) 2013 Esri. All rights reserved.

#import "ViewController.h"

@interface ViewController ()

@End

@implementation ViewController

//GPS location function, comment-out to remove location display (blue dot)
- (void) mapViewDidLoad:(AGSMapView *)mapView
{
// [mapView.locationDisplay startDataSource];
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

NSURL *url1 = [NSURL
URLWithString:@"http://demo.opengeo.org/geoserver/wms"];

NSURL *url2 = [NSURL URLWithString:@"http://sampleserver6.arcgisonl ... ot%3B];

AGSWMSLayer *wmsLayer1 = [AGSWMSLayer wmsLayer1WithURL:url1];
AGSWMSLayer *wmsLayer2 = [AGSWMSLayer wmsLayer2WithURL:url2];

[self.mapView addMapLayer:wmsLayer1 withName:@"AnyName"];

[self.mapView addMapLayer:wmsLayer2 withName:@"AnyName"];
wmsLayer2.visibleLayers = [NSArray arrayWithObject:@"2"];

self.mapView.layerDelegate = self;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@End

WMTS In the '.h' file, provide the URL to the WMTS service. This may vary depending on the server structure. Here is an example of a valid URL: • This is an instance of ArcGIS Server

#define wmtsURL @" http://sampleserver6.arcgisonl ... ot%3B
1. Add the AGSWMTSInfoDelegate to the ViewController interface:


@interface ViewController : UIViewController <AGSMapViewLayerDelegate, AGSWMTSInfoDelegate> {
AGSMapView *_mapView;}
2. Add properties to the WMTS layer:


@property (strong, nonatomic) AGSWMTSInfo *wmtsInfo;
@property (strong, nonatomic) AGSWMTSLayer *wmtsLayer;
3. In the '.m' file, add the WMTS to the map:


self.wmtsInfo = [[AGSWMTSInfo alloc] initWithURL: [NSURL URLWithString:wmtsURL]];
self.wmtsInfo.delegate = self;

Sample WMTS application file (ViewController.h):

// ViewController.h
// MyFirstMapApp
// Copyright (c) 2013 Esri. All rights reserved.

#import <UIKit/UIKit.h>
#import <ArcGIS/ArcGIS.h>
//spatial reference is 102100 (3857)
#define wmtsURL @" http://sampleserver6.arcgisonl ... ot%3B

@interface ViewController : UIViewController <AGSMapViewLayerDelegate, AGSWMTSInfoDelegate> {
//container for map layers
AGSMapView *_mapView;
}
//map view is an outlet so we can associate it with UIView
@property (strong, nonatomic) IBOutlet AGSMapView *mapView;

//add WMTS properties...
@property (strong, nonatomic) AGSWMTSInfo *wmtsInfo;
@property (strong, nonatomic) AGSWMTSLayer *wmtsLayer;

@End

Sample WMTS application file(ViewController.m):

// ViewController.m
// MyFirstMapApp
// Copyright (c) 2013 Esri. All rights reserved.

#import "ViewController.h"
@implementation ViewController
@synthesize mapView = _mapView;
//GPS location function, comment-out to remove location display (blue dot)
- (void) mapViewDidLoad:(AGSMapView *)mapView
{
// [mapView.locationDisplay startDataSource];
}

- (void)viewDidLoad
{
[super viewDidLoad];

self.mapView.layerDelegate = self;
self.wmtsInfo = [[AGSWMTSInfo alloc] initWithURL: [NSURL URLWithString:wmtsURL]];
self.wmtsInfo.delegate = self;

// Do any additional setup after loading the view, typically from a nib.
}

- (void) wmtsInfoDidLoad:(AGSWMTSInfo *) wmtsInfo{
NSArray *layerInfos = [wmtsInfo layerInfos];
AGSWMTSLayerInfo *layerInfo = [layerInfos objectAtIndex:0];
self.wmtsLayer = [wmtsInfo wmtsLayerWithLayerInfo:layerInfo andSpatialReference:nil];
[self.mapView addMapLayer:self.wmtsLayer withName:@"wmts Layer"];
}

// Show error message if something goes wrong
- (void) wmtsInfo:(AGSWMTSInfo *)wmtsInfo didFailToLoad:(NSError *)error {
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@End



其它相关参考
  1. WMS layer
  2. AGSWMSLayer Class Reference
  3. AGSWMTSLayer Class Reference


创建及修改时间
Created: 8/28/2013

Last Modified: 1/22/2014
原文链接
http://support.esri.com/en/kno ... 41542

要回复问题请先登录注册