Hi,
I was wondering if anyone can help me with a tile generating issue for a custom cache method I’ve implemented.
The method seems to create the tiles correctly. However, when the tiles are saved to the temporary folder, the tiles are numbered differently to what I believe should be expected, so that when the caching tool checks for tiles in the temporary folder, it believes that none are part of the correct grid and so generates its own.
Here’s the code for the tile generation below:
the parameters take: All the layers, The current scale, The extent (current view) of the map, GeographyUnit.Meter, and the cache files( usually in windows temp folder).
public static void GenerateCacheFiles(IEnumerable layers, double scale, RectangleShape restrictedExtent, GeographyUnit mapUnit, string cacheDirectory, string cacheId)
{
FileBitmapTileCache cache = new FileBitmapTileCache(cacheDirectory, cacheId);
cache.TileMatrix.Scale = scale;
cache.TileMatrix = new MapSuiteTileMatrix(scale, 256, 256, mapUnit, restrictedExtent);
Collection<TileMatrixCell> cells = cache.TileMatrix.GetIntersectingCells(restrictedExtent); foreach (TileMatrixCell cell in cells) { using (Bitmap bitmap = new Bitmap(256, 256)) { PlatformGeoCanvas geoCanvas = new PlatformGeoCanvas(); geoCanvas.BeginDrawing(bitmap, cell.BoundingBox, mapUnit); foreach (Layer layer in layers) { lock (layer) { if (!layer.IsOpen) { layer.Open(); } layer.Draw(geoCanvas, new Collection<SimpleCandidate>()); } }
geoCanvas.EndDrawing(); GeoImage geoImage = new GeoImage(bitmap);
// create tile object to maintain current tile information. BitmapTile tile = new BitmapTile(geoImage, cell.BoundingBox, scale);
// save tile. cache.SaveTile(tile); } } }
Here is the init of the tile cache:
userOverlay.TileCache = new FileBitmapTileCache(Path.GetTempPath(), “test”);
userOverlay.TileCache.TileMatrix.BoundingBoxUnit = GeographyUnit.Meter;
Below is the folder where the cache tiles are saved. As you can see, the files that the cache generated on its own gives different results to the cache tiles that were created with the custom tile generator.
Regards,
Zak