Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qgeotilefetchermapbox.cpp
Go to the documentation of this file.
1// Copyright (C) 2014 Canonical Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6#include "qmapboxcommon.h"
7
8#include <QtNetwork/QNetworkAccessManager>
9#include <QtNetwork/QNetworkRequest>
10#include <QtLocation/private/qgeotilefetcher_p.h>
11#include <QtLocation/private/qgeotiledmappingmanagerengine_p.h>
12#include <QtLocation/private/qgeotilespec_p.h>
13#include <QDebug>
14
16
18: QGeoTileFetcher(parent), m_networkManager(new QNetworkAccessManager(this)),
19 m_userAgent(mapboxDefaultUserAgent),
20 m_format("png"),
21 m_replyFormat("png"),
22 m_accessToken("")
23{
24 m_scaleFactor = qBound(1, scaleFactor, 2);
25}
26
28{
29 m_userAgent = userAgent;
30}
31
32void QGeoTileFetcherMapbox::setMapIds(const QList<QString> &mapIds)
33{
34 m_mapIds = mapIds;
35}
36
38{
39 m_format = format;
40
41 if (m_format == "png" || m_format == "png32" || m_format == "png64" || m_format == "png128" || m_format == "png256")
42 m_replyFormat = "png";
43 else if (m_format == "jpg70" || m_format == "jpg80" || m_format == "jpg90")
44 m_replyFormat = "jpg";
45 else
46 qWarning() << "Unknown map format " << m_format;
47}
48
50{
51 m_accessToken = accessToken;
52}
53
55{
57 request.setRawHeader("User-Agent", m_userAgent);
58
60 ((spec.mapId() >= m_mapIds.size()) ? QStringLiteral("mapbox.streets") : m_mapIds[spec.mapId() - 1]) + QLatin1Char('/') +
61 QString::number(spec.zoom()) + QLatin1Char('/') +
62 QString::number(spec.x()) + QLatin1Char('/') +
63 QString::number(spec.y()) +
64 ((m_scaleFactor > 1) ? (QLatin1Char('@') + QString::number(m_scaleFactor) + QLatin1String("x.")) : QLatin1String(".")) +
65 m_format + QLatin1Char('?') +
66 QStringLiteral("access_token=") + m_accessToken));
67
68 QNetworkReply *reply = m_networkManager->get(request);
69
70 return new QGeoMapReplyMapbox(reply, spec, m_replyFormat);
71}
72
\inmodule QtCore
Definition qbytearray.h:57
QGeoTileFetcherMapbox(int scaleFactor, QGeoTiledMappingManagerEngine *parent)
void setMapIds(const QList< QString > &mapIds)
void setAccessToken(const QString &accessToken)
void setUserAgent(const QByteArray &userAgent)
QGeoTiledMapReply * getTileImage(const QGeoTileSpec &spec) override
void setFormat(const QString &format)
int x() const
int zoom() const
int mapId() const
int y() const
\inmodule QtLocation
qsizetype size() const noexcept
Definition qlist.h:397
The QNetworkAccessManager class allows the application to send network requests and receive replies.
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
void setRawHeader(const QByteArray &headerName, const QByteArray &value)
Sets the header headerName to be of value headerValue.
void setUrl(const QUrl &url)
Sets the URL this network request is referring to be url.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:8084
\inmodule QtCore
Definition qurl.h:94
#define this
Definition dialogs.cpp:9
Combined button and popup list for selecting options.
#define qWarning
Definition qlogging.h:166
static const QByteArray mapboxDefaultUserAgent
static QT_BEGIN_NAMESPACE const QString mapboxTilesApiPath
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
GLint GLsizei GLsizei GLenum format
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
QNetworkRequest request(url)
QNetworkReply * reply
\inmodule QtCore \reentrant
Definition qchar.h:18