internal void DoProcess(MultiscaleImageViewport state)
 {
     this.parameters    = state;
     this.hasParameters = true;
     this.processStart  = true;
     this.processRequest.Set();
 }
        private void Process()
        {
            MultiscaleImageViewport viewport = this.parameters;

            if (viewport.ActualWidth > 0 && viewport.ViewportWidth > 0)
            {
                this.zoomLevelShift = (int)Math.Round(Math.Log(viewport.TileWidth, 2));
                double zoom        = viewport.ActualWidth / viewport.TileWidth / viewport.ViewportWidth;
                double zoomLevel   = Math.Log(zoom, 2d);
                double currentZoom = Math.Round(zoomLevel);
                double scaleFactor = Math.Pow(2, zoomLevel - currentZoom);
                double tileWidth   = viewport.TileWidth * scaleFactor;
                double tileHeight  = viewport.TileHeight * scaleFactor;

                Rect imageRect = TilesDownloadManager.GetImageBounds(zoom, viewport);
                if (!imageRect.IsEmpty)
                {
                    this.endLevel   = (int)Math.Ceiling(Math.Log(zoom, 2d));
                    this.startTileX = (int)(imageRect.X / tileWidth);
                    this.startTileY = (int)(imageRect.Y / tileHeight);
                    this.endTileX   = (int)Math.Ceiling(imageRect.Right / tileWidth) - 1;
                    this.endTileY   = (int)Math.Ceiling(imageRect.Bottom / tileHeight) - 1;

                    int endLevel3 = this.endLevel - 2;
                    endLevel3 = endLevel3 >= 0 ? endLevel3 : 0;
                    this.RequestTop3Levels(endLevel3);
                    this.RequestOtherLevels(endLevel3);

                    this.UpdateTileChache();
                }
            }
        }
Beispiel #3
0
        internal void ProcessTilesDownload(MultiscaleImageViewport state)
        {
            if (!(this is EmptyTileMapSource))
            {
                TilesDownloadManager manager = null;
                if (this.downloadManager == null)
                {
                    TilesDownloadManager downloader = new TilesDownloadManager(this);
                    downloader.MaxTileCacheSize = this.maxTileCacheSize;
                    downloader.MinTileNumber    = this.minTileNumber;
                    this.downloadManager        = downloader;
                    downloader.StartDownload();
                }

                manager = this.downloadManager;

                state.TileWidth  = this.tileWidth;
                state.TileHeight = this.tileHeight;

                if (manager != null)
                {
                    manager.DoProcess(state);
                }
            }
        }
        private static Rect GetImageBounds(double zoom, MultiscaleImageViewport viewport)
        {
            double imageLeft = -viewport.ActualWidth * viewport.ViewportOrigin.X / viewport.ViewportWidth;
            double imageTop  = -viewport.ActualWidth * viewport.ViewportOrigin.Y / viewport.ViewportWidth;

            double imageWidth  = zoom * viewport.TileWidth;
            double imageHeight = zoom * viewport.TileHeight;

            Rect imageRect    = new Rect(0, 0, imageWidth, imageHeight);
            Rect viewportRect = new Rect(-imageLeft, -imageTop, viewport.ActualWidth, viewport.ActualHeight);

            imageRect.Intersect(viewportRect);

            return(imageRect);
        }
        internal bool ValidateTile(TileId tileId)
        {
            if (!this.abort)
            {
                MultiscaleImageViewport viewport = this.parameters;
                if (viewport.ActualWidth > 0 && viewport.ViewportWidth > 0)
                {
                    int    tileZoomLevelShift = (int)Math.Round(Math.Log(viewport.TileWidth, 2));
                    int    tileLevel          = tileId.Level - tileZoomLevelShift;
                    double zoom         = viewport.ActualWidth / viewport.TileWidth / viewport.ViewportWidth;
                    int    tileEndLevel = (int)Math.Ceiling(Math.Log(zoom, 2d));

                    if (tileLevel <= tileEndLevel)
                    {
                        double scale = Math.Pow(2d, Math.Log(zoom, 2d) - tileLevel);

                        MultiScaleTileSource tileSource = this.Source;
                        if (tileSource != null)
                        {
                            double width  = tileSource.TileWidth * scale;
                            double height = tileSource.TileHeight * scale;
                            double x      = tileId.X * width;
                            double y      = tileId.Y * height;

                            double imageLeft = -viewport.ActualWidth * viewport.ViewportOrigin.X / viewport.ViewportWidth;
                            double imageTop  = -viewport.ActualWidth * viewport.ViewportOrigin.Y / viewport.ViewportWidth;

                            Rect tileBounds  = new Rect(x + imageLeft, y + imageTop, width, height);
                            Rect imageBounds = new Rect(0, 0, viewport.ActualWidth, viewport.ActualHeight);
                            imageBounds.Intersect(tileBounds);
                            if (!imageBounds.IsEmpty)
                            {
                                return(true);
                            }
                        }
                    }
                }

                this.RemoveRequest(tileId);
            }

            return(false);
        }
Beispiel #6
0
        private void Arrange()
        {
            MultiScaleTileSource tileSource = this.multiScaleTileSource;
            double internalViewportWidth    = (double)this.GetValue(InternalViewportWidthProperty);

            if (tileSource != null && !(tileSource is EmptyTileMapSource) && internalViewportWidth > 0)
            {
                MultiscaleImageViewport state = new MultiscaleImageViewport()
                {
                    ViewportOrigin = this.viewportOrigin,
                    ViewportWidth  = this.viewportWidth,
                    ActualWidth    = this.ActualWidth,
                    ActualHeight   = this.ActualHeight
                };

                tileSource.ProcessTilesDownload(state);

                this.CalculateImageLocation();
                this.ArrangeTiles();
            }
        }