[qt] add ResourceTransform API

This commit is contained in:
Rinigus
2017-10-07 15:56:50 +03:00
committed by Bruno de Oliveira Abinader
parent 6e7781862e
commit 965bfcfaac
3 changed files with 47 additions and 0 deletions

View File

@@ -10,6 +10,8 @@
#include <QString>
#include <QStringList>
#include <functional>
class QMapboxGLPrivate;
// This header follows the Qt coding style: https://wiki.qt.io/Qt_Coding_Style
@@ -59,6 +61,9 @@ public:
QString apiBaseUrl() const;
void setApiBaseUrl(const QString &);
std::function<std::string(const std::string &&)> resourceTransform() const;
void setResourceTransform(std::function<std::string(const std::string &&)> &);
private:
GLContextMode m_contextMode;
ConstrainMode m_constrainMode;
@@ -69,6 +74,7 @@ private:
QString m_assetPath;
QString m_accessToken;
QString m_apiBaseUrl;
std::function<std::string(const std::string &&)> m_resourceTransform;
};
struct Q_DECL_EXPORT QMapboxGLCameraOptions {

View File

@@ -29,6 +29,7 @@
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/shared_thread_pool.hpp>
#include <mbgl/util/traits.hpp>
#include <mbgl/actor/scheduler.hpp>
#if QT_VERSION >= 0x050000
#include <QGuiApplication>
@@ -361,6 +362,27 @@ void QMapboxGLSettings::setApiBaseUrl(const QString& url)
m_apiBaseUrl = url;
}
/*!
Returns resource transformation callback used to transform requested URLs.
*/
std::function<std::string(const std::string &&)> QMapboxGLSettings::resourceTransform() const
{
return m_resourceTransform;
}
/*!
Sets the resource transformation callback.
When given, resource transformation callback will be used to transform the
requested resource URLs before they are requested from internet. This can be
used add or remove custom parameters, or reroute certain requests to other
servers or endpoints.
*/
void QMapboxGLSettings::setResourceTransform(std::function<std::string(const std::string &&)> &transform)
{
m_resourceTransform = transform;
}
/*!
\class QMapboxGL
\brief The QMapboxGL class is a Qt wrapper for the Mapbox GL Native engine.
@@ -1499,6 +1521,18 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin
settings.cacheDatabaseMaximumSize()))
, threadPool(mbgl::sharedThreadPool())
{
// Setup resource transform if needed
if (settings.resourceTransform()) {
m_resourceTransform =
std::make_unique< mbgl::Actor<mbgl::ResourceTransform> >( *mbgl::Scheduler::GetCurrent(),
[callback = settings.resourceTransform()]
(mbgl::Resource::Kind , const std::string&& url_) -> std::string {
return callback(std::move(url_));
}
);
fileSourceObj->setResourceTransform(m_resourceTransform->self());
}
// Setup and connect the renderer frontend
frontend = std::make_unique<QMapboxGLRendererFrontend>(
std::make_unique<mbgl::Renderer>(*this, pixelRatio, *fileSourceObj, *threadPool,

View File

@@ -3,15 +3,19 @@
#include "qmapboxgl.hpp"
#include "qmapboxgl_renderer_frontend_p.hpp"
#include <mbgl/actor/actor.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/renderer/renderer_backend.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/storage/resource_transform.hpp>
#include <QObject>
#include <QSize>
#include <memory>
class QMapboxGLPrivate : public QObject, public mbgl::RendererBackend, public mbgl::MapObserver
{
Q_OBJECT
@@ -68,4 +72,7 @@ signals:
void needsRendering();
void mapChanged(QMapboxGL::MapChange);
void copyrightsChanged(const QString &copyrightsHtml);
private:
std::unique_ptr< mbgl::Actor<mbgl::ResourceTransform> > m_resourceTransform;
};