This project is read-only.

DotSpatial and GMap.NET

Nov 18, 2012 at 4:48 AM

Someone has worked with GMap.NET into DotSpatial to load a satellite image in the DotSpatial.Controls.Map?

Nov 23, 2012 at 1:50 PM

There are to ways I am working with satellite image in my DotSpatial app.

1. Take the actual map window an show the same frame (+- GMap.NET has fixed zoom levels) in GMap.NET.

 Dim wmX As Double
            Dim wmY As Double
            Dim wmWidth As Double
            Dim wmHeight As Double

            With GMapControl1
                '.Visible = True
                '.Dock = DockStyle.Fill
                .MapProvider = GMapProviders.GoogleSatelliteMap
                '.MapScaleInfoEnabled = True
                .MinZoom = 2
                .MaxZoom = 17
                '.Zoom = 2
                .Manager.Mode = GMap.NET.AccessMode.ServerAndCache
                GMapControl1.DragButton = Windows.Forms.MouseButtons.None
            End With

            If Map1.ProjectionEsriString.Contains("Web_Mercator") Then
                WebMercatorToGeographic(Map1.ViewExtents.MinX, Map1.ViewExtents.MaxY, wmX, wmY)
                WebMercatorToGeographic(Map1.ViewExtents.Width, Map1.ViewExtents.Height, wmWidth, wmHeight)
                'MsgBox(wmX & " - " & wmY)
                Dim OSM_rec_WM As New GMap.NET.RectLatLng(wmY, wmX, wmWidth, wmHeight)

                Dim OSM_rec As New GMap.NET.RectLatLng(Map1.ViewExtents.MaxY, Map1.ViewExtents.MinX, Map1.ViewExtents.Width, Map1.ViewExtents.Height)
            End If
            currentMarker.Position = GMapControl1.Position

Private Sub WebMercatorToGeographic(ByVal mercatorX As Double, ByVal mercatorY As Double, ByRef lat As Double, ByRef lon As Double)
If ((mercatorX < -20037508.3427892) _
OrElse (mercatorX > 20037508.3427892)) Then
Throw New ArgumentException("Point does not fall within a valid range of the mercator projection.")
End If
Dim x As Double = mercatorX
Dim y As Double = mercatorY
Dim num3 As Double = (x / 6378137)
Dim num4 As Double = (num3 * 57.295779513082323)
Dim num5 As Double = Math.Floor(CType(((num4 + 180) / 360), Double))
Dim num6 As Double = (num4 - (num5 * 360))
Dim num7 As Double = (1.5707963267948966 - (2 * Math.Atan(Math.Exp((((1 * y) * -1) / 6378137)))))
lat = num6
lon = (num7 * 57.295779513082323)
End Sub

Private Sub GeographicToWebMercator(ByVal lat As Double, ByVal lon As Double, ByRef mercatorX As Double, ByRef mercatorY As Double)
If ((lat < -90) _
OrElse (lon > 90)) Then
Throw New ArgumentException("Point does not fall within a valid range of a geographic coordinate system.")
End If
Dim num As Double = (lat * 0.017453292519943295)
Dim x As Double = (6378137 * num)
Dim a As Double = (lon * 0.017453292519943295)
mercatorX = x
mercatorY = (3189068.5 * Math.Log(((1 + Math.Sin(a)) / (1 - Math.Sin(a)))))
End Sub


The second way is to use the DotSpatial.Controls.BruTileLayer from FObermaier. This works fine.

First download the source from

Open the project and compile with your actual DotSpatial version.

To use with google maps add this to his code:

 public static BruTileLayer CreateGoogleMapLayer()
            return new BruTileLayer(new GoogleTileSource(GoogleMapType.GoogleMap), new MemoryCache<byte[]>(100, 200));

        public static BruTileLayer CreateGoogleSatelliteLayer()
            return new BruTileLayer(new GoogleTileSource(GoogleMapType.GoogleSatellite), new MemoryCache<byte[]>(100, 200));

The result is this:

Nov 23, 2012 at 6:56 PM

thanks a lot...

I will try to do that you say...

Nov 23, 2012 at 6:56 PM

the link is broken....

Nov 23, 2012 at 9:03 PM

You can download from my Dropbox

Nov 24, 2012 at 11:24 PM

Thank you very much...

downloading it... 

I will study thank a lot...

Mar 21, 2013 at 5:04 AM
Everything works fine but in the case of "CreateGoogleSatelliteLayer" server is not found
Mar 21, 2013 at 7:31 AM
I tried it this moment and for me it works.

_btLayer = BruTileLayer.CreateGoogleSatelliteLayer
Mar 21, 2013 at 3:48 PM
add to DotSpatial.Controls.BruTileLayer the above lines of code to add the kind of google, even I added:

and all work well but not GoogleSatellite.

Mar 21, 2013 at 4:11 PM
Now i compiled with DS 1.4 here the 2 dlls you need.
This works actualy for me, if this dlls work for you too I send you the source again.


Mar 21, 2013 at 5:47 PM
Thomas thank you very much me your dll works great but I would like to have the project DotSpatial.Controls.BruTileLayer could you send it to me, since my project does not work well

sorry for me english... :D
Mar 23, 2013 at 7:13 AM
Hi Camiza,

You can download the source here.
It works with brutile.dll

Sep 23, 2013 at 4:08 PM
Mar 4, 2014 at 6:15 AM
Dear Camiza,
I am facing the following error as i am using dotspatial 1.0.
I just want to add OSM layer to map control. It will be nice if you help me.
"Error 2 Assembly 'DotSpatial.Controls.BruTileLayer, Version=, Culture=neutral, PublicKeyToken=bd5ca4b760779a42' uses 'BruTile, Version=, Culture=neutral, PublicKeyToken=00e75fd79e391f40' which has a higher version than referenced assembly 'BruTile, Version=, Culture=neutral, PublicKeyToken=00e75fd79e391f40' c:\Users\Director\Documents\Visual Studio 2010\Projects\PRSC Desktop GIS\PRSC Desktop GIS\bin\DotSpatial.Controls.BruTileLayer.dll PRSC Desktop GIS"