• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • lib
  • marble
TileId.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2008, 2010 Jens-Michael Hoffmann <jensmh@gmx.de>
9 // Copyright 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
10 //
11 
12 // Own
13 #include "TileId.h"
14 
15 #include <QDebug>
16 #include <QStringList>
17 
18 namespace Marble
19 {
20 
21 TileId::TileId( QString const & mapThemeId, int zoomLevel, int tileX, int tileY )
22  : m_mapThemeIdHash( qHash( mapThemeId )), m_zoomLevel( zoomLevel ), m_tileX( tileX ), m_tileY( tileY )
23 {
24 }
25 
26 TileId::TileId( uint mapThemeIdHash, int zoomLevel, int tileX, int tileY )
27  : m_mapThemeIdHash( mapThemeIdHash ), m_zoomLevel( zoomLevel ), m_tileX( tileX ), m_tileY( tileY )
28 {
29 }
30 
31 TileId::TileId()
32  : m_mapThemeIdHash( 0 ), m_zoomLevel( 0 ), m_tileX( 0 ), m_tileY( 0 )
33 {
34 }
35 
36 GeoDataLatLonBox TileId::toLatLonBox( const GeoSceneTiled *textureLayer ) const
37 {
38 
39  qreal radius = ( 1 << zoomLevel() ) * textureLayer->levelZeroColumns() / 2.0;
40 
41  qreal lonLeft = ( x() - radius ) / radius * M_PI;
42  qreal lonRight = ( x() - radius + 1 ) / radius * M_PI;
43 
44  radius = ( 1 << zoomLevel() ) * textureLayer->levelZeroRows() / 2.0;
45  qreal latTop = 0;
46  qreal latBottom = 0;
47 
48  switch ( textureLayer->projection() ) {
49  case GeoSceneTiled::Equirectangular:
50  latTop = ( radius - y() ) / radius * M_PI / 2.0;
51  latBottom = ( radius - y() - 1 ) / radius * M_PI / 2.0;
52  break;
53  case GeoSceneTiled::Mercator:
54  latTop = atan( sinh( ( radius - y() ) / radius * M_PI ) );
55  latBottom = atan( sinh( ( radius - y() - 1 ) / radius * M_PI ) );
56  break;
57  }
58 
59  return GeoDataLatLonBox( latTop, latBottom, lonRight, lonLeft );
60 }
61 
62 TileId TileId::fromCoordinates(const GeoDataCoordinates &coords, int zoomLevel)
63 {
64  if ( zoomLevel < 0 ) {
65  return TileId();
66  }
67  const int maxLat = 90 * 1000000;
68  const int maxLon = 180 * 1000000;
69  int lat = GeoDataCoordinates::normalizeLat( coords.latitude( GeoDataCoordinates::Degree ), GeoDataCoordinates::Degree ) * 1000000;
70  int lon = GeoDataCoordinates::normalizeLon( coords.longitude( GeoDataCoordinates::Degree ), GeoDataCoordinates::Degree ) * 1000000;
71  int x = 0;
72  int y = 0;
73  for( int i=0; i<zoomLevel; ++i ) {
74  const int deltaLat = maxLat >> i;
75  if( lat <= ( maxLat - deltaLat )) {
76  y += 1<<(zoomLevel-i-1);
77  lat += deltaLat;
78  }
79  const int deltaLon = maxLon >> i;
80  if( lon >= ( maxLon - deltaLon )) {
81  x += 1<<(zoomLevel-i-1);
82  } else {
83  lon += deltaLon;
84  }
85  }
86  return TileId(0, zoomLevel, x, y);
87 }
88 
89 }
90 
91 #ifndef QT_NO_DEBUG_STREAM
92 QDebug operator<<( QDebug dbg, const Marble::TileId &id )
93 {
94  return dbg << QString( "Marble::TileId(%1, %2, %3, %4)" ).arg( id.mapThemeIdHash() )
95  .arg( id.zoomLevel() )
96  .arg( id.x() )
97  .arg( id.y() );
98 }
99 #endif
TileId.h
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::GeoSceneTiled::Equirectangular
Definition: GeoSceneTiled.h:47
Marble::TileId::zoomLevel
int zoomLevel() const
Definition: TileId.h:57
Marble::qHash
uint qHash(const GeoDataLatLonAltBox &r)
Definition: GeoDataLatLonAltBox.h:149
Marble::GeoDataCoordinates::normalizeLon
static qreal normalizeLon(qreal lon, GeoDataCoordinates::Unit=GeoDataCoordinates::Radian)
normalize the longitude to always be -M_PI <= lon <= +M_PI (Radian).
Definition: GeoDataCoordinates.cpp:776
Marble::TileId::y
int y() const
Definition: TileId.h:67
Marble::GeoSceneTiled::levelZeroColumns
int levelZeroColumns() const
Definition: GeoSceneTiled.cpp:97
Marble::GeoSceneTiled
Definition: GeoSceneTiled.h:43
Marble::GeoDataCoordinates::latitude
qreal latitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
Definition: GeoDataCoordinates.cpp:751
Marble::TileId::TileId
TileId()
Definition: TileId.cpp:31
Marble::GeoSceneTiled::projection
Projection projection() const
Definition: GeoSceneTiled.cpp:169
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::radius
static qreal radius(qreal zoom)
Definition: thumbnailer.cpp:99
Marble::GeoDataCoordinates::normalizeLat
static qreal normalizeLat(qreal lat, GeoDataCoordinates::Unit=GeoDataCoordinates::Radian)
normalize latitude to always be in -M_PI / 2.
Definition: GeoDataCoordinates.cpp:799
QString
Marble::TileId::toLatLonBox
GeoDataLatLonBox toLatLonBox(const GeoSceneTiled *textureLayer) const
Definition: TileId.cpp:36
Marble::TileId::x
int x() const
Definition: TileId.h:62
Marble::GeoSceneTiled::levelZeroRows
int levelZeroRows() const
Definition: GeoSceneTiled.cpp:107
Marble::GeoDataCoordinates::longitude
qreal longitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
Definition: GeoDataCoordinates.cpp:739
Marble::GeoSceneTiled::Mercator
Definition: GeoSceneTiled.h:47
QDebug
Marble::TileId
Definition: TileId.h:27
Marble::TileId::fromCoordinates
static TileId fromCoordinates(const GeoDataCoordinates &coords, int popularity)
Definition: TileId.cpp:62
operator<<
QDebug operator<<(QDebug dbg, const Marble::TileId &id)
Definition: TileId.cpp:92
M_PI
#define M_PI
Definition: GeoDataCoordinates.h:26
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Marble::GeoDataLatLonBox
A class that defines a 2D bounding box for geographic data.
Definition: GeoDataLatLonBox.h:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:42 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal