7#include "ServerLayout.h" 
    9#include "GeoDataLatLonBox.h" 
   10#include "GeoSceneTileDataset.h" 
   11#include "MarbleGlobal.h" 
   21ServerLayout::ServerLayout(GeoSceneTileDataset *textureLayer)
 
   22    : m_textureLayer(textureLayer)
 
   26ServerLayout::~ServerLayout() = 
default;
 
   28MarbleServerLayout::MarbleServerLayout(GeoSceneTileDataset *textureLayer)
 
   29    : ServerLayout(textureLayer)
 
   33QUrl MarbleServerLayout::downloadUrl(
const QUrl &prototypeUrl, 
const TileId &
id)
 const 
   35    const QString path = QStringLiteral(
"%1/%2/%3/%3_%4.%5")
 
   40                             .
arg(m_textureLayer->fileFormat().toLower());
 
   42    QUrl url = prototypeUrl;
 
   48QString MarbleServerLayout::name()
 const 
   50    return QStringLiteral(
"Marble");
 
   53QString ServerLayout::sourceDir()
 const 
   55    return m_textureLayer ? m_textureLayer->sourceDir() : 
QString();
 
   58OsmServerLayout::OsmServerLayout(GeoSceneTileDataset *textureLayer)
 
   59    : ServerLayout(textureLayer)
 
   63QUrl OsmServerLayout::downloadUrl(
const QUrl &prototypeUrl, 
const TileId &
id)
 const 
   68    QUrl url = prototypeUrl;
 
   74QString OsmServerLayout::name()
 const 
   76    return QStringLiteral(
"OpenStreetMap");
 
   79CustomServerLayout::CustomServerLayout(GeoSceneTileDataset *texture)
 
   80    : ServerLayout(texture)
 
   84QUrl CustomServerLayout::downloadUrl(
const QUrl &prototypeUrl, 
const TileId &
id)
 const 
   86    const GeoDataLatLonBox bbox = m_textureLayer->tileProjection()->geoCoordinates(
id);
 
   95    urlStr.
replace(QStringLiteral(
"{south}"), 
QString::number(bbox.south(GeoDataCoordinates::Degree), 
'f', 12));
 
   97    urlStr.
replace(QStringLiteral(
"{north}"), 
QString::number(bbox.north(GeoDataCoordinates::Degree), 
'f', 12));
 
  102QString CustomServerLayout::name()
 const 
  104    return QStringLiteral(
"Custom");
 
  107WmsServerLayout::WmsServerLayout(GeoSceneTileDataset *texture)
 
  108    : ServerLayout(texture)
 
  112QUrl WmsServerLayout::downloadUrl(
const QUrl &prototypeUrl, 
const Marble::TileId &tileId)
 const 
  114    const GeoDataLatLonBox box = m_textureLayer->tileProjection()->geoCoordinates(tileId);
 
  117    url.addQueryItem(QStringLiteral(
"service"), QStringLiteral(
"WMS"));
 
  118    url.addQueryItem(QStringLiteral(
"request"), QStringLiteral(
"GetMap"));
 
  119    url.addQueryItem(QStringLiteral(
"version"), QStringLiteral(
"1.1.1"));
 
  120    if (!url.hasQueryItem(QStringLiteral(
"styles")))
 
  121        url.addQueryItem(QStringLiteral(
"styles"), {});
 
  122    if (!url.hasQueryItem(QStringLiteral(
"format"))) {
 
  123        url.addQueryItem(QStringLiteral(
"format"), 
QLatin1StringView(
"image/") + m_textureLayer->fileFormat().toLower());
 
  125    if (!url.hasQueryItem(QStringLiteral(
"srs"))) {
 
  126        url.addQueryItem(QStringLiteral(
"srs"), epsgCode());
 
  128    if (!url.hasQueryItem(QStringLiteral(
"layers")))
 
  129        url.addQueryItem(QStringLiteral(
"layers"), m_textureLayer->name());
 
  130    url.addQueryItem(QStringLiteral(
"width"), 
QString::number(m_textureLayer->tileSize().width()));
 
  131    url.addQueryItem(QStringLiteral(
"height"), 
QString::number(m_textureLayer->tileSize().height()));
 
  132    double west, south, east, north;
 
  133    if (m_textureLayer->tileProjectionType() == GeoSceneAbstractTileProjection::Mercator) {
 
  135        west = (box.west(GeoDataCoordinates::Degree) * 20037508.34) / 180;
 
  136        south = 20037508.34 / M_PI * log(tan(((90 + box.south(GeoDataCoordinates::Degree)) * M_PI) / 360));
 
  137        east = (box.east(GeoDataCoordinates::Degree) * 20037508.34) / 180;
 
  138        north = 20037508.34 / M_PI * log(tan(((90 + box.north(GeoDataCoordinates::Degree)) * M_PI) / 360));
 
  140        west = box.west(GeoDataCoordinates::Degree);
 
  141        south = box.south(GeoDataCoordinates::Degree);
 
  142        east = box.east(GeoDataCoordinates::Degree);
 
  143        north = box.north(GeoDataCoordinates::Degree);
 
  147        QStringLiteral(
"bbox"),
 
  148        QStringLiteral(
"%1,%2,%3,%4")
 
  149            .arg(
QString::number(west, 
'f', 12), 
QString::number(south, 
'f', 12), 
QString::number(east, 
'f', 12), 
QString::number(north, 
'f', 12)));
 
  150    QUrl finalUrl = prototypeUrl;
 
  155QString WmsServerLayout::name()
 const 
  157    return QStringLiteral(
"WebMapService");
 
  160QString WmsServerLayout::epsgCode()
 const 
  162    switch (m_textureLayer->tileProjectionType()) {
 
  163    case GeoSceneAbstractTileProjection::Equirectangular:
 
  164        return QStringLiteral(
"EPSG:4326");
 
  165    case GeoSceneAbstractTileProjection::Mercator:
 
  166        return QStringLiteral(
"EPSG:3857");
 
  173WmtsServerLayout::WmtsServerLayout(GeoSceneTileDataset *texture)
 
  174    : ServerLayout(texture)
 
  178QUrl WmtsServerLayout::downloadUrl(
const QUrl &prototypeUrl, 
const Marble::TileId &
id)
 const 
  190QString WmtsServerLayout::name()
 const 
  192    return QStringLiteral(
"WebMapTileService");
 
  195QString WmtsServerLayout::epsgCode()
 const 
  197    switch (m_textureLayer->tileProjectionType()) {
 
  198    case GeoSceneAbstractTileProjection::Equirectangular:
 
  199        return QStringLiteral(
"EPSG:4326");
 
  200    case GeoSceneAbstractTileProjection::Mercator:
 
  201        return QStringLiteral(
"EPSG:3857");
 
  208QuadTreeServerLayout::QuadTreeServerLayout(GeoSceneTileDataset *textureLayer)
 
  209    : ServerLayout(textureLayer)
 
  213QUrl QuadTreeServerLayout::downloadUrl(
const QUrl &prototypeUrl, 
const Marble::TileId &
id)
 const 
  217    urlStr.
replace(QStringLiteral(
"{quadIndex}"), encodeQuadTree(
id));
 
  222QString QuadTreeServerLayout::name()
 const 
  224    return QStringLiteral(
"QuadTree");
 
  227QString QuadTreeServerLayout::encodeQuadTree(
const Marble::TileId &
id)
 
  231    for (
int i = 
id.zoomLevel(); i >= 0; i--) {
 
  232        const int tileX = (
id.x() >> i) % 2;
 
  233        const int tileY = (
id.y() >> i) % 2;
 
  234        const int num = (2 * tileY) + tileX;
 
  242TmsServerLayout::TmsServerLayout(GeoSceneTileDataset *textureLayer)
 
  243    : ServerLayout(textureLayer)
 
  247QUrl TmsServerLayout::downloadUrl(
const QUrl &prototypeUrl, 
const TileId &
id)
 const 
  254    int y_frombottom = (1 << 
id.zoomLevel()) - 
id.y() - 1;
 
  256    const QString path = QStringLiteral(
"%1/%2/%3.%4").
arg(
id.zoomLevel()).
arg(
id.x()).
arg(y_frombottom).
arg(suffix);
 
  257    QUrl url = prototypeUrl;
 
  263QString TmsServerLayout::name()
 const 
  265    return QStringLiteral(
"TileMapService");
 
QString path(const QString &relativePath)
 
Binds a QML item to a specific geodetic location in screen coordinates.
 
QString arg(Args &&... args) const const
 
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
 
QString number(double n, char format, int precision)
 
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
 
QString toLower() const const
 
QString path(ComponentFormattingOptions options) const const
 
QString query(ComponentFormattingOptions options) const const
 
void setPath(const QString &path, ParsingMode mode)
 
void setQuery(const QString &query, ParsingMode mode)
 
QString toString(FormattingOptions options) const const