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 the layer.
How it works
To display a WMTS layer directly from a URL:
Create a WmtsService object using the URL of the WMTS service.
Create a WmtsLayer object with the ID of the layer to display.
To explore layers from a WMTS service:
Create a WmtsService object using the URL of the WMTS service.
After loading the WMTS service, get the list of WmtsLayerInfo objects from the service info of the WMTS service with wmtsServiceInfo.layerInfos.
Use one of the layer infos to create the WMTS layer with WmtsLayer(layerInfos[0]).
Create a basemap with the WMTS layer and set it to the map with map.basemap = Basemap(wmtsLayer).
Relevant API
WmtsLayer
WmtsLayerInfo
WmtsService
WmtsServiceInfo
About the data
The map visualizes world time zones.
Tags
layer, OGC, raster, tiled, web map tile service
Sample Code
MainActivity.kt
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* 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.
*
*/package com.esri.arcgisruntime.sample.wmtslayer
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.esri.arcgisruntime.layers.WmtsLayer
import com.esri.arcgisruntime.loadable.LoadStatus
import com.esri.arcgisruntime.mapping.ArcGISMap
import com.esri.arcgisruntime.mapping.Basemap
import com.esri.arcgisruntime.mapping.view.MapView
import com.esri.arcgisruntime.ogc.wmts.WmtsService
import com.esri.arcgisruntime.sample.wmtslayer.databinding.ActivityMainBinding
classMainActivity : AppCompatActivity() {
// objects that implement Loadable must be class fields to prevent being garbage collected before loadingprivateval wmtsService: WmtsService by lazy { WmtsService(getString(R.string.wmts_url)) }
privateval activityMainBinding by lazy {
ActivityMainBinding.inflate(layoutInflater)
}
privateval mapView: MapView by lazy {
activityMainBinding.mapView
}
overridefunonCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(activityMainBinding.root)
// create a Mapval map = ArcGISMap()
// set the map to be displayed in this view mapView.map = map
// display wmts data on the map wmtsService.addDoneLoadingListener {
if (wmtsService.loadStatus == LoadStatus.LOADED) {
// get service infoval wmtsServiceInfo = wmtsService.serviceInfo
// get the first layers idval layerInfos = wmtsServiceInfo.layerInfos
// create WMTS layer from layer infoval wmtsLayer = WmtsLayer(layerInfos[0])
// set the basemap of the map with WMTS layer map.basemap = Basemap(wmtsLayer)
}
}
wmtsService.loadAsync()
}
overridefunonPause() {
super.onPause()
mapView.pause()
}
overridefunonResume() {
super.onResume()
mapView.resume()
}
overridefunonDestroy() {
super.onDestroy()
mapView.dispose()
}
}