2
// This file is part of the Marble Virtual Globe.
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
8
// Copyright 2010,2011 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
12
#include "ServerLayout.h"
14
#include "GeoSceneTexture.h"
23
ServerLayout::ServerLayout( GeoSceneTexture *textureLayer )
24
: m_textureLayer( textureLayer )
28
ServerLayout::~ServerLayout()
32
qint64 ServerLayout::numTilesX( const Marble::TileId& tileId ) const
34
return ( 1 << tileId.zoomLevel() ) * m_textureLayer->levelZeroColumns();
37
qint64 ServerLayout::numTilesY( const Marble::TileId& tileId ) const
39
return ( 1 << tileId.zoomLevel() ) * m_textureLayer->levelZeroRows();
42
MarbleServerLayout::MarbleServerLayout( GeoSceneTexture *textureLayer )
43
: ServerLayout( textureLayer )
47
QUrl MarbleServerLayout::downloadUrl( const QUrl &prototypeUrl, const TileId &id ) const
49
QUrl url = prototypeUrl;
50
url.setPath( url.path() + m_textureLayer->relativeTileFileName( id ) );
55
QString MarbleServerLayout::name() const
61
OsmServerLayout::OsmServerLayout( GeoSceneTexture *textureLayer )
62
: ServerLayout( textureLayer )
66
QUrl OsmServerLayout::downloadUrl( const QUrl &prototypeUrl, const TileId &id ) const
68
const QString suffix = m_textureLayer->fileFormat().toLower();
69
const QString path = QString( "%1/%2/%3.%4" ).arg( id.zoomLevel() )
74
QUrl url = prototypeUrl;
75
url.setPath( url.path() + path );
80
QString OsmServerLayout::name() const
82
return "OpenStreetMap";
86
CustomServerLayout::CustomServerLayout( GeoSceneTexture *texture )
87
: ServerLayout( texture )
91
QUrl CustomServerLayout::downloadUrl( const QUrl &prototypeUrl, const TileId &id ) const
93
QString urlStr = prototypeUrl.toString();
95
urlStr.replace( "{zoomLevel}", QString::number( id.zoomLevel() ) );
96
urlStr.replace( "{x}", QString::number( id.x() ) );
97
urlStr.replace( "{y}", QString::number( id.y() ) );
99
return QUrl( urlStr );
102
QString CustomServerLayout::name() const
108
WmsServerLayout::WmsServerLayout( GeoSceneTexture *texture )
109
: ServerLayout( texture )
113
QUrl WmsServerLayout::downloadUrl( const QUrl &prototypeUrl, const Marble::TileId &tileId ) const
115
const qreal radius = numTilesX( tileId ) / 2.0;
116
const qint64 x = tileId.x();
118
const qreal lonLeft = ( x - radius ) / radius * 180.0;
119
const qreal lonRight = ( x - radius + 1 ) / radius * 180.0;
121
QUrl url = prototypeUrl;
122
url.addQueryItem( "service", "WMS" );
123
url.addQueryItem( "request", "GetMap" );
124
url.addQueryItem( "version", "1.1.1" );
125
if ( !url.hasQueryItem( "styles" ) )
126
url.addQueryItem( "styles", "" );
127
if ( !url.hasQueryItem( "format" ) ) {
128
if ( m_textureLayer->fileFormat().toLower() == "jpg" )
129
url.addQueryItem( "format", "image/jpeg" );
131
url.addQueryItem( "format", "image/" + m_textureLayer->fileFormat().toLower() );
133
if ( !url.hasQueryItem( "srs" ) ) {
134
url.addQueryItem( "srs", epsgCode() );
136
if ( !url.hasQueryItem( "layers" ) )
137
url.addQueryItem( "layers", m_textureLayer->name() );
138
url.addQueryItem( "width", QString::number( m_textureLayer->tileSize().width() ) );
139
url.addQueryItem( "height", QString::number( m_textureLayer->tileSize().height() ) );
140
url.addQueryItem( "bbox", QString( "%1,%2,%3,%4" ).arg( QString::number( lonLeft, 'f', 12 ) )
141
.arg( QString::number( latBottom( tileId ), 'f', 12 ) )
142
.arg( QString::number( lonRight, 'f', 12 ) )
143
.arg( QString::number( latTop( tileId ), 'f', 12 ) ) );
148
QString WmsServerLayout::name() const
150
return "WebMapService";
153
qreal WmsServerLayout::latBottom( const Marble::TileId &tileId ) const
155
const qreal radius = numTilesY( tileId ) / 2.0;
157
switch( m_textureLayer->projection() )
159
case GeoSceneTexture::Equirectangular:
160
return ( radius - tileId.y() - 1 ) / radius * 90.0;
161
case GeoSceneTexture::Mercator:
162
return atan( sinh( ( radius - tileId.y() - 1 ) / radius * M_PI ) ) * 180.0 / M_PI;
165
Q_ASSERT( false ); // not reached
169
qreal WmsServerLayout::latTop( const Marble::TileId &tileId ) const
171
const qreal radius = numTilesY( tileId ) / 2.0;
173
switch( m_textureLayer->projection() )
175
case GeoSceneTexture::Equirectangular:
176
return ( radius - tileId.y() ) / radius * 90.0;
177
case GeoSceneTexture::Mercator:
178
return atan( sinh( ( radius - tileId.y() ) / radius * M_PI ) ) * 180.0 / M_PI;
181
Q_ASSERT( false ); // not reached
185
QString WmsServerLayout::epsgCode() const
187
switch ( m_textureLayer->projection() ) {
188
case GeoSceneTexture::Equirectangular:
190
case GeoSceneTexture::Mercator:
194
Q_ASSERT( false ); // not reached
198
QuadTreeServerLayout::QuadTreeServerLayout( GeoSceneTexture *textureLayer )
199
: ServerLayout( textureLayer )
203
QUrl QuadTreeServerLayout::downloadUrl( const QUrl &prototypeUrl, const Marble::TileId &id ) const
205
QString urlStr = prototypeUrl.toString();
207
urlStr.replace( "{quadIndex}", encodeQuadTree( id ) );
209
return QUrl( urlStr );
212
QString QuadTreeServerLayout::name() const
217
QString QuadTreeServerLayout::encodeQuadTree( const Marble::TileId &id )
221
for ( int i = id.zoomLevel(); i >= 0; i-- ) {
222
const int tileX = (id.x() >> i) % 2;
223
const int tileY = (id.y() >> i) % 2;
224
const int num = ( 2 * tileY ) + tileX;
226
tileNum += QString::number( num );