WMTS services can have several layers. You can use Runtime to explore the layers available from a service. This would commonly be used to enable a browsing experience where users can choose which layers they want to display at run time.
How to use the sample
The layer will be displayed automatically. Pan and zoom to explore.
How it works
Create an AGSWMTSService object using the URL of the WMTS service.
Create an AGSWMTSLayer object with the ID of the layer to display.
Make an AGSBasemap from the AGSWMTSLayer and apply it to the map.
Relevant API
AGSWMTSLayer
AGSWMTSLayerInfo
AGSWMTSService
AGSWMTSServiceInfo
About the data
The map visualizes world time zones.
Tags
layer, OGC, raster, tiled, web map tile service
Sample Code
WMTSLayerViewController.swift
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2017 Esri.//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.import UIKit
import ArcGIS
classWMTSLayerViewController: UIViewController{
@IBOutletprivateweakvar mapView: AGSMapView!
privatevar map: AGSMap!
privatevar wmtsService: AGSWMTSService!
privatelet wmtsServiceURL =URL(string: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/WMTS")!overridefuncviewDidLoad() {
super.viewDidLoad()
// initialize the mapself.map =AGSMap()
// assign the map to the map viewself.mapView.map =self.map
// create a WMTS service with the service URLself.wmtsService =AGSWMTSService(url: wmtsServiceURL)
// load the WMTS service to access the service informationself.wmtsService.load { [weakself] (error) inguardletself=selfelse { return }
iflet error = error {
self.presentAlert(message: "Failed to load WMTS layer: \(error.localizedDescription)")
} elseiflet layerInfo =self.wmtsService.serviceInfo?.layerInfos.first {
// Create a WMTS layer using the first element in the collection// of WMTS layer info objects.let wmtsLayer =AGSWMTSLayer(layerInfo: layerInfo)
// Set the basemap of the map with WMTS layer.self.map.basemap =AGSBasemap(baseLayer: wmtsLayer)
}
}
// add the source code button item to the right of navigation bar (self.navigationItem.rightBarButtonItem as!SourceCodeBarButtonItem).filenames = ["WMTSLayerViewController"]
}
}