Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
4
#
include
"qgeotilefetchermapbox.h"
5
#
include
"qgeomapreplymapbox.h"
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
15
QT_BEGIN_NAMESPACE
16
17
QGeoTileFetcherMapbox::QGeoTileFetcherMapbox(
int
scaleFactor, QGeoTiledMappingManagerEngine *parent)
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
27
void
QGeoTileFetcherMapbox
::
setUserAgent
(
const
QByteArray &userAgent)
28
{
29
m_userAgent = userAgent;
30
}
31
32
void
QGeoTileFetcherMapbox
::
setMapIds
(
const
QList<QString> &mapIds)
33
{
34
m_mapIds = mapIds;
35
}
36
37
void
QGeoTileFetcherMapbox
::
setFormat
(
const
QString &format)
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
49
void
QGeoTileFetcherMapbox
::
setAccessToken
(
const
QString &accessToken)
50
{
51
m_accessToken = accessToken;
52
}
53
54
QGeoTiledMapReply
*
QGeoTileFetcherMapbox
::
getTileImage
(
const
QGeoTileSpec &spec)
55
{
56
QNetworkRequest request;
57
request.setRawHeader(
"User-Agent"
, m_userAgent);
58
59
request.setUrl(QUrl(mapboxTilesApiPath +
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
73
QT_END_NAMESPACE
QGeoTileFetcherMapbox
Definition
qgeotilefetchermapbox.h:16
QGeoTileFetcherMapbox::setMapIds
void setMapIds(const QList< QString > &mapIds)
Definition
qgeotilefetchermapbox.cpp:32
QGeoTileFetcherMapbox::setAccessToken
void setAccessToken(const QString &accessToken)
Definition
qgeotilefetchermapbox.cpp:49
QGeoTileFetcherMapbox::setUserAgent
void setUserAgent(const QByteArray &userAgent)
Definition
qgeotilefetchermapbox.cpp:27
QGeoTileFetcherMapbox::getTileImage
QGeoTiledMapReply * getTileImage(const QGeoTileSpec &spec) override
Definition
qgeotilefetchermapbox.cpp:54
QGeoTileFetcherMapbox::setFormat
void setFormat(const QString &format)
Definition
qgeotilefetchermapbox.cpp:37
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtlocation
src
plugins
geoservices
mapbox
qgeotilefetchermapbox.cpp
Generated on
for Qt by
1.18.0