Hi
I generated map caches by the code that is provide on this site.
I try to make Mercator projection map, but the results have some problem.
1) Map shifted to the bottom left side direction, you can see the result in the attachment.
2) I expect only 4 tiles but there are 9 tiles as result.
Would you please let me know the reason or solution?
Thanks
Daniel
generate_MapTiles(LayerProvider.GetLayersToCache(), new SphericalMercatorZoomLevelSet().ZoomLevel02.Scale,
Utils.ConvertGeoToMeter(new RectangleShape(-180, 90, 180, -90)), GeographyUnit.Meter, edOutputFolder.Text, “AVES”);
private void generate_MapTiles(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);
tileCache.TileMatrix.BoundingBoxUnit = mapUnit;
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.Red), 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);
}
}
}
public static RectangleShape ConvertGeoToMeter(RectangleShape po_GeoRect)
{
ManagedProj4Projection proj4 = new ManagedProj4Projection
{
InternalProjectionParametersString = ManagedProj4Projection.GetDecimalDegreesParametersString(),
ExternalProjectionParametersString = ManagedProj4Projection.GetSphericalMercatorParametersString()
};
proj4.Open();
RectangleShape result = proj4.ConvertToExternalProjection(po_GeoRect);
proj4.Close();
return result;
}
public static Collection<Layer> GetLayersToCache(bool pb_RebuildIndex = false)
{
Collection<Layer> result = new Collection<Layer>();
GeoColor colorSea = GeoColor.FromHtml("#A5BFDD");
GeoColor colorLand = GeoColor.FromHtml("#EFEFEF");
GeoColor colorBackPiracy = GeoColor.FromArgb(150, 0xFF, 0xE0, 0x93);
GeoColor colorBackEcazone = GeoColor.FromArgb(180, 0xA0, 0xDA, 0xFF);
GeoColor colorLinePiracy = GeoColor.FromArgb(170, 0xFF, 0x42, 0x00);
GeoColor colorLineEcazone = GeoColor.FromArgb(120, 0x00, 0x48, 0xFF);
GeoColor colorLineLand = GeoColor.FromArgb(170, 0x89, 0xA8, 0xCF);
GeoColor colorLineLandLighter = GeoColor.FromArgb(12, 0x89, 0xA8, 0xCF);
GeoColor colorLineCountry = GeoColor.FromHtml("#B9B6A5");
GeoColor colorLineTimezone = GeoColor.FromHtml("#C0DDDA");
GeoColor colorLineState = GeoColor.FromHtml("#E1E1E1");
GeoColor colorText = GeoColor.FromHtml("#251d19");
GeoColor colorTextLighter = GeoColor.FromHtml("#5b5b5b");
LineStyle linePiracy = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(255, colorLinePiracy), 0.5F, true);
LineStyle lineEcazone = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(255, colorLineEcazone), 0.5F, true);
LineStyle lineBaseMap = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(255, colorLand), 0.5F, true);
LineStyle lineLiverLake = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(255, colorSea), 1.0F, true);
LineStyle lineInnerLiver = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(255, colorSea), 1.0F, true);
LineStyle lineCountry = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(255, colorLineCountry), 1.0F, true);
LineStyle lineState = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(255, colorLineState), 0.5F, LineDashStyle.Dash, true);
AreaStyle areaTimeZone = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, colorLineTimezone, 1, LineDashStyle.DashDot);
AreaStyle areaPiracy = AreaStyles.CreateSimpleAreaStyle(colorBackPiracy, colorLinePiracy, 1, LineDashStyle.DashDot);
AreaStyle areaEcazone = AreaStyles.CreateSimpleAreaStyle(colorBackEcazone, colorLineEcazone, 1, LineDashStyle.DashDot);
AreaStyle areaBaseMap1 = AreaStyles.CreateSimpleAreaStyle(colorLand, colorLineLandLighter, 1, LineDashStyle.Solid);
AreaStyle areaBaseMap2 = AreaStyles.CreateSimpleAreaStyle(colorLand, colorLineLand, 1, LineDashStyle.Solid);
AreaStyle areaLiverLake = AreaStyles.CreateSimpleAreaStyle(colorSea, colorLand, 1, LineDashStyle.Solid);
AreaStyle areaInnerLiver = AreaStyles.CreateSimpleAreaStyle(colorLand, colorSea, 1, LineDashStyle.Solid);
TextStyle textTimeZone1 = TextStyles.CreateSimpleTextStyle(“NAME”, “Segoe UI”, 7.0F, DrawingFontStyles.Regular, colorTextLighter);
TextStyle textTimeZone2 = TextStyles.CreateSimpleTextStyle(“NAME”, “Segoe UI”, 8.75F, DrawingFontStyles.Regular, colorTextLighter);
TextStyle textBaseMap1 = TextStyles.CreateSimpleTextStyle(“NAME”, “Segoe UI”, 7.5F, DrawingFontStyles.Regular, colorText);
TextStyle textBaseMap2 = TextStyles.CreateSimpleTextStyle(“NAME”, “Segoe UI”, 8.75F, DrawingFontStyles.Regular, colorText);
TextStyle textPortName = TextStyles.CreateSimpleTextStyle(“NAME”, “Segoe UI”, 8.5F, DrawingFontStyles.Regular, colorText);
// Draw Base Background color
result.Add(new BackgroundLayer(new GeoSolidBrush(colorSea)));
// Draw Time Zone lines
result.Add(new LayerDefinition(02, 07, @“M:\SHAPE\NaturalEarth\10m_cultural\ne_10m_time_zones.shp”).GetShapeLayer(null, areaTimeZone));
// Draw Time Zone labels for lower zoom level
result.Add(new LayerDefinition(01, 03, @“M:\SHAPE\NaturalEarth\10m_cultural\ne_10m_time_zones.shp”).GetLabelLayer(textTimeZone1));
// Draw Time Zone labels for higher zoom level
result.Add(new LayerDefinition(04, 20, @“M:\SHAPE\NaturalEarth\10m_cultural\ne_10m_time_zones.shp”).GetLabelLayer(textTimeZone2));
// Draw Piracy areas
result.Add(new LayerDefinition(01, 20, @“M:\SHAPE\AWT\Piracy.shp”).GetShapeLayer(linePiracy, areaPiracy));
// Draw Eca Zone areas
result.Add(new LayerDefinition(01, 20, @“M:\SHAPE\AWT\Ecazone.shp”).GetShapeLayer(lineEcazone, areaEcazone));
// Draw Land borders for lower zoom level
result.Add(new LayerDefinition(01, 07, @“M:\SHAPE\ThinkGeo\countries.shp”).GetShapeLayer(lineBaseMap, areaBaseMap1));
// Draw Land borders for higher zoom level
result.Add(new LayerDefinition(08, 20, @“M:\SHAPE\NoaaGSHHG\V2.2.2\GSHHS_shp\f\GSHHS_f_L1.shp”).GetShapeLayer(lineBaseMap, areaBaseMap2));
return result;
}
Cache tile pre-generation problem
Hi Daniel,
We have a TileCache Generator Utility for generator tile cache, please try to use it generate your cache. thinkgeo.com/forums/MapSuite/tabid/143/aft/10446/Default.aspx
And I noticed you mentioned “Map shifted to the bottom left side direction” but I haven’t sawn related attachment.
Any question please let me know.
Regards,
Don
Thank you for your answer.
I already used the program, also I made a modified tile generator for my needs.
It is very successful in equirectangular projection,but I want to create tiles in Mercator projection.
As you can see below, tile in image is create at the down left position, the red line have to be at the right top corner.
In the equirectangular projection, the image was create on the perfect position, as you can see the last two images.
What is the reason?
Hi Daniel,
You should have created a ticket for the same problem, please see our response there.
Regards,
Don