Esempio n. 1
0
        static private PointF Sx(PointGeo a, double[] b)
        {
            double c = b[0] + b[1] * Math.Abs(a.lng);                                                                                                      // c: 13387435.419690479
            double d = Math.Abs(a.lat) / b[9];
            double e = b[2] + b[3] * d + b[4] * d * d + b[5] * d * d * d + b[6] * d * d * d * d + b[7] * d * d * d * d * d + b[8] * d * d * d * d * d * d; // d: 3682405.2310994808
            double f = c * (0 > a.lng ? -1 : 1);                                                                                                           // c: 13387435.419690479
            double g = e * (0 > a.lat ? -1 : 1);                                                                                                           // d: 3682405.2310994808

            return(new PointF(f, g));
        }
Esempio n. 2
0
        public void execute(String baseDir, PointGeo leftBottomPoint, PointGeo rightTopPoint, List <int> zoomArray, int threadCnt, int mapType, String mapStyle)
        {
            mBaseDir = baseDir;
            if (!String.IsNullOrEmpty(mapStyle))
            {
                this.mapStyle      = mapStyle;
                this.isCustomStyle = true;
            }

            if (mBaseDir.EndsWith("\\"))
            {
                mBaseMapTileDir = mBaseDir + MAP_TILE_DIR;
            }
            else
            {
                mBaseMapTileDir = mBaseDir + "\\" + MAP_TILE_DIR;
            }

            // 经纬度 缩放级别
            mLeftBottomPoint = leftBottomPoint;
            mrightTopPoint   = rightTopPoint;
            mZoomArray       = zoomArray;
            mThreadCnt       = threadCnt;
            mThreads         = new List <Thread>();
            mMapType         = mapType;

            mErrorCnt       = 0;
            mTotalTile      = 0;
            mDownloadedTile = 0;

            mStop = false;

            //创建目录
            Util.createDir(mBaseMapTileDir);

            //计算瓦片数
            mTotalTile = getTileTotal();

            //初始化任务
            initTask(0);
            //开始下载
            for (int i = 0; i < mThreadCnt; i++)
            {
                //ThreadPool.QueueUserWorkItem(new WaitCallback(TaskProc), i);

                Thread t = new Thread(new ParameterizedThreadStart(TaskProc));
                mThreads.Add(t);
                t.Start(i);
            }
        }
Esempio n. 3
0
        static public PointF lngLatToPoint(double lng, double lat)
        {
            PointGeo pt = new PointGeo();

            pt.lng = MapTool.ft(lng, -180, 180);  // lng: 120.26007
            pt.lat = MapTool.lt(lat, -74, 74);    // lat: 31.554487


            //b = new F(a.lng, a.lat);            // b: lat: 31.554487  lng: 120.26007

            double[] c = null;
            //北纬
            for (int d = 0; d < MapTool.Wm.Length; d++)
            {
                if (pt.lat >= MapTool.Wm[d])
                {
                    // Wm: [75, 60, 45, 30, 15, 0] (常量)
                    c = MapTool.bv[d];                 // bv: 10*6的二维数组(常量)
                    break;
                }
            }

            //南纬
            if (c == null || c.Length <= 0)
            {
                for (int d = MapTool.Wm.Length - 1; 0 <= d; d--)
                {
                    if (pt.lat <= -MapTool.Wm[d])
                    {
                        c = MapTool.bv[d];
                        break;
                    }
                }
            }

            PointF fpt = MapTool.Sx(pt, c); //a:  lat: 31.554487   lng: 120.26007,   c = this.bv[d];  (d = 3)

            return(new PointF(Convert.ToDouble(fpt.x.ToString("0.00")), Convert.ToDouble(fpt.y.ToString("0.00"))));
            //DecimalFormat df = new DecimalFormat("#.00");
            //return new PointF(Double.parseDouble(df.format(fpt.x)), Double.parseDouble(df.format(fpt.y))); // a: lat: 3682405.23  lng: 13387435.42
        }
Esempio n. 4
0
        private void button_start_Click(object sender, EventArgs e)
        {
            if (this.textBox_left_bottom_lng.Text == "" ||
                this.textBox_left_bottom_lat.Text == "" ||
                this.textBox_right_top_lng.Text == "" ||
                this.textBox_right_top_lat.Text == "")
            {
                MessageBox.Show("请输入经纬度,或者划定要下载的区域");
                return;
            }

            //经纬度范围
            double   lng             = Convert.ToDouble(this.textBox_left_bottom_lng.Text);
            double   lat             = Convert.ToDouble(this.textBox_left_bottom_lat.Text);
            PointGeo leftBottomPoint = new PointGeo(lng, lat); // 左下角

            lng = Convert.ToDouble(this.textBox_right_top_lng.Text);
            lat = Convert.ToDouble(this.textBox_right_top_lat.Text);
            PointGeo rightTopPoint = new PointGeo(lng, lat); // 右上角

            if (leftBottomPoint.lng == rightTopPoint.lng ||
                leftBottomPoint.lat == rightTopPoint.lat)
            {
                MessageBox.Show("两个经度或者纬度不能一样");
                return;
            }

            //放大级别
            List <int> zoomArray = new List <int>();

            for (int i = 0; i < mCheckBoxZoom.Length; i++)
            {
                if (mCheckBoxZoom[i].Checked)
                {
                    zoomArray.Add(i + 1);
                }
            }

            if (zoomArray.Count == 0)
            {
                MessageBox.Show("请选择放大级别");
                return;
            }

            //下载内容
            int mapType = 0;

            if (this.radio_street_map.Checked) //街道图
            {
                mapType = 0;
            }
            else if (this.radio_satellite_map.Checked) //卫星图
            {
                mapType = 1;
            }
            else
            {
                mapType = 0;
            }

            //线程数
            int threadCnt = Convert.ToInt16(numericUpDown_downlaod_thread_cnt.Value);

            //保存路径
            String savePath = this.textBox_maptile_dir.Text;

            if (savePath == null || savePath.Length == 0)
            {
                MessageBox.Show("请设置保存目录");
                return;
            }

            this.toolStripStatusLabel_download_status.Text = "开始下载";

            mDownloader.execute(savePath, leftBottomPoint, rightTopPoint, zoomArray, threadCnt, mapType);

            this.button_start.Enabled = false;
            this.button_pause.Enabled = true;
        }