示例#1
0
        protected void SelectTiles()
        {
            var maxZoomLevel = Math.Min(zoomLevel, MaxZoomLevel);
            var minZoomLevel = maxZoomLevel;
            var container    = TileContainer;

            if (LoadLowerZoomLevels && container != null && container.Children.IndexOf(this) == 0)
            {
                minZoomLevel = MinZoomLevel;
            }

            var newTiles = new List <Tile>();

            for (var z = minZoomLevel; z <= maxZoomLevel; z++)
            {
                var tileSize = 1 << (zoomLevel - z);
                var x1       = (int)Math.Floor((double)grid.X / tileSize); // may be negative
                var x2       = (grid.X + grid.Width - 1) / tileSize;
                var y1       = Math.Max(grid.Y / tileSize, 0);
                var y2       = Math.Min((grid.Y + grid.Height - 1) / tileSize, (1 << z) - 1);

                for (var y = y1; y <= y2; y++)
                {
                    for (var x = x1; x <= x2; x++)
                    {
                        var tile = tiles.FirstOrDefault(t => t.ZoomLevel == z && t.X == x && t.Y == y);

                        if (tile == null)
                        {
                            tile = new Tile(z, x, y);

                            var equivalentTile = tiles.FirstOrDefault(
                                t => t.ImageSource != null && t.ZoomLevel == z && t.XIndex == tile.XIndex && t.Y == y);

                            if (equivalentTile != null)
                            {
                                // do not animate to avoid flicker when crossing date line
                                tile.SetImageSource(equivalentTile.ImageSource, false);
                            }
                        }

                        newTiles.Add(tile);
                    }
                }
            }

            tiles = newTiles;
        }
示例#2
0
        private void SelectTiles()
        {
            var maxZoomLevel = Math.Min(zoomLevel, MaxZoomLevel);
            var minZoomLevel = maxZoomLevel;

            if (LoadLowerZoomLevels && Parent is TileContainer && ((TileContainer)Parent).TileLayers.FirstOrDefault() == this)
            {
                minZoomLevel = MinZoomLevel;
            }

            var newTiles = new List<Tile>();

            for (var z = minZoomLevel; z <= maxZoomLevel; z++)
            {
                var tileSize = 1 << (zoomLevel - z);
                var x1 = (int)Math.Floor((double)grid.X / tileSize); // may be negative
                var x2 = (grid.X + grid.Width - 1) / tileSize;
                var y1 = Math.Max(grid.Y / tileSize, 0);
                var y2 = Math.Min((grid.Y + grid.Height - 1) / tileSize, (1 << z) - 1);

                for (var y = y1; y <= y2; y++)
                {
                    for (var x = x1; x <= x2; x++)
                    {
                        var tile = tiles.FirstOrDefault(t => t.ZoomLevel == z && t.X == x && t.Y == y && t.Rotation == rotation);

                        if (tile == null)
                        {
                            tile = new Tile(z, x, y, rotation);

                            var equivalentTile = tiles.FirstOrDefault(
                                t => t.Image.Source != null && t.ZoomLevel == z && t.XIndex == tile.XIndex && t.Y == y);

                            if (equivalentTile != null)
                            {
                                // do not animate to avoid flicker when crossing date line
                                tile.SetImageSource(equivalentTile.Image.Source, false, equivalentTile.Rotation != rotation);
                            }
                        }

                        newTiles.Add(tile);
                    }
                }
            }

            tiles = newTiles;
        }