Web Tiled Layer

Download Samples Repository

Description

Demonstrates adding a Web tiled layer to a Map in XAML, and changing layer properties in code behind.Also demonstrates including Attribution as per Terms of Use for the various layers.

"Desktop" "Store" "Phone" Available for Desktop, Store, Phone

Sample Code

<UserControl x:Class="ArcGISRuntime.Samples.Desktop.WebTiledLayerSample"
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
			 xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">

    <Grid>
        <esri:MapView x:Name="MyMapView">
            <esri:Map InitialViewpoint="-9840712.566, 5094828.570, -9684169.532, 5187877.291, 102100">
                <esri:WebTiledLayer ID="MyWebTiledLayer" TemplateUri="http://{subDomain}.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{level}/{row}/{col}"
                    SubDomains="server, services" CopyrightText="National Geographic, Esri, DeLorme, NAVTEQ, UNEP-WCMC, USGS, NASA, ESA, METI, NRCAN, GEBCO, NOAA, iPC" />
            </esri:Map>
        </esri:MapView>

        <Border BorderBrush="Black" BorderThickness="1" Background="White" HorizontalAlignment="Right" 
                VerticalAlignment="Top" Margin="30" Padding="20">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                </Grid.RowDefinitions>

                <TextBlock Text="Select Service:  " VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Column="0"/>

                <ComboBox x:Name="cboLayers" Width="250" Height="25" HorizontalAlignment="Left" 
                          Grid.Column="1" SelectionChanged="cboLayers_SelectionChanged" >
                    <ComboBoxItem  Content="Esri National Geographic"/>
                    <ComboBoxItem  Content="MapQuest"/>
                    <ComboBoxItem  Content="OpenCycleMap"/>
                    <ComboBoxItem  Content="Cloudmade Midnight Commander"/>
                    <ComboBoxItem  Content="Cloudmade Pale Dawn"/>
                    <ComboBoxItem  Content="MapBox Dark"/>
                    <ComboBoxItem  Content="Mapbox Terrain"/>
                    <ComboBoxItem  Content="Stamen Terrain"/>
                    <ComboBoxItem  Content="Stamen Watercolor"/>
                    <ComboBoxItem  Content="Stamen Toner"/>
                </ComboBox>
            </Grid>
        </Border>

        <!-- Attribution -->
        <ContentControl x:Name="Attribution"  HorizontalAlignment="Right" VerticalAlignment="Bottom"
            Margin="10" Visibility="Collapsed">
            <ContentControl.Resources>
                <!-- National Geographic-->
                <TextBlock x:Key="NatGeoAttribution" 
                           TextWrapping="Wrap" 
                           Background="White" 
                           Padding="4">
                    <Run Text="National Geographic, Esri, DeLorme, NAVTEQ, UNEP-WCMC, USGS, NASA, ESA, METI, NRCAN, GEBCO, NOAA, iPC"/>
                </TextBlock>
                <!-- MapQuest -->
                <TextBlock x:Key="MapQuestAttribution" 
                           TextWrapping="Wrap" 
                           Background="White" 
                           Padding="4">
                <Run Text="Tiles courtesy of "/>
                <Hyperlink NavigateUri="http://www.mapquest.com/" 
                           RequestNavigate="Hyperlink_RequestNavigate">MapQuest</Hyperlink>
                <Image Source="http://developer.mapquest.com/content/osm/mq_logo.png" 
                       Height="16" 
                       Width="16"/>
                </TextBlock>
                <!-- OpenStreetMap Cycle Map -->
                <TextBlock x:Key="OpenCycleMapAttribution" 
                           TextWrapping="Wrap" 
                           Background="White" 
                           Padding="4">
                <Run Text="OpenCycleMap.org - the "/>
                <Hyperlink NavigateUri="http://www.openstreetmap.org/#map=5/51.500/-0.100" 
                           RequestNavigate="Hyperlink_RequestNavigate">OpenStreetMap</Hyperlink>
                <Run Text=" Cycle Map"/>
                </TextBlock>
                <!-- Mapbox -->
                <TextBlock x:Key="MapboxAttribution" 
                           TextWrapping="Wrap" 
                           Background="White" 
                           Padding="4">
                <Run Text="© Mapbox © OpenStreetMap"/>
                <Hyperlink NavigateUri="https://www.mapbox.com/map-feedback/" 
                           RequestNavigate="Hyperlink_RequestNavigate">Improve this map</Hyperlink>
                </TextBlock>
                <!-- Stamen Toner Map -->
                <TextBlock x:Key="StamenTonerAttribution" 
                           TextWrapping="Wrap" 
                           Background="White" 
                           Padding="4">
                <Run Text="Map tiles by "/>
                <Hyperlink NavigateUri="http://stamen.com/" 
                           RequestNavigate="Hyperlink_RequestNavigate">Stamen Design</Hyperlink>
                <Run Text=", under "/>
                    <Hyperlink NavigateUri="http://creativecommons.org/licenses/by/3.0" 
                               RequestNavigate="Hyperlink_RequestNavigate">CC BY 3.0.</Hyperlink>
                <Run Text=" Data by "/>
                    <Hyperlink NavigateUri="http://openstreetmap.org/" 
                               RequestNavigate="Hyperlink_RequestNavigate">OpenStreetMap</Hyperlink>
                <Run Text=", under "/>
                    <Hyperlink NavigateUri="http://www.openstreetmap.org/copyright" 
                               RequestNavigate="Hyperlink_RequestNavigate">ODbl.</Hyperlink>
                </TextBlock>
                <!-- Stamen Other Map -->
                <TextBlock x:Key="StamenOtherAttribution" 
                           TextWrapping="Wrap" 
                           Background="White" 
                           Padding="4">
                <Run Text="Map tiles by "/>
                <Hyperlink NavigateUri="http://stamen.com/"
                           RequestNavigate="Hyperlink_RequestNavigate">Stamen Design</Hyperlink>
                <Run Text=", under "/>
                    <Hyperlink NavigateUri="http://creativecommons.org/licenses/by/3.0" 
                               RequestNavigate="Hyperlink_RequestNavigate">CC BY 3.0.</Hyperlink>
                <Run Text=" Data by "/>
                    <Hyperlink NavigateUri="http://openstreetmap.org/" 
                               RequestNavigate="Hyperlink_RequestNavigate">OpenStreetMap</Hyperlink>
                <Run Text=", under "/>
                    <Hyperlink NavigateUri="http://creativecommons.org/licenses/by-sa/3.0" 
                               RequestNavigate="Hyperlink_RequestNavigate">CC BY SA.</Hyperlink>
                </TextBlock>
            </ContentControl.Resources>
        </ContentControl>
    </Grid>
</UserControl>
using Esri.ArcGISRuntime.Layers;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;

namespace ArcGISRuntime.Samples.Desktop
{
    /// <summary>
    /// Demonstrates adding a Web tiled layer to a Map in XAML, and changing layer properties in code behind.
    /// Also demonstrates including Attribution as per Terms of Use for the various layers. 
    /// </summary>
    /// <title>Web Tiled Layer</title>
    /// <category>Layers</category>
    /// <subcategory>Tiled Layers</subcategory>
    public partial class WebTiledLayerSample : UserControl
    {

        public WebTiledLayerSample()
        {
            InitializeComponent();

            MyMapView.SpatialReferenceChanged += MyMapView_SpatialReferenceChanged;
        }

        void MyMapView_SpatialReferenceChanged(object sender, System.EventArgs e)
        {
            cboLayers.SelectedIndex = 0;
        }

        private void cboLayers_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (MyMapView.SpatialReference == null)
                return;

            MyMapView.Map.Layers.Remove("MyWebTiledLayer");

            WebTiledLayer webTiledLayer = new WebTiledLayer() { ID = "MyWebTiledLayer" };

            switch (cboLayers.SelectedIndex)
            {
                //Esri National Geographic
                case 0:
                    webTiledLayer.TemplateUri = "http://{subDomain}.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{level}/{row}/{col}";
                    webTiledLayer.SubDomains = new string[] { "server", "services" };
                    Attribution.Content = Attribution.Resources["NatGeoAttribution"];
                    Attribution.Visibility = Visibility.Visible;
                    break;
                //MapQuest
                case 1:
                    webTiledLayer.TemplateUri = "http://otile1.mqcdn.com/tiles/1.0.0/vx/map/{level}/{col}/{row}.jpg";
                    Attribution.Content = Attribution.Resources["MapQuestAttribution"];
                    Attribution.Visibility = Visibility.Visible;
                    break;
                //OpenCycleMap
                case 2:
                    webTiledLayer.TemplateUri = "http://{subDomain}.tile.opencyclemap.org/cycle/{level}/{col}/{row}.png";
                    webTiledLayer.SubDomains = new string[] { "a", "b", "c" };
                    Attribution.Content = Attribution.Resources["OpenCycleMapAttribution"];
                    Attribution.Visibility = Visibility.Visible;
                    break;
                //Cloudmade Midnight Commander
                case 3:
                    webTiledLayer.TemplateUri = "http://{subDomain}.tile.cloudmade.com/1a1b06b230af4efdbb989ea99e9841af/999/256/{level}/{col}/{row}.png";
                    webTiledLayer.SubDomains = new string[] { "a", "b", "c" };
                    Attribution.Visibility = Visibility.Collapsed; // No attribution info here, so keep dialog collapsed.
                    break;
                //Cloudmade Pale Dawn
                case 4:
                    webTiledLayer.TemplateUri = "http://{subDomain}.tile.cloudmade.com/1a1b06b230af4efdbb989ea99e9841af/998/256/{level}/{col}/{row}.png";
                    webTiledLayer.SubDomains = new string[] { "a", "b", "c" };
                    Attribution.Visibility = Visibility.Collapsed; // No attribution info here, so keep dialog collapsed.
                    break;
                //MapBox Dark
                case 5:
                    webTiledLayer.TemplateUri = "http://{subDomain}.tiles.mapbox.com/v3/examples.map-cnkhv76j/{level}/{col}/{row}.png";
                    webTiledLayer.SubDomains = new string[] { "a", "b", "c", "d" };
                    Attribution.Content = Attribution.Resources["MapboxAttribution"];
                    Attribution.Visibility = Visibility.Visible;
                    break;
                //Mapbox Terrain
                case 6:
                    webTiledLayer.TemplateUri = "http://{subDomain}.tiles.mapbox.com/v3/mapbox.mapbox-warden/{level}/{col}/{row}.png";
                    webTiledLayer.SubDomains = new string[] { "a", "b", "c", "d" };
                    Attribution.Content = Attribution.Resources["MapboxAttribution"];
                    Attribution.Visibility = Visibility.Visible;
                    break;
                //Stamen Terrain
                case 7:
                    webTiledLayer.TemplateUri = "http://{subDomain}.tile.stamen.com/terrain/{level}/{col}/{row}.jpg";
                    webTiledLayer.SubDomains = new string[] { "a", "b", "c", "d" };
                    Attribution.Content = Attribution.Resources["StamenOtherAttribution"];
                    Attribution.Visibility = Visibility.Visible;
                    break;
                //Stamen Watercolor
                case 8:
                    webTiledLayer.TemplateUri = "http://{subDomain}.tile.stamen.com/watercolor/{level}/{col}/{row}.jpg";
                    webTiledLayer.SubDomains = new string[] { "a", "b", "c", "d" };
                    Attribution.Content = Attribution.Resources["StamenOtherAttribution"];
                    Attribution.Visibility = Visibility.Visible;
                    break;
                //Stamen Toner
                case 9:
                    webTiledLayer.TemplateUri = "http://{subDomain}.tile.stamen.com/toner/{level}/{col}/{row}.png";
                    webTiledLayer.SubDomains = new string[] { "a", "b", "c", "d" };
                    Attribution.Content = Attribution.Resources["StamenTonerAttribution"];
                    Attribution.Visibility = Visibility.Visible;
                    break;
            }

            MyMapView.Map.Layers.Add(webTiledLayer);
        }

        private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
        {
            Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
            e.Handled = true;
        }
    }


}
Feedback on this topic?