WMTS layer

View inJavaKotlinView on GitHubSample viewer app

Display a layer from a Web Map Tile Service.

Image of WMTS layer

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

Pan and zoom to explore the WMTS layer, which is displayed automatically.

How it works

  1. Create a WmtsService using the URL of the WMTS Service.
  2. After loading the WMTS service, get the list of WmtsLayerInfos from the service info: service.getServiceInfo().getLayerInfos()
  3. Use one of the layer infos to create a new WmtsLayer(layerInfos.get(0))
  4. Set it as the maps' basemap with map.setBasemap(new 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.java
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
81
82
83
84
85
86
87
88
89
/* Copyright 2018 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 java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
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.WmtsLayerInfo;
import com.esri.arcgisruntime.ogc.wmts.WmtsService;
import com.esri.arcgisruntime.ogc.wmts.WmtsServiceInfo;

public class MainActivity extends AppCompatActivity {

  private final String TAG = MainActivity.class.getSimpleName();
  private MapView mMapView;
  // objects that implement Loadable must be class fields to prevent being garbage collected before loading
  private WmtsService mWmtsService;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // inflate MapView from layout
    mMapView = findViewById(R.id.mapView);
    // create an ArcGIS map
    ArcGISMap map = new ArcGISMap();
    mMapView.setMap(map);
    // create wmts service from url string
    mWmtsService = new WmtsService(getString(R.string.wmts_url));
    mWmtsService.addDoneLoadingListener(() -> {
      if (mWmtsService.getLoadStatus() == LoadStatus.LOADED) {
        // get service info
        WmtsServiceInfo wmtsServiceInfo = mWmtsService.getServiceInfo();
        // get the first layer id
        List<WmtsLayerInfo> layerInfoList = wmtsServiceInfo.getLayerInfos();
        // create WMTS layer from layer info
        WmtsLayer wmtsLayer = new WmtsLayer(layerInfoList.get(0));
        // set the basemap of the map with WMTS layer
        map.setBasemap(new Basemap(wmtsLayer));
      } else {
        String error = "Error loading WMTS Service: " + mWmtsService.getLoadError();
        Log.e(TAG, error);
        Toast.makeText(this, error, Toast.LENGTH_LONG).show();
      }
    });
    mWmtsService.loadAsync();
  }

  @Override
  protected void onPause() {
    super.onPause();
    mMapView.pause();
  }

  @Override
  protected void onResume() {
    super.onResume();
    mMapView.resume();
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    mMapView.dispose();
  }
}

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