/// <summary> /// 墨卡托转经纬度 /// </summary> /// <param name="mercator"></param> /// <returns></returns> public static MapPoint Mercator2LonLat(MapPoint mercator) { MapPoint lonLat = new MapPoint(); double x = mercator.X / 20037508.34 * 180; double y = mercator.Y / 20037508.34 * 180; y = 180 / Math.PI * (2 * Math.Atan(Math.Exp(y * Math.PI / 180)) - Math.PI / 2); lonLat.X = x; lonLat.Y = y; return lonLat; }
/// <summary> /// 经纬度转墨卡托 /// </summary> /// <param name="lonLat"></param> /// <returns></returns> public static MapPoint LonLat2Mercator(MapPoint lonLat) { MapPoint mercator = new MapPoint(); double x = lonLat.X * 20037508.34 / 180; double y = Math.Log(Math.Tan((90 + lonLat.Y) * Math.PI / 360)) / (Math.PI / 180); y = y * 20037508.34 / 180; mercator.X = x; mercator.Y = y; return mercator; }
/// <summary> /// 下载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDownload_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtSaveFolder.Text)) { MessageBox.Show("保存路径不能为空"); btnSaveFolder.Focus(); return; } if (!Util.Validation.IsNumber(txtMinLongitude.Text) || !Util.Validation.IsNumber(txtMaxLongitude.Text) || !Util.Validation.IsNumber(txtMinLatitude.Text) || !Util.Validation.IsNumber(txtMaxLatitude.Text)) { MessageBox.Show("坐标格式不正确"); return; } PureProjection proj = mapControl.MapProvider.Projection; int zoom = Convert.ToInt32(mapControl.Zoom); GSize minOfTiles = proj.GetTileMatrixMinXY(zoom); GSize maxOfTiles = proj.GetTileMatrixMaxXY(zoom); PointLatLng position = new PointLatLng(double.Parse(txtMinLatitude.Text), double.Parse(txtMinLongitude.Text)); PointLatLng position1 = new PointLatLng(double.Parse(txtMaxLatitude.Text), double.Parse(txtMaxLongitude.Text)); Core.MapPoint minPoint = new Core.MapPoint() { X = position.Lng, Y = position.Lat }; Core.MapPoint maxPoint = new Core.MapPoint() { X = position1.Lng, Y = position1.Lat }; Core.Log.Clear(logFile); downloader = new Core.Provider.GoogleChinaMapDownloader( new Core.Extent(minPoint.X, minPoint.Y, maxPoint.X, maxPoint.Y), int.Parse(txtMinZoom.Text), int.Parse(txtMaxZoom.Text) ) { SavePath = txtSaveFolder.Text }; downloader.TileDownloadCompleted += TileDownloadCompleted; downloader.DownloadCompleted += DownloadCompleted; downloader.BeginDownload(); statusbar_progress.Visible = true; statusbar_progress.Maximum = 100; statusbar_status.Text = "下载中......"; }