public void ReadHeader() { List <long> tileOffsets = new List <long>(); _mapFile.StreamReader.Position = ZoomIntervalConfig.AbsStartPositionSubFile; MinX = (int)MapFile.GetTileX((double)_mapFile.Header.MinLon, ZoomIntervalConfig.BaseZoomLevel); MaxX = (int)MapFile.GetTileX((double)_mapFile.Header.MaxLon, ZoomIntervalConfig.BaseZoomLevel); MinY = (int)MapFile.GetTileY((double)_mapFile.Header.MaxLat, ZoomIntervalConfig.BaseZoomLevel); MaxY = (int)MapFile.GetTileY((double)_mapFile.Header.MinLat, ZoomIntervalConfig.BaseZoomLevel); if (_mapFile.Header.DebugInformationPresent) { TileIndexSignature = _mapFile.ReadFixedString(16); } else { TileIndexSignature = null; } long hTiles = MaxX - MinX + 1; long vTiles = MaxY - MinY + 1; long blockCount = hTiles * vTiles; long endOfIndex = ZoomIntervalConfig.AbsStartPositionSubFile + (blockCount * 5); //tile entries byte[] buffer = new byte[8]; while (_mapFile.StreamReader.Position < endOfIndex) { Array.Clear(buffer, 0, 8); _mapFile.StreamReader.Read(buffer, 3, 5); long offset; if ((buffer[3] & 0x80) == 0x80) { //in water offset = 0; } else { offset = BitConverter.ToInt64(MapFile.ReverseBytes(buffer, 0, 8), 0); } tileOffsets.Add(offset); } _tileAbsOffsets = tileOffsets.ToArray(); }
private static double toRelTileX(double longitude, long tileX, int zoom) { return((MapFile.GetTileX(longitude / 1000000.0, zoom) - tileX) * 256.0); }