PGIs Download offline map SQLITE+WPF

Source: Internet
Author: User
Tags abs sqlite database



Project is ultra-high-resolution screen wall, real-time online loading PGIs map speed will be slow, resulting in a large number of screen left white. Then use the map cache, the map of this block in advance to all down, using the SQLite database to save. Retained.





// Task taskDown = new Task (DownTiles);
//taskDown.Start ();

private void DownTiles ()
        {
            double maxX = 138.796586;
            double maxY = 24.371022;
            double minX = 138.447725;
            double minY = 24.086215;
            double X0 = -180;
            double Y0 = 90;
            string tempUrl = "";
            HttpWebRequest req = null;
            Stream stream = null;

            int bufferLen = 1024 * 1024;
            int actual;
            byte [] buffer = new byte [bufferLen];

            for (int i = 9; i <21; i ++) // Level
            {
                int cmin = Math.Abs (Convert.ToInt32 (Math.Floor ((X0-minX) / (256 * MapMethods.GetResoulution (i)))));
                int cmax = Math.Abs (Convert.ToInt32 (Math.Floor ((X0-maxX) / (256 * MapMethods.GetResoulution (i)))));
                int rmin = Math.Abs (Convert.ToInt32 (Math.Floor ((Y0-maxY) / (256 * MapMethods.GetResoulution (i)))));
                int rmax = Math.Abs (Convert.ToInt32 (Math.Floor ((Y0-minY) / (256 * MapMethods.GetResoulution (i)))));
                for (int r = rmin; r <rmax; r ++) // loop line
                {
                    for (int c = cmin; c <cmax; c ++) // loop column
                    {
                        //Thread.Sleep(100);
                        tempUrl = GetTileUrl (i, r, c);
                        req = (HttpWebRequest) WebRequest.Create (tempUrl);
                        stream = req.GetResponse (). GetResponseStream ();



                        MemoryStream memoryStream = new MemoryStream ();
                        
                        while ((actual = stream.Read (buffer, 0, bufferLen))> 0)
                        {
                            memoryStream.Write (buffer, 0, actual);
                        }
                        memoryStream.Position = 0;

                        SaveTile (i, r, c, StreamToBytes2 (memoryStream));
                        
                        
                    }
                }
            }
        }

        private byte [] StreamToBytes2 (MemoryStream input)
        {
            byte [] bytes = new byte [input.Length];
            input.Read (bytes, 0, bytes.Length);
            return bytes;
        } 





PGIs Download offline map SQLITE+WPF


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.