• 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
ServerLayout.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 2010,2011 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
9 //
10 
11 // Own
12 #include "ServerLayout.h"
13 
14 #include "GeoSceneTiled.h"
15 #include "MarbleGlobal.h"
16 #include "TileId.h"
17 
18 #if QT_VERSION >= 0x050000
19 #include <QUrlQuery>
20 #endif
21 
22 #include <math.h>
23 
24 namespace Marble
25 {
26 
27 ServerLayout::ServerLayout( GeoSceneTiled *textureLayer )
28  : m_textureLayer( textureLayer )
29 {
30 }
31 
32 ServerLayout::~ServerLayout()
33 {
34 }
35 
36 MarbleServerLayout::MarbleServerLayout( GeoSceneTiled *textureLayer )
37  : ServerLayout( textureLayer )
38 {
39 }
40 
41 QUrl MarbleServerLayout::downloadUrl( const QUrl &prototypeUrl, const TileId &id ) const
42 {
43  QUrl url = prototypeUrl;
44  url.setPath( url.path() + m_textureLayer->relativeTileFileName( id ) );
45 
46  return url;
47 }
48 
49 QString MarbleServerLayout::name() const
50 {
51  return "Marble";
52 }
53 
54 
55 OsmServerLayout::OsmServerLayout( GeoSceneTiled *textureLayer )
56  : ServerLayout( textureLayer )
57 {
58 }
59 
60 QUrl OsmServerLayout::downloadUrl( const QUrl &prototypeUrl, const TileId &id ) const
61 {
62  const QString suffix = m_textureLayer->fileFormat().toLower();
63  const QString path = QString( "%1/%2/%3.%4" ).arg( id.zoomLevel() )
64  .arg( id.x() )
65  .arg( id.y() )
66  .arg( suffix );
67 
68  QUrl url = prototypeUrl;
69  url.setPath( url.path() + path );
70 
71  return url;
72 }
73 
74 QString OsmServerLayout::name() const
75 {
76  return "OpenStreetMap";
77 }
78 
79 
80 CustomServerLayout::CustomServerLayout( GeoSceneTiled *texture )
81  : ServerLayout( texture )
82 {
83 }
84 
85 QUrl CustomServerLayout::downloadUrl( const QUrl &prototypeUrl, const TileId &id ) const
86 {
87 #if QT_VERSION < 0x050000
88  QString urlStr = prototypeUrl.toString();
89 #else
90  QString urlStr = prototypeUrl.toString( QUrl::DecodeReserved );
91 #endif
92 
93  urlStr.replace( "{zoomLevel}", QString::number( id.zoomLevel() ) );
94  urlStr.replace( "{x}", QString::number( id.x() ) );
95  urlStr.replace( "{y}", QString::number( id.y() ) );
96 
97  return QUrl( urlStr );
98 }
99 
100 QString CustomServerLayout::name() const
101 {
102  return "Custom";
103 }
104 
105 
106 WmsServerLayout::WmsServerLayout( GeoSceneTiled *texture )
107  : ServerLayout( texture )
108 {
109 }
110 
111 QUrl WmsServerLayout::downloadUrl( const QUrl &prototypeUrl, const Marble::TileId &tileId ) const
112 {
113  GeoDataLatLonBox box = tileId.toLatLonBox( m_textureLayer );
114 
115 #if QT_VERSION < 0x050000
116  QUrl url = prototypeUrl;
117 #else
118  QUrlQuery url(prototypeUrl.query());
119 #endif
120  url.addQueryItem( "service", "WMS" );
121  url.addQueryItem( "request", "GetMap" );
122  url.addQueryItem( "version", "1.1.1" );
123  if ( !url.hasQueryItem( "styles" ) )
124  url.addQueryItem( "styles", "" );
125  if ( !url.hasQueryItem( "format" ) ) {
126  if ( m_textureLayer->fileFormat().toLower() == "jpg" )
127  url.addQueryItem( "format", "image/jpeg" );
128  else
129  url.addQueryItem( "format", "image/" + m_textureLayer->fileFormat().toLower() );
130  }
131  if ( !url.hasQueryItem( "srs" ) ) {
132  url.addQueryItem( "srs", epsgCode() );
133  }
134  if ( !url.hasQueryItem( "layers" ) )
135  url.addQueryItem( "layers", m_textureLayer->name() );
136  url.addQueryItem( "width", QString::number( m_textureLayer->tileSize().width() ) );
137  url.addQueryItem( "height", QString::number( m_textureLayer->tileSize().height() ) );
138  url.addQueryItem( "bbox", QString( "%1,%2,%3,%4" ).arg( QString::number( box.west( GeoDataCoordinates::Degree ), 'f', 12 ) )
139  .arg( QString::number( box.south( GeoDataCoordinates::Degree ), 'f', 12 ) )
140  .arg( QString::number( box.east( GeoDataCoordinates::Degree ), 'f', 12 ) )
141  .arg( QString::number( box.north( GeoDataCoordinates::Degree ), 'f', 12 ) ) );
142 #if QT_VERSION < 0x050000
143  return url;
144 #else
145  QUrl finalUrl = prototypeUrl;
146  finalUrl.setQuery(url);
147  return finalUrl;
148 #endif
149 }
150 
151 QString WmsServerLayout::name() const
152 {
153  return "WebMapService";
154 }
155 
156 QString WmsServerLayout::epsgCode() const
157 {
158  switch ( m_textureLayer->projection() ) {
159  case GeoSceneTiled::Equirectangular:
160  return "EPSG:4326";
161  case GeoSceneTiled::Mercator:
162  return "EPSG:3785";
163  }
164 
165  Q_ASSERT( false ); // not reached
166  return QString();
167 }
168 
169 QuadTreeServerLayout::QuadTreeServerLayout( GeoSceneTiled *textureLayer )
170  : ServerLayout( textureLayer )
171 {
172 }
173 
174 QUrl QuadTreeServerLayout::downloadUrl( const QUrl &prototypeUrl, const Marble::TileId &id ) const
175 {
176 #if QT_VERSION < 0x050000
177  QString urlStr = prototypeUrl.toString();
178 #else
179  QString urlStr = prototypeUrl.toString( QUrl::DecodeReserved );
180 #endif
181 
182  urlStr.replace( "{quadIndex}", encodeQuadTree( id ) );
183 
184  return QUrl( urlStr );
185 }
186 
187 QString QuadTreeServerLayout::name() const
188 {
189  return "QuadTree";
190 }
191 
192 QString QuadTreeServerLayout::encodeQuadTree( const Marble::TileId &id )
193 {
194  QString tileNum;
195 
196  for ( int i = id.zoomLevel(); i >= 0; i-- ) {
197  const int tileX = (id.x() >> i) % 2;
198  const int tileY = (id.y() >> i) % 2;
199  const int num = ( 2 * tileY ) + tileX;
200 
201  tileNum += QString::number( num );
202  }
203 
204  return tileNum;
205 }
206 
207 TmsServerLayout::TmsServerLayout(GeoSceneTiled *textureLayer )
208  : ServerLayout( textureLayer )
209 {
210 }
211 
212 QUrl TmsServerLayout::downloadUrl( const QUrl &prototypeUrl, const TileId &id ) const
213 {
214  const QString suffix = m_textureLayer->fileFormat().toLower();
215  // y coordinate in TMS start at the bottom of the map (South) and go upwards,
216  // opposed to OSM which start at the top.
217  //
218  // http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification
219  int y_frombottom = ( 1<<id.zoomLevel() ) - id.y() - 1 ;
220 
221  const QString path = QString( "%1/%2/%3.%4" ).arg( id.zoomLevel() )
222  .arg( id.x() )
223  .arg( y_frombottom )
224  .arg( suffix );
225  QUrl url = prototypeUrl;
226  url.setPath( url.path() + path );
227 
228  return url;
229 }
230 
231 QString TmsServerLayout::name() const
232 {
233  return "TileMapService";
234 }
235 
236 }
Marble::GeoSceneTiled::relativeTileFileName
QString relativeTileFileName(const TileId &) const
Definition: GeoSceneTiled.cpp:204
TileId.h
Marble::GeoSceneTiled::Equirectangular
Definition: GeoSceneTiled.h:47
Marble::WmsServerLayout::epsgCode
QString epsgCode() const
Definition: ServerLayout.cpp:156
QUrl::setQuery
void setQuery(const QString &txt)
QSize::width
int width() const
Marble::TmsServerLayout::TmsServerLayout
TmsServerLayout(GeoSceneTiled *textureLayer)
Definition: ServerLayout.cpp:207
Marble::ServerLayout::ServerLayout
ServerLayout(GeoSceneTiled *textureLayer)
Definition: ServerLayout.cpp:27
Marble::TmsServerLayout::name
virtual QString name() const
Returns the name of the server layout to be used as the value in the mode attribute in the DGML file...
Definition: ServerLayout.cpp:231
Marble::ServerLayout::~ServerLayout
virtual ~ServerLayout()
Definition: ServerLayout.cpp:32
Marble::ServerLayout::m_textureLayer
GeoSceneTiled *const m_textureLayer
Definition: ServerLayout.h:44
Marble::OsmServerLayout::name
virtual QString name() const
Returns the name of the server layout to be used as the value in the mode attribute in the DGML file...
Definition: ServerLayout.cpp:74
Marble::GeoSceneAbstractDataset::fileFormat
QString fileFormat() const
Definition: GeoSceneAbstractDataset.cpp:43
Marble::GeoSceneTiled
Definition: GeoSceneTiled.h:43
Marble::WmsServerLayout::downloadUrl
virtual QUrl downloadUrl(const QUrl &prototypeUrl, const Marble::TileId &tileId) const
Adds WMS query items to the prototypeUrl and returns the result.
Definition: ServerLayout.cpp:111
QUrl::hasQueryItem
bool hasQueryItem(const QString &key) const
Marble::GeoSceneTiled::projection
Projection projection() const
Definition: GeoSceneTiled.cpp:169
QUrl::toString
QString toString(QFlags< QUrl::FormattingOption > options) const
Marble::WmsServerLayout::WmsServerLayout
WmsServerLayout(GeoSceneTiled *texture)
Definition: ServerLayout.cpp:106
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::CustomServerLayout::downloadUrl
virtual QUrl downloadUrl(const QUrl &prototypeUrl, const TileId &id) const
Replaces escape sequences in the prototypeUrl by the values in id and returns the result...
Definition: ServerLayout.cpp:85
Marble::GeoSceneAbstractDataset::name
QString name() const
Definition: GeoSceneAbstractDataset.cpp:38
QUrl::setPath
void setPath(const QString &path)
Marble::OsmServerLayout::OsmServerLayout
OsmServerLayout(GeoSceneTiled *textureLayer)
Definition: ServerLayout.cpp:55
Marble::GeoDataLatLonBox::north
qreal north(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the northern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:93
Marble::GeoDataLatLonBox::east
qreal east(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the eastern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:135
QString::number
QString number(int n, int base)
Marble::TmsServerLayout::downloadUrl
virtual QUrl downloadUrl(const QUrl &prototypeUrl, const TileId &) const
Appends zoomLevel/x/2^zoomLevel-y-1.
Definition: ServerLayout.cpp:212
Marble::OsmServerLayout::downloadUrl
virtual QUrl downloadUrl(const QUrl &prototypeUrl, const TileId &) const
Appends zoomLevel/x/y.
Definition: ServerLayout.cpp:60
Marble::MarbleServerLayout::name
virtual QString name() const
Returns the name of the server layout to be used as the value in the mode attribute in the DGML file...
Definition: ServerLayout.cpp:49
QUrl::path
QString path() const
QString
MarbleGlobal.h
Marble::TileId::toLatLonBox
GeoDataLatLonBox toLatLonBox(const GeoSceneTiled *textureLayer) const
Definition: TileId.cpp:36
Marble::WmsServerLayout::name
virtual QString name() const
Returns the name of the server layout to be used as the value in the mode attribute in the DGML file...
Definition: ServerLayout.cpp:151
QString::toLower
QString toLower() const
Marble::ServerLayout
Definition: ServerLayout.h:21
Marble::GeoSceneTiled::Mercator
Definition: GeoSceneTiled.h:47
QUrl
ServerLayout.h
QString::replace
QString & replace(int position, int n, QChar after)
Marble::GeoSceneTiled::tileSize
const QSize tileSize() const
Definition: GeoSceneTiled.cpp:132
Marble::GeoDataLatLonBox::west
qreal west(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the western boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:156
Marble::TileId
Definition: TileId.h:27
Marble::MarbleServerLayout::downloadUrl
virtual QUrl downloadUrl(const QUrl &prototypeUrl, const TileId &) const
Completes the path of the prototypeUrl and returns it.
Definition: ServerLayout.cpp:41
Marble::QuadTreeServerLayout::downloadUrl
virtual QUrl downloadUrl(const QUrl &, const Marble::TileId &) const
Translates given tile id using a prototypeUrl into an URL that can be used for downloading.
Definition: ServerLayout.cpp:174
GeoSceneTiled.h
Marble::QuadTreeServerLayout::QuadTreeServerLayout
QuadTreeServerLayout(GeoSceneTiled *textureLayer)
Definition: ServerLayout.cpp:169
Marble::QuadTreeServerLayout::name
virtual QString name() const
Returns the name of the server layout to be used as the value in the mode attribute in the DGML file...
Definition: ServerLayout.cpp:187
Marble::GeoDataLatLonBox::south
qreal south(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the southern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:114
QSize::height
int height() const
QUrl::addQueryItem
void addQueryItem(const QString &key, const QString &value)
Marble::CustomServerLayout::name
virtual QString name() const
Returns the name of the server layout to be used as the value in the mode attribute in the DGML file...
Definition: ServerLayout.cpp:100
QUrl::query
QString query() const
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Marble::MarbleServerLayout::MarbleServerLayout
MarbleServerLayout(GeoSceneTiled *textureLayer)
Definition: ServerLayout.cpp:36
Marble::CustomServerLayout::CustomServerLayout
CustomServerLayout(GeoSceneTiled *texture)
Definition: ServerLayout.cpp:80
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:41 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