Hi Gustavo,
I'm sorry that I cannot spend much time to work on your exact requirement. But here I wrote a method for you to help generating the tiles; you will know more about our cache system after you reading this code; I'm sure you can implement your requirement by your logic later. It's a long reply here;
this method generates cache for one zoomlevel.
private static void GenerateCacheFiles(IEnumerable<Layer> layers, double scale, RectangleShape restrictedExtent, GeographyUnit mapUnit, string cacheDirectory, string cacheId)
{
// create a MapSuite default tile matrix object.
MapSuiteTileMatrix matrix = new MapSuiteTileMatrix(scale, 256, 256, mapUnit);
// get cells in the specified extent.
Collection<TileMatrixCell> cells = matrix.GetIntersectingCells(restrictedExtent);
// create a tile cache object with the cache directory and cache id.
FileBitmapTileCache tileCache = new FileBitmapTileCache(cacheDirectory, cacheId);
foreach (TileMatrixCell cell in cells)
{
// create a bitmap whoes size equals to the tile size.
using (Bitmap bitmap = new Bitmap(256, 256))
{
// create a GeoCanvas which for drawing the passed layers.
GdiPlusGeoCanvas geoCanvas = new GdiPlusGeoCanvas();
geoCanvas.BeginDrawing(bitmap, cell.BoundingBox, mapUnit);
foreach (Layer layer in layers)
{
lock (layer)
{
if (!layer.IsOpen) { layer.Open(); }
layer.Draw(geoCanvas, new Collection<SimpleCandidate>());
}
}
// you can commend this line out because it's just for mark a cache label in order to see if it works with our samples.
geoCanvas.DrawText("Cache", new GeoFont("Arial", 12), new GeoSolidBrush(GeoColor.SimpleColors.Black), new Collection<ScreenPointF>() { new ScreenPointF(128f, 128f) }, DrawingLevel.LabelLevel);
geoCanvas.EndDrawing();
// create tile object to maintain current tile information.
BitmapTile tile = new BitmapTile(bitmap, cell.BoundingBox, scale);
// save tile.
tileCache.SaveTile(tile);
}
}
}
The following code indicates how to use the method above to generate cache files from zoomlevel01 to 03.
string cacheDirectory = @"c:\share\new";
string cacheId = "Cache1";
ZoomLevelSet zoomLevelSet = new ZoomLevelSet();
Collection<Layer> layers = new Collection<Layer>() { worldLayer };
RectangleShape restrictedExtent = new RectangleShape(-180, 90, 180, -90);
GenerateCacheFiles(layers, zoomLevelSet.ZoomLevel01.Scale, restrictedExtent, GeographyUnit.DecimalDegree, cacheDirectory, cacheId);
GenerateCacheFiles(layers, zoomLevelSet.ZoomLevel02.Scale, restrictedExtent, GeographyUnit.DecimalDegree, cacheDirectory, cacheId);
GenerateCacheFiles(layers, zoomLevelSet.ZoomLevel03.Scale, restrictedExtent, GeographyUnit.DecimalDegree, cacheDirectory, cacheId);
MessageBox.Show("Done");
The following code indicates how to use the cache files.
Map1.MapUnit = GeographyUnit.DecimalDegree;
Map1.CurrentExtent = new RectangleShape(-155.733, 95.60, 104.42, -81.9);
ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"..\..\SampleData\Data\Countries02.shp");
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Green));
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
string cacheDirectory = @"c:\share\new";
string cacheId = "Cache1";
LayerOverlay layerOverlay = new LayerOverlay();
layerOverlay.Layers.Add(worldLayer);
layerOverlay.TileCache = new FileBitmapTileCache(cacheDirectory, cacheId);
Map1.Overlays.Add(layerOverlay);
Map1.Refresh();
Please let me know if you have any queries. We adjusted the matrix in the WpfDesktop Edition few days ago, please download the latest build if this sample doesn't work.
Thanks,
Howard