Exemple #1
0
        /// <summary>
        /// 更新下载记录状态
        /// </summary>
        /// <param name="downloadItem"></param>
        public static void UpdateDownloading(DownloadZoom downloadItem)
        {
            lock (lockInstance)
            {
                MapServerDownloader downloader = downloadItem.Downloader;
                XElement            eleUpdate;

                eleUpdate       = configDoc.Root.Element("downloadedTileCount");
                eleUpdate.Value = downloader.DownloadedTileCount.ToString();

                eleUpdate       = configDoc.Root.Element("curDownloadZoom");
                eleUpdate.Value = downloadItem.Zoom.ToString();

                XElement ele = configDoc.Root.Element("items").Elements()
                               .Where(e => e.Attribute("zoom").Value.Trim() == downloadItem.Zoom.ToString())
                               .FirstOrDefault();

                if (ele == null)
                {
                    return;
                }

                eleUpdate       = ele.Element("curTileX");
                eleUpdate.Value = downloadItem.CurTileX.ToString();

                eleUpdate       = ele.Element("curTileY");
                eleUpdate.Value = downloadItem.CurTileY.ToString();

                eleUpdate       = ele.Element("downloadedTileCount");
                eleUpdate.Value = downloadItem.DownloadedTileCount.ToString();

                Save();
            }
        }
Exemple #2
0
        /// <summary>
        /// 写入日志文件
        /// </summary>
        /// <param name="downloader"></param>
        public static void WriteConfig(MapServerDownloader downloader)
        {
            Clear();
            configDoc.Root.Add(new XElement("mapType", downloader.MapType));
            configDoc.Root.Add(new XElement("extent",
                                            new XAttribute("minLongitude", downloader.DownloadExtent.MinLongitude.ToString()),
                                            new XAttribute("maxLongitude", downloader.DownloadExtent.MaxLongitude.ToString()),
                                            new XAttribute("minLatitude", downloader.DownloadExtent.MinLatitude.ToString()),
                                            new XAttribute("maxLatitude", downloader.DownloadExtent.MaxLongitude.ToString())
                                            ));
            configDoc.Root.Add(new XElement("zoom",
                                            new XAttribute("from", downloader.MinDownloadZoom.ToString()),
                                            new XAttribute("to", downloader.MaxDownloadZoom.ToString())
                                            ));
            configDoc.Root.Add(new XElement("savePath", downloader.SavePath));
            configDoc.Root.Add(new XElement("downloadTileCount", downloader.DownloadTileCount.ToString()));
            configDoc.Root.Add(new XElement("downloadedTileCount", downloader.DownloadedTileCount.ToString()));
            configDoc.Root.Add(new XElement("curDownloadZoom", downloader.CurDownloadZoom != null ? downloader.CurDownloadZoom.Zoom.ToString() : downloader.MinDownloadZoom.ToString()));

            XElement downloadItems = new XElement("items");

            foreach (DownloadZoom item in downloader.DownloadZoomQueue)
            {
                downloadItems.Add(DownloadZoomItemConfig(item));
            }

            configDoc.Root.Add(downloadItems);

            Save();
        }
        private void btnLoadConfig_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                downloader = Core.DownloadConfig.Load(fileDialog.FileName);
            }
        }
        /// <summary>
        /// 瓦片下载完成
        /// </summary>
        /// <param name="downloader"></param>
        /// <param name="tile"></param>
        private void TileDownloadCompleted(Core.MapServerDownloader downloader, Core.Tile tile)
        {
            string logFormat = "当前线程:{0}    瓦片:{1},{2},{3}     时间:{4}";

            Core.Log.Write(logFile,
                           string.Format(logFormat, System.Threading.Thread.CurrentThread.Name
                                         , tile.X.ToString(), tile.Y.ToString(), tile.Zoom.ToString(), DateTime.Now.ToString("MM-dd HH:mm:ss ffff")));

            statusbar_progress.Value = (int)((downloader.DownloadedTileCount / (decimal)downloader.DownloadTileCount) * 100);
            statusbar_status.Text    = "下载中......" + downloader.DownloadedTileCount.ToString() + "/" + downloader.DownloadTileCount.ToString();
        }
        /// <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      = "下载中......";
        }
Exemple #6
0
        /// <summary>
        /// 加载配置文件
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static MapServerDownloader Load(string path)
        {
            XDocument doc = XDocument.Load(path);

            if (doc == null)
            {
                return(null);
            }

            MapServerDownloader downloader = InitByType(doc.Root.Element("mapType").Value);
            XElement            ele        = doc.Root.Element("extent");
            double minLon = double.Parse(ele.Attribute("minLongitude").Value);
            double maxLon = double.Parse(ele.Attribute("maxLongitude").Value);
            double minLat = double.Parse(ele.Attribute("minLatitude").Value);
            double maxLat = double.Parse(ele.Attribute("maxLatitude").Value);

            downloader.DownloadExtent = new Extent(minLon, minLat, maxLon, maxLat);

            ele = doc.Root.Element("zoom");
            downloader.MinDownloadZoom     = int.Parse(ele.Attribute("from").Value);
            downloader.MaxDownloadZoom     = int.Parse(ele.Attribute("to").Value);
            downloader.SavePath            = doc.Root.Element("savePath").Value;
            downloader.DownloadedTileCount = ulong.Parse(doc.Root.Element("downloadedTileCount").Value);

            DownloadZoom downloadZoom;

            foreach (XElement item in doc.Root.Element("items").Elements("item"))
            {
                downloadZoom            = ReadDownloadZoom(item);
                downloadZoom.Downloader = downloader;

                downloader.DownloadZoomQueue.Add(downloadZoom);
            }

            downloader.DownloadTileCount = (ulong)downloader.DownloadZoomQueue.Sum(d => d.TileCount);
            downloader.CurDownloadZoom   = downloader.DownloadZoomQueue.Where(d => d.Zoom == int.Parse(doc.Root.Element("curDownloadZoom").Value)).First();
            WriteConfig(downloader);

            return(downloader);
        }
        /// <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 = "下载中......";
        }
        private void btnLoadConfig_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                downloader = Core.DownloadConfig.Load(fileDialog.FileName);
            }
        }
        /// <summary>
        /// 写入日志文件
        /// </summary>
        /// <param name="downloader"></param>
        public static void WriteConfig(MapServerDownloader downloader)
        {
            Clear();
            configDoc.Root.Add(new XElement("mapType", downloader.MapType));
            configDoc.Root.Add(new XElement("extent",
                new XAttribute("minLongitude", downloader.DownloadExtent.MinLongitude.ToString()),
                new XAttribute("maxLongitude", downloader.DownloadExtent.MaxLongitude.ToString()),
                new XAttribute("minLatitude", downloader.DownloadExtent.MinLatitude.ToString()),
                new XAttribute("maxLatitude", downloader.DownloadExtent.MaxLongitude.ToString())
            ));
            configDoc.Root.Add(new XElement("zoom",
                new XAttribute("from", downloader.MinDownloadZoom.ToString()),
                 new XAttribute("to", downloader.MaxDownloadZoom.ToString())
            ));
            configDoc.Root.Add(new XElement("savePath", downloader.SavePath));
            configDoc.Root.Add(new XElement("downloadTileCount", downloader.DownloadTileCount.ToString()));
            configDoc.Root.Add(new XElement("downloadedTileCount", downloader.DownloadedTileCount.ToString()));
            configDoc.Root.Add(new XElement("curDownloadZoom", downloader.CurDownloadZoom != null ? downloader.CurDownloadZoom.Zoom.ToString() : downloader.MinDownloadZoom.ToString()));

            XElement downloadItems = new XElement("items");
            foreach (DownloadZoom item in downloader.DownloadZoomQueue)
            {
                downloadItems.Add(DownloadZoomItemConfig(item));
            }

            configDoc.Root.Add(downloadItems);

            Save();
        }