Thanks for your update, I get many information from your communication.
The reason why DeleteTiles don’t works is because its default scale point to zoom level 01, so it always try to delete the cached image from folder 590591790 by default. After map refresh, the scale get changed, it also change the value of overlay.TileCache.TileMatrix.Scale, so you can delete target images correct.
Based on this, you can see the solution to delete cache images is:
double currentScale = ExtentHelper.GetSnappedScale(rect, (float)map.ActualWidth, map.MapUnit);
cache.TileMatrix.Scale = currentScale;
You can put it in the map_Loaded event, it will delete target tiles in initial zoom level.
And you can delete other levels in other functions for example:
map.CurrentScaleChanged += Map_CurrentScaleChanged;
private void Map_CurrentScaleChanged(object sender, CurrentScaleChangedWpfMapEventArgs e)
if (thisLevelDeletedFlag)// You can set a flag here to avoid delete many times which will reduce performance
LayerOverlay overlay = map.Overlays as LayerOverlay;
overlay.TileCache.TileMatrix.Scale = e.CurrentScale;
You can also build a function to delete all levels or specified levels once:
public void DeleteOldCache(FileBitmapTileCache cache, RectangleShape rect, ZoomLevelSet zoomLevelSet)
foreach (ZoomLevel level in zoomLevelSet.GetZoomLevels())
cache.TileMatrix.Scale = level.Scale;
But I don’t suggest you use it, because in certain scenario it’s very slow for deep levels even if they don’t have cached images.
For avoid that, you can use the other solution, loop the folder names (They are scale value) under your cache folder (For example “LinearCachedTiles”), then loop the names, set it to TileMatrix.Scale and delete the tiles in specified area.
And please notice, if the specified area is very big, clear cache is a better choice, clear cache will delete the cache folder without calculation.
I hope that’s able to help you.