/// <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) { // Pick the set of vertices where elevation will be computed. int[] verticesX = backslashVerticesX; int[] verticesY = backslashVerticesY; if (IsSlashQuadrant(level, tileX, tileY)) { verticesX = slashVerticesX; verticesY = slashVerticesY; } // Compute required elevations. short[] h = new short[verticesX.Length]; Vector2d pt = new Vector2d(); OctTileMap tileMap = new OctTileMap(level, tileX, tileY); for (int i = 0; i < verticesX.Length; i++) { pt.X = ((double)verticesX[i]) / VertexInterval; pt.Y = ((double)verticesY[i]) / VertexInterval; Vector2d v = tileMap.PointToRaDec(pt); h[i] = this.elevationMap.GetElevation(v.X - 180.0, v.Y); } // Save elevations. this.tileSerializer.Serialize(h, level, tileX, tileY); }
/// <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; }
/// <summary> /// Maps image pixels to lat-long values. /// </summary> /// <param name="tileMap">Tile mapper.</param> /// <param name="hasData">Boolean indicates whether the coordinates maps to valid color.</param> /// <returns>List of color values.</returns> private List<Color> MapToColors(OctTileMap tileMap, out bool hasData) { List<Color> colors = new List<Color>(Constants.TileSize * Constants.TileSize); Vector2d point = new Vector2d(); hasData = false; for (int pixelY = 0; pixelY < Constants.TileSize; pixelY++) { point.Y = ((double)pixelY + 0.5) / Constants.TileSize; for (int pixelX = 0; pixelX < Constants.TileSize; pixelX++) { point.X = ((double)pixelX + 0.5) / Constants.TileSize; var v = tileMap.PointToRaDec(point); Color color = (this.colorMap.GetColor(v.X, v.Y)); if (color != Color.Transparent) { hasData = true; } colors.Add(color); } } return colors; }
/// <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; if (this.LookAtOutsideSurface) { 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, this.ReferenceTileSerializer); } }