WMTS layer

View on GitHub
Sample viewer app

Display a layer from a Web Map Tile Service.

WMTS layer sample

Use case

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

  1. Create an AGSWMTSService object using the URL of the WMTS service.
  2. Create an AGSWMTSLayer object with the ID of the layer to display.
  3. 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
                                                       
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

class WMTSLayerViewController: UIViewController {
    @IBOutlet private weak var mapView: AGSMapView!

    private var map: AGSMap!
    private var wmtsService: AGSWMTSService!

    private let wmtsServiceURL = URL(string: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/WMTS")!

    override func viewDidLoad() {
        super.viewDidLoad()

        // initialize the map
        self.map = AGSMap()

        // assign the map to the map view
        self.mapView.map = self.map

        // create a WMTS service with the service URL
        self.wmtsService = AGSWMTSService(url: wmtsServiceURL)

        // load the WMTS service to access the service information
        self.wmtsService.load { [weak self] (error) in
            guard let self = self else { return }
            if let error = error {
                self.presentAlert(message: "Failed to load WMTS layer: \(error.localizedDescription)")
            } else if let 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"]
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.