File indexing completed on 2025-01-05 03:59:37
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2008, 2010 Jens-Michael Hoffmann <jensmh@gmx.de> 0004 // SPDX-FileCopyrightText: 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de> 0005 // 0006 0007 // Own 0008 #include "TileId.h" 0009 0010 #include "GeoDataCoordinates.h" 0011 0012 #include "digikam_debug.h" 0013 0014 namespace Marble 0015 { 0016 0017 TileId::TileId( QString const & mapThemeId, int zoomLevel, int tileX, int tileY ) 0018 : m_mapThemeIdHash( qHash( mapThemeId )), m_zoomLevel( zoomLevel ), m_tileX( tileX ), m_tileY( tileY ) 0019 { 0020 } 0021 0022 TileId::TileId( uint mapThemeIdHash, int zoomLevel, int tileX, int tileY ) 0023 : m_mapThemeIdHash( mapThemeIdHash ), m_zoomLevel( zoomLevel ), m_tileX( tileX ), m_tileY( tileY ) 0024 { 0025 } 0026 0027 TileId::TileId() 0028 : m_mapThemeIdHash( 0 ), m_zoomLevel( 0 ), m_tileX( 0 ), m_tileY( 0 ) 0029 { 0030 } 0031 0032 TileId TileId::fromCoordinates(const GeoDataCoordinates &coords, int zoomLevel) 0033 { 0034 if ( zoomLevel < 0 ) { 0035 return TileId(); 0036 } 0037 const int maxLat = 90 * 1000000; 0038 const int maxLon = 180 * 1000000; 0039 int lat = GeoDataCoordinates::normalizeLat( coords.latitude( GeoDataCoordinates::Degree ), GeoDataCoordinates::Degree ) * 1000000; 0040 int lon = GeoDataCoordinates::normalizeLon( coords.longitude( GeoDataCoordinates::Degree ), GeoDataCoordinates::Degree ) * 1000000; 0041 int x = 0; 0042 int y = 0; 0043 for( int i=0; i<zoomLevel; ++i ) { 0044 const int deltaLat = maxLat >> i; 0045 if( lat <= ( maxLat - deltaLat )) { 0046 y += 1<<(zoomLevel-i-1); 0047 lat += deltaLat; 0048 } 0049 const int deltaLon = maxLon >> i; 0050 if( lon >= ( maxLon - deltaLon )) { 0051 x += 1<<(zoomLevel-i-1); 0052 } else { 0053 lon += deltaLon; 0054 } 0055 } 0056 return TileId(0, zoomLevel, x, y); 0057 } 0058 0059 } 0060 0061 #ifndef QT_NO_DEBUG_STREAM 0062 QDebug operator<<( QDebug dbg, const Marble::TileId &id ) 0063 { 0064 return dbg << QString::fromUtf8( "Marble::TileId(%1, %2, %3, %4)" ).arg( id.mapThemeIdHash() ) 0065 .arg( id.zoomLevel() ) 0066 .arg( id.x() ) 0067 .arg( id.y() ); 0068 } 0069 #endif