Yandex Traffic. For Russian users of this wonderful component.

Topics: Windows Forms
Apr 19, 2012 at 6:21 AM

'Yandex Traffic. For Russian users of this wonderful component. 
'Thanks to radioman and all the other selfless helpers!
 Private Sub DrawProbki()
            If ToolStripButton11.Checked Then  ' if check for show traffic
                Dim ret As PureImage = Nothing
                Dim MyTiles As List(Of GMap.NET.GPoint) = GMap.NET.MapProviders.GMapProviders.YandexMap.Projection.GetAreaTileList(MainMap.ViewArea, CInt(MainMap.Zoom), 0) 'MainMap.MapProvider.Projection.GetAreaTileList(MainMap.ViewArea, CInt(MainMap.Zoom), 0) 'MainMap.Projection.GetAreaTileList(area, i, 0)

                Dim tm As String = DateTimeToUnixTimestamp(Now.AddHours(-4)).ToString
                For i As Integer = 0 To MyTiles.Count - 1
                    Dim MyPoint As GPoint = GMap.NET.MapProviders.GMapProviders.YandexMap.Projection.FromTileXYToPixel(MyTiles(i)) 'MainMap.MapProvider.Projection.FromTileXYToPixel(MyTiles(i))
                        ret = MainMap.MapProvider.GetTileImageUsingHttp("" + (MyTiles(i).X).ToString + "&y=" + (MyTiles(i).Y).ToString + "&z=" + CInt(MainMap.Zoom).ToString + "&tm=" + tm)
                        Dim MyImage As Image = Image.FromStream(ret.Data)

                        If Not MyImage Is Nothing Then
                            Dim MarkerProbki As New MyGMap.NET.WindowsForms.Markers.GMapMarker_YandexProbki(GMap.NET.MapProviders.GMapProviders.YandexMap.Projection.FromPixelToLatLng(MyPoint, CInt(MainMap.Zoom)), MyImage)
                            MarkerProbki.IsHitTestVisible = False
                        End If
                    Catch ex As Exception
                        Debug.Print(i.ToString + " - " + MyTiles.Count.ToString + ". ERROR: " + ex.Message)
                    End Try

                ToolStripButton12.Enabled = True
                ToolStripButton12.Enabled = False
            End If
        Catch ex As Exception
            Debug.Print("Yandex trafic ERROR: " + ex.Message)
        End Try

    End Sub
    Public Function DateTimeToUnixTimestamp(ByVal _DateTime As DateTime) As Long
        Dim _UnixTimeSpan As TimeSpan = (_DateTime.Subtract(New DateTime(1970, 1, 1, 0, 0, 0)))
        Return CLng(Fix(_UnixTimeSpan.TotalSeconds))
    End Function
'===============Custom Marker for show traffic =======================================
Imports GMap.NET.WindowsForms
Imports GMap.NET

Namespace MyGMap.NET.WindowsForms.Markers
    Public Class GMapMarker_YandexProbki
        Inherits GMapMarker

        Private _image As System.Drawing.Image
        Private _point As PointLatLng

        Sub New(ByVal iPoint As PointLatLng, image As System.Drawing.Image)
            _point = iPoint
            _image = image
        End Sub

        Public Overloads Overrides Sub OnRender(ByVal g As Graphics)
                g.DrawImageUnscaled(_image, System.Convert.ToInt32(LocalPosition.X), System.Convert.ToInt32(LocalPosition.Y))
            Catch ex As Exception

            End Try

        End Sub

        Public Sub ChangeImage()
                MyBase.Size = New Drawing.Size(_image.Size.Width, _image.Size.Height)
            Catch ex As Exception

            End Try

            'MyBase.Offset = New Drawing.Point((_image.Size.Width), _image.Size.Height)
        End Sub
    End Class

End Namespace

Apr 19, 2012 at 1:01 PM

..actualy you need to create custom provider with traffic layer, i'll add it, thanks for info

Apr 19, 2012 at 1:18 PM

Let me learn to work with Yandex routes. This will need to add exactly.

P.S. Radioman, а по русски ты понимаешь?

Apr 19, 2012 at 1:25 PM

my english is much better ;}

Apr 19, 2012 at 1:29 PM
radioman wrote:

..actualy you need to create custom provider with traffic layer, i'll add it, thanks for info

All right. Google will help us communicate. ;)
custom provider - will be stored in the cache. Do not see the point, these changes in traffic jams - you need to update. I have this working or button or automatic timed out. This is the first. And the second. Now I place the transparent layer plugs into any type of map or satellite.

Apr 19, 2012 at 1:33 PM

hm, thats true

Apr 19, 2012 at 2:14 PM

Now, if gmap would such a thing as a sub-provider for traffic jams, road events and other services from Google, Yandex, and others, which will be superimposed on the tile selected primary provider, it would be very cool. Can anyone else tell us how to obtain such additional information and then you'll do this sort of sub-provider.

 Thanks. Best regards, Igor