public SpatialViewer_GDI()
        {
            InitializeComponent();

            try
            {
                //SetStyle(ControlStyles.ResizeRedraw, true);
                SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
                SetStyle(ControlStyles.AllPaintingInWmPaint, true);

                _strokes = new Dictionary <GeometryStyle, List <GraphicsPath> >();
                _fills   = new Dictionary <GeometryStyle, List <GraphicsPath> >();
                _points  = new Dictionary <GeometryStyle, List <PointF> >();
                _labels  = new Dictionary <SqlGeometry, string>();

                _mouseTranslate = new Matrix();
                _mouseScale     = new Matrix();
                //System.Windows.Forms.Application.AddMessageFilter(this);
                System.Windows.Forms.Application.AddMessageFilter(new MouseWheelMessageFilter());
                this.MouseWheel += SpatialViewer_GDI_MouseWheel;

                // Load point icon
                Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                using (Stream file = assembly.GetManifestResourceStream("SqlServerSpatial.Toolkit.Viewers.GDI.point.png"))
                {
                    _pointBmp = (Bitmap)Image.FromStream(file);
                }

                _tileDownloader = new TileDownloader();
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 2
0
    private void OnDestroy()
    {
        KillAll();
#if !UNITY_WEBPLAYER
        SaveTiles();
#endif
        instance = null;
    }
Ejemplo n.º 3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            lastClickTime = DateTime.Now;
            var td = new TileDownloader();

            this.TD         = td;
            this.TD.Servers = ServerListTextbox.Text.ToString();
            td.DownloadToFolder(StringUtils.XyzTo012(UrlTextbox.Text.ToString()), FolderTextbox.Text.ToString(), int.Parse(MaxlevelsTextbox.Text.ToString()), int.Parse(MinlevelTextbox.Text.ToString()));
            td.DownloadFileTasks.OnCompletedCountAdded += DownloadFileTasks_OnCompletedCountAdded;
        }
Ejemplo n.º 4
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            Logger.LogInformation("Running OfflineCacheBackgroundTask.");

            using (IServiceScope scope = ScopeFactory.CreateScope())
            {
                TileCacheRepository  = scope.ServiceProvider.GetRequiredService <TileCacheRepository>();
                TileSourceRepository = scope.ServiceProvider.GetRequiredService <TileSourceRepository>();
                Mapper = scope.ServiceProvider.GetRequiredService <IMapper>();

                do
                {
                    TileCacheViewModel unfinishedTileCache =
                        Mapper.Map <TileCacheViewModel>(await TileCacheRepository.GetFirstUnfinishedTileCache());

                    if (unfinishedTileCache != null)
                    {
                        await TileCacheRepository.SetTileCacheStarted(unfinishedTileCache.TileCacheId);

                        TileCacheManager tileCacheManager = await CreateTileCacheManager(unfinishedTileCache.TileCacheId);

                        TilesCount = 0;

                        // Do not remove already downloaded tiles
                        ////tileService.ClearTiles();

                        try
                        {
                            Bounds bounds = GeometryHelper.ToBounds(unfinishedTileCache.Bbox);

                            TileSource tileSource = await TileSourceRepository.GetTileSourceWithId(unfinishedTileCache.TileSourceId);

                            TileRangeCalculator calculator = new TileRangeCalculator
                            {
                                ValidBounds    = GeometryHelper.ToBounds(tileSource.Bbox),
                                ValidZoomRange = new ZoomRange
                                {
                                    MinZoom = 0,
                                    MaxZoom = tileSource.ZoomLevelMax,
                                },
                            };

                            TileRangeCollection tiles = new TileRangeCollectionCalculator(calculator).GetTileRanges(bounds, new ZoomRange
                            {
                                MinZoom = unfinishedTileCache.ZoomLevelMin ?? 0,
                                MaxZoom = unfinishedTileCache.ZoomLevelMax,
                            });

                            TilesTotal = tiles.TilesTotal;

                            if (TilesTotal > 30000)
                            {
                                await TileCacheRepository.SetTileCacheError(unfinishedTileCache.TileCacheId);

                                throw new ArgumentException($"Tile cache exceeding the maximum number of 30000 tiles: {TilesTotal}.");
                            }

                            TileDownloader tileDownloader =
                                tileSource.AllowHiDefStitching ? new MergedTileDownloader() : new TileDownloader();
                            tileDownloader.TileServerUrls = tileSource.TileServerUrls.Select(x => x.Url).ToList();

                            await tileDownloader.Download(tiles, (zoomLevel, tileRow, tileColumn, tileData) =>
                            {
                                // Note that in the TMS tiling scheme, the Y axis is reversed from the "XYZ" coordinate system commonly used in the URLs
                                int mbtilesRow = (int)Math.Pow(2, zoomLevel) - 1 - tileRow;

                                lock (OfflineCacheBackgroundTask.lockObject)
                                {
                                    TilesCount++;
                                }

                                if (tileCacheManager.TryGetTile(tileColumn, mbtilesRow, zoomLevel) == null)
                                {
                                    tileCacheManager.SaveTile(zoomLevel, mbtilesRow, tileColumn, tileData);
                                }
                            });

                            Bounds tileCacheBounds = GeometryHelper.ToBounds(unfinishedTileCache.Bbox);
                            string metadataBounds  = tileCacheBounds.ToCsv();

                            double centerLon      = tileCacheBounds.Center().Lon;
                            double centerLat      = tileCacheBounds.Center().Lat;
                            string metadataCenter = $"{centerLon},{centerLat},{unfinishedTileCache.ZoomLevelMin}";
                            string format         = tileSource.TileServerUrls[0].Url.EndsWith("png") ? "png" : "jpg";

                            tileCacheManager.SaveMetadata(unfinishedTileCache.Name, format, metadataBounds, metadataCenter,
                                                          unfinishedTileCache.ZoomLevelMin ?? 0, unfinishedTileCache.ZoomLevelMax);

                            await TileCacheRepository.SetTileCacheFinished(unfinishedTileCache.TileCacheId,
                                                                           $"{unfinishedTileCache.TileCacheId}.mbtiles");
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine(exception);
                            Logger.LogWarning(exception,
                                              $"OfflineCacheBackgroundTask: Exception when creating tile cache for campaign {unfinishedTileCache.TileCacheId}.");
                        }
                    }

                    await Task.Delay(5 * 1000, stoppingToken);
                }while (!stoppingToken.IsCancellationRequested);

                Logger.LogInformation("Exiting OfflineCacheBackgroundTask.");
            }
        }
Ejemplo n.º 5
0
 private void OnDestroy()
 {
     KillAll();
     SaveTiles();
     instance = null;
 }
Ejemplo n.º 6
0
 private void OnDestroy()
 {
     KillAll();
     #if !UNITY_WEBPLAYER
     SaveTiles();
     #endif
     instance = null;
 }