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))
19 , m_zoomLevel(zoomLevel)
20 , m_tileX(tileX)
21 , m_tileY(tileY)
22{
23}
24
25TileId::TileId(uint mapThemeIdHash, int zoomLevel, int tileX, int tileY)
26 : m_mapThemeIdHash(mapThemeIdHash)
27 , m_zoomLevel(zoomLevel)
28 , m_tileX(tileX)
29 , m_tileY(tileY)
30{
31}
32
33TileId::TileId()
34 : m_mapThemeIdHash(0)
35 , m_zoomLevel(0)
36 , m_tileX(0)
37 , m_tileY(0)
38{
39}
40
41TileId TileId::fromCoordinates(const GeoDataCoordinates &coords, int zoomLevel)
42{
43 if (zoomLevel < 0) {
44 return {};
45 }
46 const int maxLat = 90 * 1000000;
47 const int maxLon = 180 * 1000000;
48 int lat = GeoDataCoordinates::normalizeLat(coords.latitude(GeoDataCoordinates::Degree), GeoDataCoordinates::Degree) * 1000000;
49 int lon = GeoDataCoordinates::normalizeLon(coords.longitude(GeoDataCoordinates::Degree), GeoDataCoordinates::Degree) * 1000000;
50 int x = 0;
51 int y = 0;
52 for (int i = 0; i < zoomLevel; ++i) {
53 const int deltaLat = maxLat >> i;
54 if (lat <= (maxLat - deltaLat)) {
55 y += 1 << (zoomLevel - i - 1);
56 lat += deltaLat;
57 }
58 const int deltaLon = maxLon >> i;
59 if (lon >= (maxLon - deltaLon)) {
60 x += 1 << (zoomLevel - i - 1);
61 } else {
62 lon += deltaLon;
63 }
64 }
65 return {0, zoomLevel, x, y};
66}
67
68}
69
70#ifndef QT_NO_DEBUG_STREAM
71QDebug operator<<(QDebug dbg, const Marble::TileId &id)
72{
73 return dbg << QStringLiteral("Marble::TileId(%1, %2, %3, %4)").arg(id.mapThemeIdHash()).arg(id.zoomLevel()).arg(id.x()).arg(id.y());
74}
75#endif
KCALENDARCORE_EXPORT size_t qHash(const KCalendarCore::Period &key, size_t seed=0)
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
Binds a QML item to a specific geodetic location in screen coordinates.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:02:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.