Hi Xamlmax,
Could you, please, clarify what does "dummy map source" means? The empty provider don't show any map tiles. It just provides spatial reference (projection) for other operations (i.e. show KML or ESRI shape files). If you need to show map tiles offline then you should create your own tile server which will run on the localhost.
It is quite simple to create tile server on localhost when you have images which can be identified by the zoom level and (x,y) position of the tile. All that you need to do is put your tiles in a separate directory in the C:\inetpub\wwwroot folder. So if you have the OpenStreet map tiles organized in a way similar to the structure on the OpenStreet servers (zoom\x_pos\y_pos.png) then you can create tile server on localhost in a couple of steps:
1. Create new folder like "os_images" in the "C:\inetpub\wwwroot" folder.
2. Copy whole structure of the OpenStreet images to this new folder.
Now you can create new map tile source and map provider which will access images from this folder:
/// <summary>
/// Tile source which read map tiles from the file system.
/// </summary>
public
class
LocalhostTileSource : TiledMapSource
{
private
string
tileUriFormat;
/// <summary>
/// Initializes a new instance of the FileSystemTileSource class.
/// </summary>
/// <param name="tileUriFormat">Format string to access tiles on the localhost.</param>
public
LocalhostTileSource(
string
tileUriFormat)
:
base
(1, 20, 256, 256)
{
this
.tileUriFormat = tileUriFormat;
}
/// <summary>
/// Initialize provider.
/// </summary>
public
override
void
Initialize()
{
// Raise provider intialized event.
this
.RaiseIntializeCompleted();
}
/// <summary>
/// Gets the image URI.
/// </summary>
/// <param name="tileLevel">Tile level.</param>
/// <param name="tilePositionX">Tile X.</param>
/// <param name="tilePositionY">Tile Y.</param>
/// <returns>URI of image.</returns>
protected
override
Uri GetTile(
int
tileLevel,
int
tilePositionX,
int
tilePositionY)
{
int
zoomLevel = ConvertTileToZoomLevel(tileLevel);
string
url =
this
.tileUriFormat.Replace(
"{zoom}"
, zoomLevel.ToString(CultureInfo.InvariantCulture));
url = url.Replace(
"{x}"
, tilePositionX.ToString(CultureInfo.InvariantCulture));
url = url.Replace(
"{y}"
, tilePositionY.ToString(CultureInfo.InvariantCulture));
return
new
Uri(url);
}
}
/// <summary>
/// Map provider which read map tiles from the file system.
/// </summary>
public
class
LocalhostProvider : TiledProvider
{
/// <summary>
/// Initializes a new instance of the LocalhostProvider class.
/// </summary>
/// <param name="tileUriFormat">Format string to access tiles on the localhost.</param>
public
LocalhostProvider(
string
tileUriFormat)
:
base
()
{
LocalhostTileSource source =
new
LocalhostTileSource(tileUriFormat);
this
.MapSources.Add(source.UniqueId, source);
}
/// <summary>
/// Returns the SpatialReference for the map provider.
/// </summary>
public
override
ISpatialReference SpatialReference
{
get
{
return
new
MercatorProjection();
}
}
}
Now you can use new map provider in your application:
The
ConvertTileToZoomLevel method is inherited from TiledMapSource class so you don't need to bother about its implementation.
Kind regards,
Andrey Murzov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>