//StreamWriter watch; #region 百度瓦片地图个性化下载 /// <summary> /// 百度瓦片地图个性化下载(暂时不使用) /// </summary> /// <returns></returns> //public WebApiResult<string> BaiduMapTileDownload(BaiduMapTileDownloadRequest Request) //{ // var log = new TaskLogEntity() { GUID = Request.GUID, Name = "百度瓦片下载", Type = "瓦片下载", Description = "BaiduMapTileDownload1", Status = "进行中", Parameter = JsonHelper.ToJson(Request) }; // //操作日志 // new Log<BaiduMapTileDownloadRequest>(log); // try // { // string URLtextBox = GetDownloadUrl(Request.List_TreeNode); // //检查URL地址栏 // if (URLtextBox == "") // { // //MessageBox.Show(this, "URL地址为空,请检查!", "提示"); // return new WebApiResult<string>() { success = 2, msg = "URL地址为空,请检查!" }; // } // //确定要下载的坐标范围信息,起始坐标为左下角,终点坐标为右上角 // double startcoord_x = Request.LefttextBox; // double startcoord_y = Request.BottomtextBox; // double endcoord_x = Request.RighttextBox; // double endcoord_y = Request.UptextBox; // LatLngPoint startcoord, endcoord; // //if (startcoord_x > 0 && startcoord_x < endcoord_x && endcoord_x < 180 && startcoord_y > 0 && startcoord_y < endcoord_x && endcoord_y < 90) // { // startcoord = new LatLngPoint(startcoord_y, startcoord_x); // endcoord = new LatLngPoint(endcoord_y, endcoord_x); // } // //else // //{ // // return new WebApiResult<string>() { success = 2, msg = "输入坐标值不正确,请检查!" }; // //} // //检查下载层级是否勾选 // if (Request.LevelList.Length == 0) // { // return new WebApiResult<string>() { success = 2, msg = "下载地图层级未选择,请检查!" }; // } // //获取要下载的地图层级 // foreach (int Level in Request.LevelList) // { // //int z = Level; // Tuple<int, int, int, int> BoundTup = GetTileBound(startcoord, endcoord, Level); // for (int i = BoundTup.Item1; i <= BoundTup.Item3; i++) // { // for (int j = BoundTup.Item2; j <= BoundTup.Item4; j++) // { // try // { // String link = String.Format(URLtextBox, Math.Abs(i + j) % 3, i, j, Level); // String localpath = Request.SavePathText + String.Format("\\{0}\\{1}\\", Level, i); // String filename = String.Format("{0}.png", j); // //判断文件是否存在,若存在,直接下载下一个文件 // if (File.Exists(localpath + filename)) continue; // //下载文件 // String downloadedfile = ""; // do // { // downloadedfile = DownloadFile(link, localpath, filename); // Thread.Sleep(100); // try // { // Image img = Image.FromFile(localpath + filename); // } // catch (Exception) // { // File.Delete(localpath + filename); // downloadedfile = ""; // } // } while (downloadedfile == ""); // } // catch (Exception ex) // { // log.Status = "错误"; // log.ErrorMsg = ex.ToString(); // log.ErrorDate = DateTime.Now.ToString(); // new Log<BaiduMapTileDownloadRequest>(log); // return null; // } // } // } // } // log.Status = "已完成"; // log.CompleteTime = DateTime.Now.ToString(); // new Log<BaiduMapTileDownloadRequest>(log); // } // catch (Exception ex) // { // log.Status = "错误"; // log.ErrorMsg = ex.ToString(); // log.ErrorDate = DateTime.Now.ToString(); // new Log<BaiduMapTileDownloadRequest>(log); // } // return null; //} /// <summary> /// 百度瓦片地图个性化下载(当前使用) /// </summary> /// <returns></returns> public WebApiResult <string> BaiduMapTileDownload1(BaiduMapTileDownloadRequest Request) { //watch = new StreamWriter(new FileStream(System.AppDomain.CurrentDomain.BaseDirectory + "\\App_Data\\ThreadLog.txt", FileMode.Create)); this.countdown = new CountdownEvent(Request.TaskCount); this.request = Request; UpdateLastLoc(Request.GUID); log = new TaskLogEntity() { GUID = Request.GUID, Name = Request.TName, Type = "百度瓦片下载", Description = "BaiduMapTileDownload1", Status = "进行中", Parameter = JsonHelper.ToJson(Request), SavePath = request.SavePathText }; //操作日志 new Log <BaiduMapTileDownloadRequest>(log); try { if (Request.LayerStr == "sate") { this.URLtextBox = "https://ss{0}.bdstatic.com/8bo_dTSlR1gBo1vgoIiO_jowehsv/starpic/?qt=satepc&u=x={1};y={2};z={3};v=009;type=sate"; } else { this.URLtextBox = "http://api{0}.map.bdimg.com/customimage/tile?&x={1}&y={2}&z={3}&scale=1&ak=8d6c8b8f3749aed6b1aff3aad6f40e37&" + Request.LayerStr; //GetDownloadUrl(Request.List_TreeNode); //检查URL地址栏http://api{0}.map.bdimg.com/customimage/tile?&x={1}&y={2}&z={3}&scale=1&ak=8d6c8b8f3749aed6b1aff3aad6f40e37&styles=t:background|e:all|v:off,t:poi|e:all|v:off,t:administrative|e:all|v:off } if (URLtextBox == "") { //MessageBox.Show(this, "URL地址为空,请检查!", "提示"); return(new WebApiResult <string>() { success = 2, msg = "URL地址为空,请检查!" }); } //确定要下载的坐标范围信息,起始坐标为左下角,终点坐标为右上角 double startcoord_x = Request.LefttextBox; double startcoord_y = Request.BottomtextBox; double endcoord_x = Request.RighttextBox; double endcoord_y = Request.UptextBox; //if (startcoord_x > 0 && startcoord_x < endcoord_x && endcoord_x < 180 && startcoord_y > 0 && startcoord_y < endcoord_y && endcoord_y < 90) //{ this.startcoord = new LatLngPoint(startcoord_y, startcoord_x); this.endcoord = new LatLngPoint(endcoord_y, endcoord_x); //} //else //{ // return new WebApiResult<string>() { success = 2, msg = "输入坐标值不正确,请检查!" }; //} //检查下载层级是否勾选 if (Request.LevelList.Length == 0) { return(new WebApiResult <string>() { success = 2, msg = "下载地图层级未选择,请检查!" }); } threadlog = new ThreadTaskLogEntity() { GUID = Request.GUID, TaskLog_GUID = Request.GUID, Status = "进行中", TStatus = 1, Total = 0, TName = Request.TName, IsPaused = false, Parameter = JsonHelper.ToJson(Request), URL = Request.URL }; //计算Total并更新 foreach (int Level in Request.LevelList) { Tuple <int, int, int, int> BoundTup = GetTileBound(startcoord, endcoord, Level); threadlog.Total += (BoundTup.Item3 - BoundTup.Item1 + 1) * (BoundTup.Item4 - BoundTup.Item2 + 1); } log.Count = threadlog.Total; new Log <BaiduMapTileDownloadRequest>(log); new Log <BaiduMapTileDownloadRequest>(threadlog); interval = new double[] { (endcoord.Lat - startcoord.Lat) / Request.TaskCount, (endcoord.Lng - startcoord.Lng) / Request.TaskCount }; Thread[] t = new Thread[Request.TaskCount]; for (int num = 0; num < Request.TaskCount; num++) { try { t[num] = new Thread(new ParameterizedThreadStart(run)) { Name = "Thread " + num.ToString() }; t[num].Start(num); } catch (Exception ex) { threadlog.Status = "错误"; threadlog.ErrorMsg = ex.ToString(); threadlog.TStatus = 3; new Log <BaiduMapTileDownloadRequest>(threadlog); log.Status = "错误"; log.ErrorMsg = ex.ToString(); log.ErrorDate = DateTime.Now.ToString(); //操作日志 new Log <BaiduMapTileDownloadRequest>(log); return(new WebApiResult <string>() { success = 0, msg = ex.ToString() }); } } countdown.Wait(); //watch.Close(); for (int num = 0; num < Request.TaskCount; num++) { t[num].Abort(); } lock (obj) { if (!Log <BaiduMapTileDownloadRequest> .GetThreadLogEntity(this.request.GUID).IsPaused) { log.Status = "已完成"; log.CompleteTime = DateTime.Now.ToString(); log.Current = log.Count; threadlog.Status = "已完成"; threadlog.TStatus = 2; threadlog.Current = threadlog.Total; threadlog.Current_loc = List2Str(current_loc); //操作日志 new Log <BaiduMapTileDownloadRequest>(threadlog); new Log <BaiduMapTileDownloadRequest>(log); return(new WebApiResult <string>() { success = 1, msg = "百度瓦片下载完成!" }); } } } catch (Exception ex) { log.Status = "错误"; log.ErrorMsg = ex.ToString(); log.ErrorDate = DateTime.Now.ToString(); new Log <BaiduMapTileDownloadRequest>(log); return(new WebApiResult <string>() { success = 0, msg = ex.ToString() }); } return(null); }
/// <summary> /// 百度瓦片地图个性化下载 /// </summary> /// <param name="request"></param> /// <returns></returns> public WebApiResult <string> Any(BaiduMapTileDownloadRequest request) { BMapTileDownloadService service = new BMapTileDownloadService(); return(service.BaiduMapTileDownload1(request)); }