Click or drag to resize

WmtsService Class

Represents a WMTS service. Loading this object retrieves the service metadata, accessible via ServiceInfo property.
Inheritance Hierarchy
SystemObject
  Esri.ArcGISRuntime.OgcWmtsService

Namespace:  Esri.ArcGISRuntime.Ogc
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.7.0.0
Syntax
C#
public class WmtsService : ILoadable

The WmtsService type exposes the following members.

Constructors
  NameDescription
Public methodWmtsService
Initializes a new instance of the WmtsService class.
Public methodCode exampleWmtsService(Uri)
Initializes a new instance of the WmtsService class with the specified URI.
Top
Properties
  NameDescription
Public propertyCustomParameters
Gets the dictionary of custom parameters to be sent with requests to this WMTS service.
Public propertyLoadError
Gets the Exception associated with the last load error.
Public propertyLoadStatus
Gets the load status.
Public propertyCode exampleServiceInfo
Returns the WMTS service information.
Public propertySource
Gets the Uri of this WMTS service.
Top
Methods
  NameDescription
Public methodCancelLoad
Cancel loading metadata for the object.
Public methodCode exampleLoadAsync
Load the metadata for the object asynchronously.
Public methodRetryLoadAsync
Load or retry loading metadata for the object asynchronously.
Top
Events
  NameDescription
Public eventLoaded
Event that is raised when the object is done loading.
Public eventLoadStatusChanged
Event that is raised when the LoadStatus property changes.
Top
Examples

Android

Example Name: WMTSLayer

Display a layer from a Web Map Tile Service.

Code example screen shot.

C#
// 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.

using Android.App;
using Android.OS;
using Android.Widget;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Ogc;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Collections.Generic;

namespace ArcGISRuntime.Samples.WMTSLayer
{
    [Activity (ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "WMTS layer",
        "Layers",
        "This sample demonstrates how to display a WMTS layer on a map via a Uri and WmtsLayerInfo.",
        "")]
    public class WMTSLayer : Activity
    {
        // Hold a reference to the map view
        private MapView _myMapView;

        // Button for loading layer using Uri constructor.
        private Button _uriButton;

        // Button for loading layer using WmtsService.
        private Button _infoButton;


        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Title = "WMTS layer";

            // Create the UI, setup the control references
            CreateLayout();

            // Load the map using Uri to the WMTS service.
            LoadWMTSLayer(true);
        }

        private void UriButton_Clicked(object sender, EventArgs e)
        {
            //Load the WMTS layer using Uri method.
            LoadWMTSLayer(true);

            // Disable and enable the appropriate buttons.
            _uriButton.Enabled = false;
            _infoButton.Enabled = true;
        }

        private void InfoButton_Clicked(object sender, EventArgs e)
        {
            //Load the WMTS layer using layer info.
            LoadWMTSLayer(false);

            // Disable and enable the appropriate buttons.
            _uriButton.Enabled = true;
            _infoButton.Enabled = false;
        }

        private async void LoadWMTSLayer(bool uriMode)
        {
            try
            {
                // Create a new map.
                Map myMap = new Map();

                // Get the basemap from the map.
                Basemap myBasemap = myMap.Basemap;

                // Get the layer collection for the base layers.
                LayerCollection myLayerCollection = myBasemap.BaseLayers;

                // Create an instance for the WMTS layer.
                WmtsLayer myWmtsLayer;

                // Define the Uri to the WMTS service.
                Uri wmtsUri = new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/WMTS");

                if (uriMode)
                {
                    // Create a WMTS layer using a Uri and provide an Id value.
                    myWmtsLayer = new WmtsLayer(wmtsUri, "WorldTimeZones");
                }
                else
                {
                    // Define a new instance of the WMTS service.
                    WmtsService myWmtsService = new WmtsService(wmtsUri);

                    // Load the WMTS service.
                    await myWmtsService.LoadAsync();

                    // Get the service information (i.e. metadata) about the WMTS service.
                    WmtsServiceInfo myWmtsServiceInfo = myWmtsService.ServiceInfo;

                    // Obtain the read only list of WMTS layer info objects.
                    IReadOnlyList<WmtsLayerInfo> myWmtsLayerInfos = myWmtsServiceInfo.LayerInfos;

                    // Create a WMTS layer using the first item in the read only list of WMTS layer info objects.
                    myWmtsLayer = new WmtsLayer(myWmtsLayerInfos[0]);
                }

                // Add the WMTS layer to the layer collection of the map.
                myLayerCollection.Add(myWmtsLayer);

                // Assign the map to the MapView.
                _myMapView.Map = myMap;
            }
            catch (Exception ex)
            {
                AlertDialog alert = new AlertDialog.Builder(this).Create();
                alert.SetMessage(ex.Message);
                alert.Show();
            }
        }

        private void CreateLayout()
        {
            // Create a new vertical layout for the app
            LinearLayout layout = new LinearLayout(this) { Orientation = Orientation.Vertical };

            // Create Button
            _uriButton = new Button(this)
            {
                Text = "WMTSLayer via Uri"
            };
            _uriButton.Click += UriButton_Clicked;
            _uriButton.Enabled = false;

            // Add Button to the layout
            layout.AddView(_uriButton);

            // Create Button
            _infoButton = new Button(this)
            {
                Text = "WMTSLayer via WmtsLayerInfo"
            };
            _infoButton.Click += InfoButton_Clicked;

            // Add Button to the layout
            layout.AddView(_infoButton);

            // Add the map view to the layout
            _myMapView = new MapView(this);
            layout.AddView(_myMapView);

            // Show the layout in the app
            SetContentView(layout);
        }
    }
}
Examples

Xamarin Forms Android

Example Name: WMTSLayer

Display a layer from a Web Map Tile Service.

Code example screen shot.

C#
// 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.

using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Ogc;
using System;
using System.Collections.Generic;
using Xamarin.Forms;

namespace ArcGISRuntime.Samples.WMTSLayer
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "WMTS layer",
        "Layers",
        "This sample demonstrates how to display a WMTS layer on a map via a Uri and WmtsLayerInfo.",
        "")]
    public partial class WMTSLayer : ContentPage
    {
        public WMTSLayer()
        {
            InitializeComponent();
            LoadWMTSLayer(true);
        }

        private void UriButton_Click(object sender, EventArgs e)
        {
            //Load the WMTS layer using Uri method.
            LoadWMTSLayer(true);

            // Disable and enable the appropriate buttons.
            UriButton.IsEnabled = false;
            InfoButton.IsEnabled = true;
        }

        private void InfoButton_Click(object sender, EventArgs e)
        {
            //Load the WMTS layer using layer info.
            LoadWMTSLayer(false);

            // Disable and enable the appropriate buttons.
            UriButton.IsEnabled = true;
            InfoButton.IsEnabled = false;
        }

        private async void LoadWMTSLayer(bool uriMode)
        {
            try
            {
                // Create a new map.
                Map myMap = new Map();

                // Get the basemap from the map.
                Basemap myBasemap = myMap.Basemap;

                // Get the layer collection for the base layers.
                LayerCollection myLayerCollection = myBasemap.BaseLayers;

                // Create an instance for the WMTS layer.
                WmtsLayer myWmtsLayer;

                // Define the Uri to the WMTS service.
                Uri wmtsUri = new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/WMTS");

                if (uriMode)
                {
                    // Create a WMTS layer using a Uri and provide an Id value.
                    myWmtsLayer = new WmtsLayer(wmtsUri, "WorldTimeZones");

                }
                else
                {
                    // Define a new instance of the WMTS service.
                    WmtsService myWmtsService = new WmtsService(wmtsUri);

                    // Load the WMTS service.
                    await myWmtsService.LoadAsync();

                    // Get the service information (i.e. metadata) about the WMTS service.
                    WmtsServiceInfo myWmtsServiceInfo = myWmtsService.ServiceInfo;

                    // Obtain the read only list of WMTS layer info objects.
                    IReadOnlyList<WmtsLayerInfo> myWmtsLayerInfos = myWmtsServiceInfo.LayerInfos;

                    // Create a WMTS layer using the first item in the read only list of WMTS layer info objects.
                    myWmtsLayer = new WmtsLayer(myWmtsLayerInfos[0]);
                }

                // Add the WMTS layer to the layer collection of the map.
                myLayerCollection.Add(myWmtsLayer);

                // Assign the map to the MapView.
                MyMapView.Map = myMap;

                // Zoom to appropriate level for iOS.
                await MyMapView.SetViewpointScaleAsync(300000000);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Sample error", ex.ToString(), "OK");
            }
        }
    }
}
XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
             xmlns:mapping="clr-namespace:Esri.ArcGISRuntime.Mapping;assembly=Esri.ArcGISRuntime"
             x:Class="ArcGISRuntime.Samples.WMTSLayer.WMTSLayer">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="60" />
            <RowDefinition Height="60" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Button x:Name="UriButton" Text="WMTSLayer via Uri" Clicked="UriButton_Click" Grid.Row="0" IsEnabled="false" />
        <Button x:Name="InfoButton" Text="WMTSLayer via WmtsLayerInfo" Clicked="InfoButton_Click" Grid.Row="1" />
        <esriUI:MapView x:Name="MyMapView" Grid.Row="2" />
    </Grid>
</ContentPage>
See Also
Additional Examples
Hyperlink to ExampleDescription
WMTSLayerDisplay a layer from a Web Map Tile Service.