Exemplo n.º 1
0
        void getImage()
        {
            MapType        type = MapType.GoogleSatellite;
            PureProjection prj  = null;
            int            maxZoom;

            GMaps.Instance.AdjustProjection(type, ref prj, out maxZoom);
            int zoom = 11; // 12

            if (!area.IsEmpty)
            {
                try
                {
                    List <GPoint> tileArea = prj.GetAreaTileList(area, zoom, 0);
                    //string bigImage = zoom + "-" + type + "-vilnius.png";

                    //Console.WriteLine("Preparing: " + bigImage);
                    //Console.WriteLine("Zoom: " + zoom);
                    //Console.WriteLine("Type: " + type.ToString());
                    //Console.WriteLine("Area: " + area);

                    var types = GMaps.Instance.GetAllLayersOfType(type);

                    // current area
                    GPoint topLeftPx     = prj.FromLatLngToPixel(area.LocationTopLeft, zoom);
                    GPoint rightButtomPx = prj.FromLatLngToPixel(area.Bottom, area.Right, zoom);
                    GPoint pxDelta       = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y);

                    int padding = 0;
                    {
                        using (Bitmap bmpDestination = new Bitmap(pxDelta.X + padding * 2, pxDelta.Y + padding * 2))
                        {
                            using (Graphics gfx = Graphics.FromImage(bmpDestination))
                            {
                                gfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

                                // get tiles & combine into one
                                foreach (var p in tileArea)
                                {
                                    //Console.WriteLine("Downloading[" + p + "]: " + tileArea.IndexOf(p) + " of " + tileArea.Count);

                                    foreach (MapType tp in types)
                                    {
                                        Exception         ex;
                                        WindowsFormsImage tile = GMaps.Instance.GetImageFrom(tp, p, zoom, out ex) as WindowsFormsImage;
                                        if (tile != null)
                                        {
                                            using (tile)
                                            {
                                                int x = p.X * prj.TileSize.Width - topLeftPx.X + padding;
                                                int y = p.Y * prj.TileSize.Width - topLeftPx.Y + padding;
                                                {
                                                    gfx.DrawImage(tile.Img, x, y, prj.TileSize.Width, prj.TileSize.Height);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            _terrain = new Bitmap(bmpDestination, 512, 512);


                            GL.BindTexture(TextureTarget.Texture2D, texture);

                            BitmapData data = _terrain.LockBits(new System.Drawing.Rectangle(0, 0, _terrain.Width, _terrain.Height),
                                                                ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                            //Console.WriteLine("w {0} h {1}",data.Width, data.Height);

                            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0,
                                          OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

                            _terrain.UnlockBits(data);

                            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                        }
                    }
                }
                catch { }
            }
        }
Exemplo n.º 2
0
        void bg_DoWork(object sender, DoWorkEventArgs e)
        {
            MapInfo info = e.Argument as MapInfo;

            if (!info.Area.IsEmpty)
            {
                string bigImage = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + Path.DirectorySeparatorChar + "GMap-" + DateTime.Now.Ticks + ".png";
                e.Result = bigImage;

                List <MapType> types = GMaps.Instance.GetAllLayersOfType(info.Type);

                // current area
                GMap.NET.Point topLeftPx     = info.Projection.FromLatLngToPixel(info.Area.LocationTopLeft, info.Zoom);
                GMap.NET.Point rightButtomPx = info.Projection.FromLatLngToPixel(info.Area.Bottom, info.Area.Right, info.Zoom);
                GMap.NET.Point pxDelta       = new GMap.NET.Point(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y);

                int padding = 22;
                {
                    using (Bitmap bmpDestination = new Bitmap(pxDelta.X + padding * 2, pxDelta.Y + padding * 2))
                    {
                        using (Graphics gfx = Graphics.FromImage(bmpDestination))
                        {
                            gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;

                            int i = 0;

                            // get tiles & combine into one
                            lock (tileArea)
                            {
                                foreach (var p in tileArea)
                                {
                                    if (bg.CancellationPending)
                                    {
                                        e.Cancel = true;
                                        return;
                                    }

                                    int pc = (int)(((double)++i / tileArea.Count) * 100);
                                    bg.ReportProgress(pc, p);

                                    foreach (MapType tp in types)
                                    {
                                        WindowsFormsImage tile = GMaps.Instance.GetImageFrom(tp, p, info.Zoom) as WindowsFormsImage;
                                        if (tile != null)
                                        {
                                            using (tile)
                                            {
                                                int x = p.X * info.Projection.TileSize.Width - topLeftPx.X + padding;
                                                int y = p.Y * info.Projection.TileSize.Width - topLeftPx.Y + padding;
                                                {
                                                    gfx.DrawImage(tile.Img, x, y, info.Projection.TileSize.Width, info.Projection.TileSize.Height);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        // draw info
                        {
                            System.Drawing.Rectangle rect = new System.Drawing.Rectangle();
                            {
                                rect.Location = new System.Drawing.Point(padding, padding);
                                rect.Size     = new System.Drawing.Size(pxDelta.X, pxDelta.Y);
                            }
                            using (Font f = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold))
                                using (Graphics gfx = Graphics.FromImage(bmpDestination))
                                {
                                    gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;

                                    // draw bounds & coordinates
                                    using (Pen p = new Pen(Brushes.Red, 3))
                                    {
                                        p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;

                                        gfx.DrawRectangle(p, rect);

                                        string topleft = info.Area.LocationTopLeft.ToString();
                                        SizeF  s       = gfx.MeasureString(topleft, f);

                                        gfx.DrawString(topleft, f, p.Brush, rect.X + s.Height / 2, rect.Y + s.Height / 2);

                                        string rightBottom = new PointLatLng(info.Area.Bottom, info.Area.Right).ToString();
                                        SizeF  s2          = gfx.MeasureString(rightBottom, f);

                                        gfx.DrawString(rightBottom, f, p.Brush, rect.Right - s2.Width - s2.Height / 2, rect.Bottom - s2.Height - s2.Height / 2);
                                    }

                                    // draw scale
                                    using (Pen p = new Pen(Brushes.Blue, 1))
                                    {
                                        double rez    = info.Projection.GetGroundResolution(info.Zoom, info.Area.Bottom);
                                        int    px100  = (int)(100.0 / rez);  // 100 meters
                                        int    px1000 = (int)(1000.0 / rez); // 1km

                                        gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px1000, 10);
                                        gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px100, 10);

                                        string leftBottom = "scale: 100m | 1Km";
                                        SizeF  s          = gfx.MeasureString(leftBottom, f);
                                        gfx.DrawString(leftBottom, f, p.Brush, rect.X + 10, rect.Bottom - s.Height - 20);
                                    }
                                }
                        }

                        bmpDestination.Save(bigImage, ImageFormat.Png);
                    }
                }
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            GMaps.Instance.UseMemoryCache = false;
            GMaps.Instance.Mode           = AccessMode.ServerAndCache;

            GMapProvider.TileImageProxy = WindowsFormsImageProxy.Instance;

            GMapProvider provider = GMapProviders.BingMap;

            provider.OnInitialized();

            int zoom = 12;

            RectLatLng area = RectLatLng.FromLTRB(25.013809204101563, 54.832138557519563, 25.506134033203125, 54.615623046071839);

            if (!area.IsEmpty)
            {
                try
                {
                    List <GPoint> tileArea = provider.Projection.GetAreaTileList(area, zoom, 0);
                    string        bigImage = zoom + "-" + provider + "-vilnius.png";

                    Console.WriteLine("Preparing: " + bigImage);
                    Console.WriteLine("Zoom: " + zoom);
                    Console.WriteLine("Type: " + provider.ToString());
                    Console.WriteLine("Area: " + area);

                    // current area
                    GPoint topLeftPx     = provider.Projection.FromLatLngToPixel(area.LocationTopLeft, zoom);
                    GPoint rightButtomPx = provider.Projection.FromLatLngToPixel(area.Bottom, area.Right, zoom);
                    GPoint pxDelta       = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y);

                    int padding = 22;
                    {
                        using (Bitmap bmpDestination = new Bitmap((int)(pxDelta.X + padding * 2), (int)(pxDelta.Y + padding * 2)))
                        {
                            using (Graphics gfx = Graphics.FromImage(bmpDestination))
                            {
                                gfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

                                // get tiles & combine into one
                                foreach (var p in tileArea)
                                {
                                    Console.WriteLine("Downloading[" + p + "]: " + tileArea.IndexOf(p) + " of " + tileArea.Count);

                                    foreach (var tp in provider.Overlays)
                                    {
                                        Exception         ex;
                                        WindowsFormsImage tile = GMaps.Instance.GetImageFrom(tp, p, zoom, out ex) as WindowsFormsImage;
                                        if (tile != null)
                                        {
                                            using (tile)
                                            {
                                                long x = p.X * provider.Projection.TileSize.Width - topLeftPx.X + padding;
                                                long y = p.Y * provider.Projection.TileSize.Width - topLeftPx.Y + padding;
                                                {
                                                    gfx.DrawImage(tile.Img, x, y, provider.Projection.TileSize.Width, provider.Projection.TileSize.Height);
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            // draw info
                            {
                                System.Drawing.Rectangle rect = new System.Drawing.Rectangle();
                                {
                                    rect.Location = new System.Drawing.Point(padding, padding);
                                    rect.Size     = new System.Drawing.Size((int)pxDelta.X, (int)pxDelta.Y);
                                }
                                using (Font f = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold))
                                    using (Graphics gfx = Graphics.FromImage(bmpDestination))
                                    {
                                        // draw bounds & coordinates
                                        using (Pen p = new Pen(Brushes.Red, 3))
                                        {
                                            p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;

                                            gfx.DrawRectangle(p, rect);

                                            string topleft = area.LocationTopLeft.ToString();
                                            SizeF  s       = gfx.MeasureString(topleft, f);

                                            gfx.DrawString(topleft, f, p.Brush, rect.X + s.Height / 2, rect.Y + s.Height / 2);

                                            string rightBottom = new PointLatLng(area.Bottom, area.Right).ToString();
                                            SizeF  s2          = gfx.MeasureString(rightBottom, f);

                                            gfx.DrawString(rightBottom, f, p.Brush, rect.Right - s2.Width - s2.Height / 2, rect.Bottom - s2.Height - s2.Height / 2);
                                        }

                                        // draw scale
                                        using (Pen p = new Pen(Brushes.Blue, 1))
                                        {
                                            double rez    = provider.Projection.GetGroundResolution(zoom, area.Bottom);
                                            int    px100  = (int)(100.0 / rez);  // 100 meters
                                            int    px1000 = (int)(1000.0 / rez); // 1km

                                            gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px1000, 10);
                                            gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px100, 10);

                                            string leftBottom = "scale: 100m | 1Km";
                                            SizeF  s          = gfx.MeasureString(leftBottom, f);
                                            gfx.DrawString(leftBottom, f, p.Brush, rect.X + 10, rect.Bottom - s.Height - 20);
                                        }
                                    }
                            }

                            bmpDestination.Save(bigImage, System.Drawing.Imaging.ImageFormat.Png);
                        }
                    }

                    // ok, lets see what we get
                    {
                        Console.WriteLine("Done! Starting Image: " + bigImage);

                        Process.Start(bigImage);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex.ToString());

                    Console.ReadLine();
                }
            }
        }