This is a migrated thread and some comments may be shown as answers.

Custom Map Provider

1 Answer 105 Views
Map
This is a migrated thread and some comments may be shown as answers.
Esther
Top achievements
Rank 1
Esther asked on 20 Dec 2010, 04:36 PM
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,
Esther

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()
        Me.New(Nothing)
    End Sub

    ''' <summary>
    ''' Gets or sets location of the map tiles.
    ''' </summary>
    Public Property TileLocation() As String
        Get
            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
        Get
            Return False
        End Get
    End Property

    ''' <summary>
    ''' Returns the SpatialReference for the map provider.
    ''' </summary>
    Public Overrides ReadOnly Property SpatialReference() As ISpatialReference
        Get
            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)

        Get

            Dim list As New List(Of MapMode)
            list.Add(MapMode.Road)

            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)
        Else
            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
            Me.Initialize()
        End If
    End Sub
End Class

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 23 Dec 2010, 09:12 AM
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.


Regards,
Andrey Murzov
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
Tags
Map
Asked by
Esther
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or