Marble

TileId.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2008, 2010 Jens-Michael Hoffmann <[email protected]>
4 // SPDX-FileCopyrightText: 2012 Bernhard Beschow <[email protected]>
5 //
6 
7 // Own
8 #include "TileId.h"
9 
10 #include "GeoDataCoordinates.h"
11 
12 #include <QDebug>
13 
14 namespace Marble
15 {
16 
17 TileId::TileId( QString const & mapThemeId, int zoomLevel, int tileX, int tileY )
18  : m_mapThemeIdHash( qHash( mapThemeId )), m_zoomLevel( zoomLevel ), m_tileX( tileX ), m_tileY( tileY )
19 {
20 }
21 
22 TileId::TileId( uint mapThemeIdHash, int zoomLevel, int tileX, int tileY )
23  : m_mapThemeIdHash( mapThemeIdHash ), m_zoomLevel( zoomLevel ), m_tileX( tileX ), m_tileY( tileY )
24 {
25 }
26 
27 TileId::TileId()
28  : m_mapThemeIdHash( 0 ), m_zoomLevel( 0 ), m_tileX( 0 ), m_tileY( 0 )
29 {
30 }
31 
32 TileId TileId::fromCoordinates(const GeoDataCoordinates &coords, int zoomLevel)
33 {
34  if ( zoomLevel < 0 ) {
35  return TileId();
36  }
37  const int maxLat = 90 * 1000000;
38  const int maxLon = 180 * 1000000;
39  int lat = GeoDataCoordinates::normalizeLat( coords.latitude( GeoDataCoordinates::Degree ), GeoDataCoordinates::Degree ) * 1000000;
40  int lon = GeoDataCoordinates::normalizeLon( coords.longitude( GeoDataCoordinates::Degree ), GeoDataCoordinates::Degree ) * 1000000;
41  int x = 0;
42  int y = 0;
43  for( int i=0; i<zoomLevel; ++i ) {
44  const int deltaLat = maxLat >> i;
45  if( lat <= ( maxLat - deltaLat )) {
46  y += 1<<(zoomLevel-i-1);
47  lat += deltaLat;
48  }
49  const int deltaLon = maxLon >> i;
50  if( lon >= ( maxLon - deltaLon )) {
51  x += 1<<(zoomLevel-i-1);
52  } else {
53  lon += deltaLon;
54  }
55  }
56  return TileId(0, zoomLevel, x, y);
57 }
58 
59 }
60 
61 #ifndef QT_NO_DEBUG_STREAM
62 QDebug operator<<( QDebug dbg, const Marble::TileId &id )
63 {
64  return dbg << QString( "Marble::TileId(%1, %2, %3, %4)" ).arg( id.mapThemeIdHash() )
65  .arg( id.zoomLevel() )
66  .arg( id.x() )
67  .arg( id.y() );
68 }
69 #endif
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
KCALENDARCORE_EXPORT uint qHash(const KCalendarCore::Period &key)
Binds a QML item to a specific geodetic location in screen coordinates.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
static qreal normalizeLat(qreal lat, GeoDataCoordinates::Unit=GeoDataCoordinates::Radian)
normalize latitude to always be in -M_PI / 2.
static qreal normalizeLon(qreal lon, GeoDataCoordinates::Unit=GeoDataCoordinates::Radian)
normalize the longitude to always be -M_PI <= lon <= +M_PI (Radian).
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Oct 3 2023 04:09:49 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.