/// <summary> /// Creates the tile specified by level. /// </summary> /// <param name="level"> /// Zoom level. /// </param> /// <param name="tileX"> /// X tile coordinate. /// </param> /// <param name="tileY"> /// Y tile coordinate. /// </param> public void Create(int level, int tileX, int tileY) { // Pre-compute tables to map from pixel position to global (longitude, latitude). // Map size at this level. double tileSize = (double)(((long)Constants.TileSize) << level); // Compute longitudes across the tile (px = 0 at left edge); double[] longitudes = new double[Constants.TileSize]; long pixelX = checked (tileX * Constants.TileSize); for (int px = 0; px < Constants.TileSize; px++) { double x = ((pixelX + px) + 0.5) / tileSize; longitudes[px] = 360.0 * x - 180.0; } // Compute latitudes across the tile (py = 0 at top edge). double[] latitudes = new double[Constants.TileSize]; long pixelY = checked (tileY * Constants.TileSize); for (int py = 0; py < Constants.TileSize; py++) { double y = 0.5 - (((pixelY + py) + 0.5) / tileSize); latitudes[py] = 90.0 - (360.0 * Math.Atan(Math.Exp(-y * 2.0 * Math.PI)) / Math.PI); } int[] colors = new int[Constants.TileSize * Constants.TileSize]; bool hasData = false; int position = -1; for (int py = 0; py < Constants.TileSize; py++) { for (int px = 0; px < Constants.TileSize; px++) { // Map geo location to an ARGB value. Color color = this.ColorMap.GetColor(longitudes[px], latitudes[py]); // Store and update bit indicating whether actual data is present or not. position++; colors[position] = color.ToArgb(); if (hasData == false) { hasData = (color != Color.Transparent); } } } if (hasData) { TileHelper.ToBitmap(level, tileX, tileY, colors, this.TileSerializer); } colors = null; longitudes = null; latitudes = null; }
/// <summary> /// Creates the tile specified by level. /// </summary> /// <param name="level"> /// Zoom level. /// </param> /// <param name="tileX"> /// X tile coordinate. /// </param> /// <param name="tileY"> /// Y tile coordinate. /// </param> public void Create(int level, int tileX, int tileY) { // Map to convert from pixel position to global (longitude, latitude). OctTileMap tileMap = new OctTileMap(level, tileX, tileY); int[] colors = new int[Constants.TileSize * Constants.TileSize]; bool hasData = false; int position = -1; for (int pixelY = 0; pixelY < Constants.TileSize; pixelY++) { for (int pixelX = 0; pixelX < Constants.TileSize; pixelX++) { // Map pixel (u, v) position to (longitude, latitude). double u = (0.5 + pixelX) / ((double)Constants.TileSize); double v = (0.5 + pixelY) / ((double)Constants.TileSize); Vector2d location = tileMap.PointToRaDec(new Vector2d(u, v)); double latitude = location.Y; double longitude = location.X; // For Toast projection, Longitude spans from 0 to +360 and latitude from +90 to -90. // So we need to convert from -180 to +180 => 0 to +360. longitude -= 180.0; // Map geo location to an ARGB value. Color color = this.ColorMap.GetColor(longitude, latitude); // Store and update bit indicating whether actual data is present or not. position++; colors[position] = color.ToArgb(); if (hasData == false) { hasData = (color != Color.Transparent); } } } if (hasData) { TileHelper.ToBitmap(level, tileX, tileY, colors, this.TileSerializer); } colors = null; }
public static void ToBitmap(int level, int tileX, int tileY, int[] values, IImageTileSerializer serializer) { TileHelper.ToBitmap(level, tileX, tileY, values, serializer, null); }