- VS2010
- .NET 4.0
- WPF
- WCF
- GitHub (Source code can be found at https://github.com/aaronmell/DotNetFish/
Now then, lets look at what is needed to get Gmap.net Running
- Grab the source code of the latest stable branch from the Gmap.Net repository.
- Load the source code into visual studio and build the project
- You can skip the first two steps, and just grab the binaries, but those don't come with examples, which you'll probably want.
- Add the Gmap.Net.Core.Dll and the Gmap.Net.WindowsForms.dll to your references. (Make sure that if you copy the refrences to your project directory, that the System.Data.Sqlite.dll is in the same directory as the two Gmap Dll's
- Add the Gmap.WindowsForms.dll to your toolbox, so you can have access to the Gmap map control
// config map MainMap.Position = new PointLatLng(35.2276723549358, -97.22351074); MainMap.MapType = MapType.GoogleMap; MainMap.MinZoom = 1; MainMap.MaxZoom = 17; MainMap.Zoom = 10;
That should get a basic map up and running on your form. Now for my application I need to do the following
- Allow the user to select a lake with a selection tool
- After the user has selected a lake, build an image from the tileset.
- Do some processing of the image. (Turn the image black and White)
Here is the code I am using to get the Tile Coordinates
PureProjection prj = null; int maxZoom; int zoom = 15; GMaps.Instance.AdjustProjection(type, ref prj, out maxZoom); GMaps.Instance.Mode = AccessMode.ServerOnly; GMaps.Instance.ImageProxy = new WindowsFormsImageProxy(); //This line converts the LatLng to the Proper TileXY given the level of zoom. //Remember that each level of zoom has a different TileXY coordinate for a given Lat and Lng prj.FromPixelToTileXY(prj.FromLatLngToPixel(p.Lat, p.Lng, zoom))
Once we know which tiles we need, it will be very simple to get those tiles and stitch them together into the image.
Here is the code that does the stitching.
using (Bitmap bmp = new Bitmap(tilesWide * 256, tilesHigh * 256)) { for (int x = 0; x < tilesWide; x++) { for (int y = 0; y < tilesHigh; y++) { using (Graphics gfx = Graphics.FromImage(bmp)) { Exception ex; WindowsFormsImage tile = GMaps.Instance.GetImageFrom(type, new GPoint(startTile.X + x, startTile.Y - y), zoom, out ex) as WindowsFormsImage; if (ex != null) { e.Cancel = true; return; } else if (tile != null) { using (tile) { gfx.DrawImage(tile.Img, x * 256, (tilesHigh - y - 1) * 256); } } } } }
No comments:
Post a Comment