Example #1
0
        private void OnRender()
        {
            if (rendering && !renderingPending)
            {
                Dispatcher.BeginInvoke(OnRender);
                return;
            }
            else if (rendering)
            {
                return;
            }

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            rendering        = true;
            renderingPending = false;

            ContentPanel.Children.Clear();

            var  transform = Plotter.Viewport.Transform;
            Rect output    = Plotter.Viewport.Output;

            Rect visible   = Plotter.Viewport.Visible;
            var  tileInfos = GetVisibleTiles();

            int minLevel   = TileProvider.Level - maxLevelShift;
            var lowerTiles = GetLoadedLowerTiles(tileInfos).Where(id => id.Level >= minLevel);

            foreach (var tile in lowerTiles)
            {
                if (TileSystem.IsReady(tile))
                {
                    BitmapImage bmp         = TileSystem[tile];
                    Rect        visibleRect = Transform(TileProvider.GetBounds(tile));
                    Rect        screenRect  = visibleRect.DataToScreen(transform);

                    DrawTile(bmp, screenRect, visibleRect);
                }
                else
                {
                    TileSystem.BeginLoadImage(tile);
                }
            }

            foreach (var tileInfo in tileInfos)
            {
                if (TileSystem.IsReady(tileInfo.Tile))
                {
                    BitmapImage bmp = TileSystem[tileInfo.Tile];
                    DrawTile(bmp, tileInfo.ScreenBounds, tileInfo.VisibleBounds);
                }
                else
                {
                    TileSystem.BeginLoadImage(tileInfo.Tile);
                }
            }

            rendering = false;
        }