Marble

TileId.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2008, 2010 Jens-Michael Hoffmann <jensmh@gmx.de>
4// SPDX-FileCopyrightText: 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
5//
6
7// Own
8#include "TileId.h"
9
10#include "GeoDataCoordinates.h"
11
12#include <QDebug>
13
14namespace Marble
15{
16
17TileId::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
22TileId::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
27TileId::TileId()
28 : m_mapThemeIdHash( 0 ), m_zoomLevel( 0 ), m_tileX( 0 ), m_tileY( 0 )
29{
30}
31
32TileId 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
62QDebug 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
KTEXTEDITOR_EXPORT size_t qHash(KTextEditor::Cursor cursor, size_t seed=0) noexcept
Binds a QML item to a specific geodetic location in screen coordinates.
QDebug operator<<(QDebug dbg, const PerceptualColor::LchaDouble &value)
QString arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.