Visual Basic (Declaration) | |
---|---|
Public MustInherit Class TiledMapServiceLayer Inherits TiledLayer |
C# | |
---|---|
public abstract class TiledMapServiceLayer : TiledLayer |
Implement this class if you want to create a custom tiled layer where the cached images can be referenced by a URL.
As a minimum this layer must implement TiledMapServiceLayer.GetTileUrl and set the Layer.FullExtent to the extent of the layer. The FullExtent should include a default SpatialReference for the layer. The map uses this to determine when to draw the layer. Lastly the TileInfo should be set with tile information about the tiles in the map service.
Example: Custom Tiled Layer using OpenStreetMap tiles:
// Please see the OpenStreetMap terms of use before using this layer.
public class OpenStreetMapLayer : TiledMapServiceLayer
{
private static string[] subDomains = { "a", "b", "c" };
private const string baseUrl = "http://{0}.tile.openstreetmap.org/{1}/{2}/{3}.png";
public override void Initialize()
{
this.FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892)
{
SpatialReference = new SpatialReference(102113)
};
// This layer's spatial reference
this.SpatialReference = new SpatialReference(102113);
// Set up tile information. Each tile is 256x256px, 19 levels.
this.TileInfo = new TileInfo()
{
Height = 256,
Width = 256,
Origin = new MapPoint(-cornerCoordinate, cornerCoordinate) { SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(WKID) },
Lods = new Lod[19]
};
// Set the resolutions for each level. Each level is half the resolution of the previous one.
double resolution = cornerCoordinate * 2 / 256;
for (int i = 0; i < TileInfo.Lods.Length; i++)
{
TileInfo.Lods[i] = new Lod() { Resolution = resolution };
resolution /= 2;
}
// Call base initialize to raise the initialization event
base.Initialize();
}
public override string GetTileUrl(int level, int row, int col)
{
// Select a subdomain based on level/row/column so that it will always
// be the same for a specific tile. Multiple subdomains allows the user
// to load more tiles simultanously. To take advantage of the browser cache
// the following expression also makes sure that a specific tile will always
// hit the same subdomain.
string subdomain = subDomains[(level + col + row) % subDomains.Length];
return string.Format(baseUrl, subdomain, level, col, row);
}
}
System.Object
System.Windows.DependencyObject
ESRI.ArcGIS.Client.Layer
ESRI.ArcGIS.Client.TiledLayer
ESRI.ArcGIS.Client.TiledMapServiceLayer
ESRI.ArcGIS.Client.ArcGISTiledMapServiceLayer
ESRI.ArcGIS.Client.Bing.TileLayer
ESRI.ArcGIS.Client.Toolkit.DataSources.OpenStreetMapLayer
ESRI.ArcGIS.Client.Toolkit.DataSources.WmtsLayer
Target Platforms: Windows Vista, Windows 7