示例#1
0
        private void DownloadThread(CancellationToken ct)
        {
            var leftBound  = new GeomCoordinate(Properties.Settings.Default.LeftMapBound, Properties.Settings.Default.TopMapBound);
            var rightBound = new GeomCoordinate(Properties.Settings.Default.RightMapBound, Properties.Settings.Default.BottomMapBound);

            var rectBound = new CoordinateRectangle(leftBound, rightBound);

            var mapBlockCount = 0;

            for (var mapLevel = Properties.Settings.Default.MinZoomLevel; mapLevel <= Properties.Settings.Default.MaxZoomLevel; mapLevel++)
            {
                var mapWidth  = Convert.ToInt32((new ScreenCoordinate(rectBound.RightTop, mapLevel)).X - (new ScreenCoordinate(rectBound.LeftTop, mapLevel)).X) + 2 * TileBlock.BlockSize;
                var mapHeight = Convert.ToInt32((new ScreenCoordinate(rectBound.LeftBottom, mapLevel)).Y - (new ScreenCoordinate(rectBound.LeftTop, mapLevel)).Y) + 2 * TileBlock.BlockSize;

                var viewBound = rectBound.LineMiddlePoint.GetScreenViewFromCenter(mapWidth, mapHeight, mapLevel);
                var blockView = viewBound.BlockView;
                mapBlockCount += (blockView.Right - blockView.Left + 1) * (blockView.Bottom - blockView.Top + 1);
            }

            var mapBlockNumber = 0;

            BeginInvoke(ProgressEvent, new Object[] { mapBlockNumber * 100 / mapBlockCount, mapBlockNumber, mapBlockCount });

            for (var mapLevel = Properties.Settings.Default.MinZoomLevel; mapLevel <= Properties.Settings.Default.MaxZoomLevel; mapLevel++)
            {
                var mapWidth  = Convert.ToInt32((new ScreenCoordinate(rectBound.RightTop, mapLevel)).X - (new ScreenCoordinate(rectBound.LeftTop, mapLevel)).X) + 2 * TileBlock.BlockSize;
                var mapHeight = Convert.ToInt32((new ScreenCoordinate(rectBound.LeftBottom, mapLevel)).Y - (new ScreenCoordinate(rectBound.LeftTop, mapLevel)).Y) + 2 * TileBlock.BlockSize;

                var viewBound = rectBound.LineMiddlePoint.GetScreenViewFromCenter(mapWidth, mapHeight, mapLevel);
                var blockView = viewBound.BlockView;

                for (var x = blockView.Left; x <= blockView.Right; x++)
                {
                    for (var y = blockView.Top; y <= blockView.Bottom; y++)
                    {
                        var block = new TileBlock(x, y, mapLevel);

                        var fileName = Properties.Settings.GetMapFileName(block);
                        if (!File.Exists(fileName))
                        {
                            TileLayer.DownloadImageFromTile(block, false);
                        }

                        mapBlockNumber++;

                        BeginInvoke(ProgressEvent, new Object[] { mapBlockNumber * 100 / mapBlockCount, mapBlockNumber, mapBlockCount });

                        if (ct.IsCancellationRequested)
                        {
                            return;
                        }
                    }
                }
            }
            BeginInvoke(ProgressEvent, new Object[] { 101, mapBlockNumber, mapBlockCount });
        }
示例#2
0
        private void GetFullMapThread(CancellationToken ct)
        {
            var leftBound  = new GeomCoordinate(Properties.Settings.Default.LeftMapBound, Properties.Settings.Default.TopMapBound);
            var rightBound = new GeomCoordinate(Properties.Settings.Default.RightMapBound, Properties.Settings.Default.BottomMapBound);

            var rectBound = new CoordinateRectangle(leftBound, rightBound);

            try
            {
                var mapWidth  = Convert.ToInt32((new ScreenCoordinate(rectBound.RightTop, _mapLevel)).X - (new ScreenCoordinate(rectBound.LeftTop, _mapLevel)).X) + 2 * TileBlock.BlockSize;
                var mapHeight = Convert.ToInt32((new ScreenCoordinate(rectBound.LeftBottom, _mapLevel)).Y - (new ScreenCoordinate(rectBound.LeftTop, _mapLevel)).Y) + 2 * TileBlock.BlockSize;

                var image    = GraphicLayer.CreateCompatibleBitmap(null, mapWidth, mapHeight, _mapPiFormat);
                var graphics = Graphics.FromImage(image);

                var viewBound      = rectBound.LineMiddlePoint.GetScreenViewFromCenter(mapWidth, mapHeight, _mapLevel);
                var blockView      = viewBound.BlockView;
                var mapBlockCount  = (blockView.Right - blockView.Left + 1) * (blockView.Bottom - blockView.Top + 1);
                var mapBlockNumber = 0;

                BeginInvoke(ProgressEvent, new Object[] { mapBlockNumber * 100 / mapBlockCount, mapBlockNumber, mapBlockCount });

                for (var x = blockView.Left; x <= blockView.Right; x++)
                {
                    for (var y = blockView.Top; y <= blockView.Bottom; y++)
                    {
                        var block = new TileBlock(x, y, _mapLevel);
                        var bmp   = GraphicLayer.CreateCompatibleBitmap(
                            TileLayer.DownloadImageFromFile(block) ?? TileLayer.DownloadImageFromTile(block, true),
                            TileBlock.BlockSize, TileBlock.BlockSize, _mapPiFormat);

                        var rect = ((ScreenRectangle)block).GetScreenRect(viewBound);
                        graphics.DrawImageUnscaled(bmp, rect.Location.X, rect.Location.Y);

                        mapBlockNumber++;

                        BeginInvoke(ProgressEvent, new Object[] { mapBlockNumber * 100 / mapBlockCount, mapBlockNumber, mapBlockCount });

                        if (ct.IsCancellationRequested)
                        {
                            return;
                        }
                    }
                }

                BeginInvoke(SaveMapEvent, new Object[] { image });
            }
            catch (Exception e)
            {
                BeginInvoke(ProgressEvent, new Object[] { 101, 0, 0 });
                MessageBox.Show(e.Message, @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }