コード例 #1
0
ファイル: MainForm.cs プロジェクト: skarlath/spaceapps_MIAMI
        public MainForm()
        {
            InitializeComponent();

             if(!DesignMode)
             {
            try
            {
               System.Net.IPHostEntry e = System.Net.Dns.GetHostEntry("www.bing.com");
            }
            catch
            {
               mapControl.Manager.Mode = AccessMode.CacheOnly;
               MessageBox.Show("No internet connection avaible, going to CacheOnly mode.", "GMap.NET - CloudsDemo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            mapControl.MapProvider = GMapProviders.BingSatelliteMap;
            mapControl.OnMapZoomChanged += new MapZoomChanged(mapControl_OnMapZoomChanged);

            mainOverlay = new GMapOverlay("top");
            mapControl.Overlays.Add(mainOverlay);

            clouds = new GMapImage(gtl);
            clouds.Image = Properties.Resources.USOverlay;
            mainOverlay.Markers.Add(clouds);
             }
        }
コード例 #2
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                //string conn = @"Database=mapcache-841;Data Source=127.0.0.1;pooling=false;Charset=utf8;port=3306;User Id=root;password=luxx";
                using (MySqlConnection cnGet = new MySqlConnection(this.connString))
                {
                    cnGet.Open();
                    int mapType = this.exportParameter.MapProvider.DbId;
                    for (int mapZoom = exportParameter.MinZoom; mapZoom <= exportParameter.MaxZoom; ++mapZoom)
                    {
                        int progress = Convert.ToInt32((mapZoom - exportParameter.MinZoom + 1) * 100 / (exportParameter.MaxZoom - exportParameter.MinZoom + 1));
                        worker.ReportProgress(progress, new TileExportEventArgs(mapZoom));
                        using (MySqlCommand cmdFetch = cnGet.CreateCommand())
                        {
                            cmdFetch.CommandText = String.Format("SELECT * FROM `gmapnetcache` where Type={0} and Zoom={1}", mapType, mapZoom);
                            cmdFetch.Prepare();
                            using (MySqlDataReader odata = cmdFetch.ExecuteReader())
                            {
                                while (odata.Read())
                                {
                                    try
                                    {
                                        int type = odata.GetInt32("Type");
                                        if (type == mapType)
                                        {
                                            int zoom = odata.GetInt32("Zoom");
                                            if (zoom == mapZoom)
                                            {
                                                long   x     = odata.GetInt64("X");
                                                long   y     = odata.GetInt64("Y");
                                                GPoint point = new GPoint(x, y);

                                                byte[] imageByte = new byte[odata.GetBytes(odata.GetOrdinal("Tile"), 0, null, 0, int.MaxValue)];
                                                odata.GetBytes(odata.GetOrdinal("Tile"), 0, imageByte, 0, imageByte.Length);

                                                GMapImage    image        = new GMapImage();
                                                MemoryStream memoryStream = new MemoryStream(imageByte);
                                                image.Img  = System.Drawing.Image.FromStream(memoryStream);
                                                image.Data = memoryStream;
                                                WriteTileToDisk(image, zoom, point);
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        log.Error(ex);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
コード例 #3
0
 public void addLayers()
 {
     GMapImage layer;
     foreach (Bitmap b in Layers)
     {
         layer = new GMapImage(ViewArea.LocationTopLeft);
         layer.Image = b;
         mainOverlay.Markers.Clear();
         mainOverlay.Markers.Add(layer);
     }
 }
コード例 #4
0
ファイル: MockMap.cs プロジェクト: zhenkaining/K_map
        public override PureImage GetTileImage(GPoint pos, int zoom)
        {
            var __PureImage = new GMapImage
            {
                Data = new MemoryStream(_默认数据, 0, _默认数据.Length, false, true)
                {
                    Position = 0
                }
            };

            __PureImage.Img = Image.FromStream(__PureImage.Data);
            return(__PureImage);
        }
コード例 #5
0
 private bool CacheTiles(int zoom, GPoint p, GMapProvider provider, Graphics gfx, GPoint topLeftPx)
 {
     foreach (var pr in provider.Overlays)
     {
         Exception ex;
         GMapImage tile = GMaps.Instance.GetImageFrom(pr, p, zoom, out ex) as GMapImage;
         if (tile != null)
         {
             using (tile)
             {
                 long x = p.X * this.provider.Projection.TileSize.Width - topLeftPx.X;
                 long y = p.Y * this.provider.Projection.TileSize.Width - topLeftPx.Y;
                 gfx.DrawImage(tile.Img, x, y, this.provider.Projection.TileSize.Width, this.provider.Projection.TileSize.Height);
             }
         }
         else
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #6
0
        void getImage()
        {
            GMapProvider   type = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance;
            PureProjection prj  = type.Projection;

            //GMap.NET.GMaps.Instance.GetImageFrom();

            DateTime startimage = DateTime.Now;

            if (!area.IsEmpty)
            {
                try
                {
                    //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 = type; // GMaps.Instance.GetAllLayersOfType(type);

                    // max zoom level
                    zoom = 20;

                    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);

                    // zoom based on pixel density
                    while (pxDelta.X > 2000)
                    {
                        zoom--;

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

                    // get tiles - bg
                    core.Provider = type;
                    core.Position = LocationCenter;
                    core.Zoom     = zoom;

                    // get type list at new zoom level
                    List <GPoint> tileArea = prj.GetAreaTileList(area, zoom, 0);

                    //this.Invalidate();

                    Console.WriteLine((startimage - DateTime.Now).TotalMilliseconds);

                    int padding = 0;
                    {
                        using (
                            Bitmap bmpDestination = new Bitmap((int)pxDelta.X + padding * 2, (int)pxDelta.Y + padding * 2)
                            )
                        {
                            Console.WriteLine((startimage - DateTime.Now).TotalMilliseconds);
                            using (Graphics gfx = Graphics.FromImage(bmpDestination))
                            {
                                Console.WriteLine((startimage - DateTime.Now).TotalMilliseconds);
                                gfx.CompositingMode    = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                                gfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
                                gfx.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;

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

                                    foreach (var tp in type.Overlays)
                                    {
                                        Console.WriteLine((startimage - DateTime.Now).TotalMilliseconds);
                                        GMapImage tile =
                                            ((PureImageCache)Maps.MyImageCache.Instance).GetImageFromCache(type.DbId, p,
                                                                                                           zoom) as GMapImage;

                                        //GMapImage tile = GMaps.Instance.GetImageFrom(tp, p, zoom, out ex) as GMapImage;
                                        //GMapImage tile = type.GetTileImage(p, zoom) as GMapImage;
                                        //tile.Img.Save(zoom + "-" + p.X + "-" + p.Y + ".bmp");

                                        if (tile != null)
                                        {
                                            using (tile)
                                            {
                                                long x = p.X * prj.TileSize.Width - topLeftPx.X + padding;
                                                long y = p.Y * prj.TileSize.Width - topLeftPx.Y + padding;
                                                {
                                                    Console.WriteLine((startimage - DateTime.Now).TotalMilliseconds);
                                                    gfx.DrawImage(tile.Img, x, y, prj.TileSize.Width,
                                                                  prj.TileSize.Height);
                                                    Console.WriteLine((startimage - DateTime.Now).TotalMilliseconds);
                                                }
                                            }
                                        }
                                        else
                                        {
                                        }
                                    }
                                }
                            }

                            Console.WriteLine((startimage - DateTime.Now).TotalMilliseconds);
                            _terrain = new Bitmap(bmpDestination, 1024 * 2, 1024 * 2);

                            // _terrain.Save(zoom +"-map.bmp");


                            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 (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }
コード例 #7
0
ファイル: OpenGLtest.cs プロジェクト: xxc/MissionPlanner
        void getImage()
        {
            GMapProvider   type = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance;
            PureProjection prj  = type.Projection;

            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 = type;// 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);

                    DateTime startimage = DateTime.Now;

                    int padding = 0;
                    {
                        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 (GMapProvider tp in types)
                                    {
                                        GMapImage tile = type.GetTileImage(p, zoom) as GMapImage;
                                        if (tile != null)
                                        {
                                            using (tile)
                                            {
                                                long x = p.X * prj.TileSize.Width - topLeftPx.X + padding;
                                                long y = p.Y * prj.TileSize.Width - topLeftPx.Y + padding;
                                                {
                                                    gfx.DrawImage(tile.Img, x, y, prj.TileSize.Width, prj.TileSize.Height);
                                                }
                                            }
                                        }
                                    }

                                    if ((DateTime.Now - startimage).TotalMilliseconds > 200)
                                    {
                                        break;
                                    }
                                }
                            }
                            _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);
                        }
                    }
                    if ((DateTime.Now - startimage).TotalMilliseconds > 200)
                    {
                        zoom--;
                    }
                    else
                    {
                        //zoom++;
                    }
                }
                catch { }
            }
        }
コード例 #8
0
        static Bitmap GetMap(RectLatLng area)
        {
            GMapProvider   type = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance;
            PureProjection prj  = type.Projection;

            int zoom = 16;

            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);

            // zoom based on pixel density
            while (pxDelta.X > 2000)
            {
                zoom--;

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

            // get type list at new zoom level
            List <GPoint> tileArea = prj.GetAreaTileList(area, zoom, 0);

            int padding = 10;

            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 type.Overlays)
                        {
                            Exception ex;
                            GMapImage tile = GMaps.Instance.GetImageFrom(tp, p, zoom, out ex) as GMapImage;

                            if (tile != null)
                            {
                                using (tile)
                                {
                                    long x = p.X * prj.TileSize.Width - topLeftPx.X + padding;
                                    long y = p.Y * prj.TileSize.Width - topLeftPx.Y + padding;
                                    {
                                        gfx.DrawImage(tile.Img, x, y, prj.TileSize.Width, prj.TileSize.Height);
                                    }
                                }
                            }
                        }
                    }
                }

                return(bmpDestination);
            }
        }