This sample demonstrates the use of the TileServer list for an OpenStreetMapLayer. The TileServer property can be used to: 1) Reference the url to any tiled map service that adheres to the OpenStreetMap standard. 2) Provide a list of servers from which to retrieve tiles for the same tiled map service. This example shows how to use the TileServer list in XAML and code behind, and display different OpenStreetMap tiled services, such as MapQuest, Cloudmade, or Cyclemap. Note, the OpenStreetMap.Style property references some standard OpenStreetMap tiled services. It will be ignored if the TileServer list is populated.
using System.Windows;
using System.Windows.Controls;
using ESRI.ArcGIS.Client.Toolkit.DataSources;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace ArcGISWPFSDK
{
publicpartialclass OSMTileServers : UserControl
{
OpenStreetMapLayer osmLayer;
public OSMTileServers()
{
InitializeComponent();
osmLayer = MyMap.Layers["OSMLayer"] as OpenStreetMapLayer;
}
privatevoid RadioButton_Click(object sender, RoutedEventArgs e)
{
string layerTypeTag = (string)((RadioButton)sender).Tag;
OpenStreetMapLayer.TileServerList newTileServers;
switch (layerTypeTag)
{
case"MapQuest":
//Collection is replaced
newTileServers = new OpenStreetMapLayer.TileServerList();
newTileServers.Add("http://otile1.mqcdn.com/tiles/1.0.0/osm");
newTileServers.Add("http://otile2.mqcdn.com/tiles/1.0.0/osm");
newTileServers.Add("http://otile3.mqcdn.com/tiles/1.0.0/osm");
osmLayer.TileServers = newTileServers;
break;
case"Cloudmade":
//Collection is replaced
newTileServers = new OpenStreetMapLayer.TileServerList();
newTileServers.Add("http://a.tile.cloudmade.com/fd093e52f0965d46bb1c6c6281022199/3/256");
newTileServers.Add("http://b.tile.cloudmade.com/fd093e52f0965d46bb1c6c6281022199/3/256");
newTileServers.Add("http://c.tile.cloudmade.com/fd093e52f0965d46bb1c6c6281022199/3/256");
osmLayer.TileServers = newTileServers;
break;
case"CycleMap":
//same collection is pre-populated and hence needs to be refreshed.
osmLayer.TileServers.Clear();
osmLayer.TileServers.Add("http://a.tile.opencyclemap.org/cycle");
osmLayer.TileServers.Add("http://b.tile.opencyclemap.org/cycle");
osmLayer.TileServers.Add("http://c.tile.opencyclemap.org/cycle");
osmLayer.Refresh();
break;
}
}
}
}
Imports System.Windows.Controls
Imports System.Windows
Imports ESRI.ArcGIS.Client.Toolkit.DataSources
Imports ESRI.ArcGIS.Client
Namespace ArcGISWPFSDK
PartialPublicClass OSMTileServers
Inherits UserControl
Private osmLayer As OpenStreetMapLayer
PublicSubNew()
InitializeComponent()
osmLayer = TryCast(MyMap.Layers("OSMLayer"), OpenStreetMapLayer)
EndSubPrivateSub RadioButton_Click(ByVal sender AsObject, ByVal e As RoutedEventArgs)
Dim layerTypeTag AsString = CStr((CType(sender, RadioButton)).Tag)
Dim newTileServers As OpenStreetMapLayer.TileServerList
SelectCase layerTypeTag
Case"MapQuest"'Collection is replaced
newTileServers = New OpenStreetMapLayer.TileServerList()
newTileServers.Add("http://otile1.mqcdn.com/tiles/1.0.0/osm")
newTileServers.Add("http://otile2.mqcdn.com/tiles/1.0.0/osm")
newTileServers.Add("http://otile3.mqcdn.com/tiles/1.0.0/osm")
osmLayer.TileServers = newTileServers
Case"Cloudmade"'Collection is replaced
newTileServers = New OpenStreetMapLayer.TileServerList()
newTileServers.Add("http://a.tile.cloudmade.com/fd093e52f0965d46bb1c6c6281022199/3/256")
newTileServers.Add("http://b.tile.cloudmade.com/fd093e52f0965d46bb1c6c6281022199/3/256")
newTileServers.Add("http://c.tile.cloudmade.com/fd093e52f0965d46bb1c6c6281022199/3/256")
osmLayer.TileServers = newTileServers
Case"CycleMap"'same collection is pre-populated and hence needs to be refreshed.
osmLayer.TileServers.Clear()
osmLayer.TileServers.Add("http://a.tile.opencyclemap.org/cycle")
osmLayer.TileServers.Add("http://b.tile.opencyclemap.org/cycle")
osmLayer.TileServers.Add("http://c.tile.opencyclemap.org/cycle")
osmLayer.Refresh()
EndSelectEndSubEndClassEndNamespace