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

marble

  • sources
  • kde-4.12
  • 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  QString urlStr = prototypeUrl.toString();
88 
89  urlStr.replace( "{zoomLevel}", QString::number( id.zoomLevel() ) );
90  urlStr.replace( "{x}", QString::number( id.x() ) );
91  urlStr.replace( "{y}", QString::number( id.y() ) );
92 
93  return QUrl( urlStr );
94 }
95 
96 QString CustomServerLayout::name() const
97 {
98  return "Custom";
99 }
100 
101 
102 WmsServerLayout::WmsServerLayout( GeoSceneTiled *texture )
103  : ServerLayout( texture )
104 {
105 }
106 
107 QUrl WmsServerLayout::downloadUrl( const QUrl &prototypeUrl, const Marble::TileId &tileId ) const
108 {
109  GeoDataLatLonBox box = tileId.toLatLonBox( m_textureLayer );
110 
111 #if QT_VERSION < 0x050000
112  QUrl url = prototypeUrl;
113 #else
114  QUrlQuery url(prototypeUrl.query());
115 #endif
116  url.addQueryItem( "service", "WMS" );
117  url.addQueryItem( "request", "GetMap" );
118  url.addQueryItem( "version", "1.1.1" );
119  if ( !url.hasQueryItem( "styles" ) )
120  url.addQueryItem( "styles", "" );
121  if ( !url.hasQueryItem( "format" ) ) {
122  if ( m_textureLayer->fileFormat().toLower() == "jpg" )
123  url.addQueryItem( "format", "image/jpeg" );
124  else
125  url.addQueryItem( "format", "image/" + m_textureLayer->fileFormat().toLower() );
126  }
127  if ( !url.hasQueryItem( "srs" ) ) {
128  url.addQueryItem( "srs", epsgCode() );
129  }
130  if ( !url.hasQueryItem( "layers" ) )
131  url.addQueryItem( "layers", m_textureLayer->name() );
132  url.addQueryItem( "width", QString::number( m_textureLayer->tileSize().width() ) );
133  url.addQueryItem( "height", QString::number( m_textureLayer->tileSize().height() ) );
134  url.addQueryItem( "bbox", QString( "%1,%2,%3,%4" ).arg( QString::number( box.west( GeoDataCoordinates::Degree ), 'f', 12 ) )
135  .arg( QString::number( box.south( GeoDataCoordinates::Degree ), 'f', 12 ) )
136  .arg( QString::number( box.east( GeoDataCoordinates::Degree ), 'f', 12 ) )
137  .arg( QString::number( box.north( GeoDataCoordinates::Degree ), 'f', 12 ) ) );
138 #if QT_VERSION < 0x050000
139  return url;
140 #else
141  QUrl finalUrl = prototypeUrl;
142  finalUrl.setQuery(url);
143  return finalUrl;
144 #endif
145 }
146 
147 QString WmsServerLayout::name() const
148 {
149  return "WebMapService";
150 }
151 
152 QString WmsServerLayout::epsgCode() const
153 {
154  switch ( m_textureLayer->projection() ) {
155  case GeoSceneTiled::Equirectangular:
156  return "EPSG:4326";
157  case GeoSceneTiled::Mercator:
158  return "EPSG:3785";
159  }
160 
161  Q_ASSERT( false ); // not reached
162  return QString();
163 }
164 
165 QuadTreeServerLayout::QuadTreeServerLayout( GeoSceneTiled *textureLayer )
166  : ServerLayout( textureLayer )
167 {
168 }
169 
170 QUrl QuadTreeServerLayout::downloadUrl( const QUrl &prototypeUrl, const Marble::TileId &id ) const
171 {
172  QString urlStr = prototypeUrl.toString();
173 
174  urlStr.replace( "{quadIndex}", encodeQuadTree( id ) );
175 
176  return QUrl( urlStr );
177 }
178 
179 QString QuadTreeServerLayout::name() const
180 {
181  return "QuadTree";
182 }
183 
184 QString QuadTreeServerLayout::encodeQuadTree( const Marble::TileId &id )
185 {
186  QString tileNum;
187 
188  for ( int i = id.zoomLevel(); i >= 0; i-- ) {
189  const int tileX = (id.x() >> i) % 2;
190  const int tileY = (id.y() >> i) % 2;
191  const int num = ( 2 * tileY ) + tileX;
192 
193  tileNum += QString::number( num );
194  }
195 
196  return tileNum;
197 }
198 
199 TmsServerLayout::TmsServerLayout(GeoSceneTiled *textureLayer )
200  : ServerLayout( textureLayer )
201 {
202 }
203 
204 QUrl TmsServerLayout::downloadUrl( const QUrl &prototypeUrl, const TileId &id ) const
205 {
206  const QString suffix = m_textureLayer->fileFormat().toLower();
207  // y coordinate in TMS start at the bottom of the map (South) and go upwards,
208  // opposed to OSM which start at the top.
209  //
210  // http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification
211  int y_frombottom = ( 1<<id.zoomLevel() ) - id.y() - 1 ;
212 
213  const QString path = QString( "%1/%2/%3.%4" ).arg( id.zoomLevel() )
214  .arg( id.x() )
215  .arg( y_frombottom )
216  .arg( suffix );
217  QUrl url = prototypeUrl;
218  url.setPath( url.path() + path );
219 
220  return url;
221 }
222 
223 QString TmsServerLayout::name() const
224 {
225  return "TileMapService";
226 }
227 
228 }
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:152
Marble::TmsServerLayout::TmsServerLayout
TmsServerLayout(GeoSceneTiled *textureLayer)
Definition: ServerLayout.cpp:199
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:223
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:107
Marble::GeoSceneTiled::projection
Projection projection() const
Definition: GeoSceneTiled.cpp:169
Marble::WmsServerLayout::WmsServerLayout
WmsServerLayout(GeoSceneTiled *texture)
Definition: ServerLayout.cpp:102
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
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
Marble::TmsServerLayout::downloadUrl
virtual QUrl downloadUrl(const QUrl &prototypeUrl, const TileId &) const
Appends zoomLevel/x/2^zoomLevel-y-1.
Definition: ServerLayout.cpp:204
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
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:147
Marble::ServerLayout
Definition: ServerLayout.h:21
Marble::GeoSceneTiled::Mercator
Definition: GeoSceneTiled.h:47
ServerLayout.h
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:170
GeoSceneTiled.h
Marble::QuadTreeServerLayout::QuadTreeServerLayout
QuadTreeServerLayout(GeoSceneTiled *textureLayer)
Definition: ServerLayout.cpp:165
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:179
Marble::GeoDataLatLonBox::south
qreal south(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the southern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:114
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:96
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-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:52 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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