public TilePyramid(Geometry.GridRectangle bounds) { Bounds = bounds; }
protected void UpdateTiles(Rect visRect, double downsample) { System.Diagnostics.Trace.WriteLine("UpdateTiles()"); if (visRect.Width == 0 || visRect.Height == 0) return; //Find which tiles changed //Rect visRect = this.VisibleRect; Geometry.GridRectangle visibleGridRect = new Geometry.GridRectangle(visRect.Left, visRect.Right, visRect.Top, visRect.Bottom); TilePyramid oldTilePyramid = this.TilePyramid; Trace.WriteLine(TileMapping.ToString()); TilePyramid newTilePyramid = TileMapping.VisibleTiles(visibleGridRect, downsample); if (oldTilePyramid != null) { if (false == oldTilePyramid.Bounds.Intersects(newTilePyramid.Bounds)) Tiles.Clear(); else { //Might be able to really speed up culling dead tiles with QuadTrees //Sort out which of the old tiles are no longer visible for (int iTile = 0; iTile < Tiles.Count; iTile++) { TileViewModel t = Tiles[iTile]; if (false == visibleGridRect.Intersects(t.Bounds)) { Tiles.RemoveAt(iTile); iTile--; } else { //SortedDictionary<string, Tile> tilesForLevel = newTilePyramid.GetTilesForLevel(t.Downsample); } } } } //Create tiles which are new for(int iLevel = newTilePyramid.AvailableLevels.Length -1; iLevel >= 0; iLevel--) //for (int iLevel = 0; iLevel >= 0; iLevel--) //for (int iLevel = 0; iLevel < newTilePyramid.AvailableLevels.Length; iLevel++) { int level = newTilePyramid.AvailableLevels[iLevel]; SortedDictionary<string, Tile> tiles = newTilePyramid.GetTilesForLevel(level); bool IgnoreOldPyramid = oldTilePyramid == null; //Don't check the old pyramid if it doesn't have the downsample level we are looking at if (false == IgnoreOldPyramid) { if (oldTilePyramid.AvailableLevels.Length == 0) { IgnoreOldPyramid = true; } else { IgnoreOldPyramid = level < oldTilePyramid.AvailableLevels.Min(); if (false == IgnoreOldPyramid) { IgnoreOldPyramid = level > oldTilePyramid.AvailableLevels.Max(); } } } foreach (Tile t in tiles.Values) { //We already loaded this one // if (!IgnoreOldPyramid && oldTilePyramid.Bounds.Intersects(t.Bounds)) // continue; // else { TileViewModel tileViewModel = null; tileViewModel = TileCache.Fetch(t.UniqueKey); if (tileViewModel == null) { tileViewModel = new TileViewModel(t, TileMapping.TilePath); TileCache.Add(t.UniqueKey, tileViewModel); } // else // { //Don't add it to the collection again if (Tiles.Contains(tileViewModel)) continue; //} this.Tiles.Add(tileViewModel); } } } //This is horrible, but I do it to trigger the Dependancy property listeners because 3D collections don't subribe to the collection change notifications ObservableCollection<TileViewModel> newTiles = new ObservableCollection<TileViewModel>(this.Tiles); this.Tiles = newTiles; TilePyramid = newTilePyramid; }