Custom Map Provider

2 posts, 0 answers
  1. Esther
    Esther avatar
    13 posts
    Member since:
    Jun 2010

    Posted 20 Dec 2010 Link to this post

    Good evening,
    I´m trying to build my own map provider. I have my tiles for an specific country.
    How could I project my tiles to their proper coordinates?
    Provider is working but with wrong coordinates. Below is my code.
    Thank you very much,

    Imports System.Collections.Generic
    Imports System.IO
    Imports System.Linq
    Imports System.Text
    Imports Telerik.Windows.Controls.Map

    Public Class NavteqTilesProvider
        Inherits MapProviderBase
        Private Const TILE_SIZE As Integer = 256
        Private initialized As Boolean
        Private m_tileLocation As String

        ''' <summary>
        ''' Initializes a new instance of the FileSystemProvider class.
        ''' </summary>
        ''' <param name="mode">Map mode.</param>
        ''' <param name="labelVisible">Is labels visible.</param>
        Public Sub New(ByVal tileLocation As String)
            MyBase.New(MapMode.Road, True)

            Me.m_tileLocation = tileLocation

        End Sub

        ''' <summary>
        ''' Initializes a new instance of the FileSystemProvider class.
        ''' </summary>
        Public Sub New()
        End Sub

        ''' <summary>
        ''' Gets or sets location of the map tiles.
        ''' </summary>
        Public Property TileLocation() As String
                Return Me.m_tileLocation
            End Get

            Set(ByVal value As String)
                Me.m_tileLocation = value
            End Set
        End Property

        ' ''' <summary>
        ' ''' Gets the IsInitialized property.
        ' ''' Indicates that the provider is initialized.
        ' ''' </summary>

        ''' <summary>
        ''' Gets value which indicates whether labels are supported by the map provider.
        ''' </summary>
        Public Overrides ReadOnly Property IsLabelSupported() As Boolean
                Return False
            End Get
        End Property

        ''' <summary>
        ''' Returns the SpatialReference for the map provider.
        ''' </summary>
        Public Overrides ReadOnly Property SpatialReference() As ISpatialReference
                Return New MercatorProjection()

            End Get
        End Property

        ''' <summary>
        ''' Gets list of the supported map modes.
        ''' </summary>
        ''' <returns>List of the supported map modes.</returns>
        Public Overrides ReadOnly Property SupportedModes() As IEnumerable(Of MapMode)


                Dim list As New List(Of MapMode)

                Return list

            End Get
        End Property

        ''' <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>
        Public Overrides Function GetTile(ByVal tileLevel As Integer, ByVal tilePositionX As Integer, ByVal tilePositionY As Integer) As Uri
            Dim zoomLevel As Integer = ConvertTileToZoomLevel(tileLevel)

            Dim tileFileName As String = String.Format("map_{0}_{1}_{2}.png", tilePositionX, tilePositionY, zoomLevel)
            tileFileName = Path.Combine(Me.TileLocation, tileFileName)

            If File.Exists(tileFileName) Then
                Return New Uri(tileFileName)
                Return Nothing
            End If
        End Function

        ''' <summary>
        ''' Initialize provider.
        ''' </summary>
        Public Overrides Sub Initialize()
            Me.initialized = MyBase.IsInitialized
        End Sub

        ''' <summary>
        ''' Gets value which indicates whether given mode is supported by map provider.
        ''' </summary>
        ''' <param name="mode">Map mode to check.</param>
        ''' <returns>true if given mode is supported. Otherwise - false.</returns>
        Public Overrides Function IsModeSupported(ByVal mode As MapMode) As Boolean
            Return (mode = MapMode.Road)
        End Function

        ''' <summary>
        ''' MapModeChanged handler.
        ''' </summary>
        Protected Overrides Sub OnMapModeChanged(ByVal oldMode As MapMode, ByVal newMode As MapMode)
            If Not Me.IsSuspended Then
            End If
        End Sub
    End Class

  2. Andrey
    Andrey avatar
    1681 posts

    Posted 23 Dec 2010 Link to this post

    Hello Esther,

    Currently the custom map provider for the map control should keep the following restrictions:
    - Each tile should have a pixel size as 256 x 256
    - Tiles should cover a world map with a grid of the following ranges of geographical coordinates:
       -85 to 85 latitude,
       -180 to 180 longitude.
    - Tiles should cover a world map according to deep zoom concept
    The width and height of whole map in tiles is calculated as 2 ^ zoom level. For example the zoom level 1 should contain 4 tiles. Zoom level 2 should contain 16 etc.
    I.e. each tile has the fixed geographical location according to its zoom level and x-y position.For example when the zoom level is 1 (tileLevel is 9) and tilePositionX is 0 and tilePositionY is 0 then the real geographic location of the tile is 85, -180 (lat, lon).

    Of course the custom map provider can provide some region only, but the geographic location of tiles should correspond to the rules above.

    We are planning to support a custom provider which uses tiles for certain geographic region only, but this feature will be implemented in future releases.

    Andrey Murzov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF
Back to Top