Skip to content

Commit

Permalink
Rework style settings and make QMapLibre::Settings more future-proof
Browse files Browse the repository at this point in the history
  • Loading branch information
ntadej committed Nov 4, 2023
1 parent 80fe60e commit 1451c42
Show file tree
Hide file tree
Showing 21 changed files with 691 additions and 138 deletions.
2 changes: 1 addition & 1 deletion examples/quick/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Window {
name: "maplibre"
// specify plugin parameters if necessary
PluginParameter {
name: "maplibre.map.style_urls"
name: "maplibre.map.styles"
value: "https://demotiles.maplibre.org/style.json"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ target_sources(
renderer_backend.cpp renderer_backend_p.hpp
renderer_observer_p.hpp
scheduler.cpp scheduler_p.hpp
settings.cpp
settings.cpp settings_p.hpp
types.cpp
utils.cpp
)
Expand Down
22 changes: 8 additions & 14 deletions src/core/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,17 @@ mbgl::MapOptions mapOptionsFromSettings(const QMapLibre::Settings &settings, con
}

mbgl::ResourceOptions resourceOptionsFromSettings(const QMapLibre::Settings &settings) {
if (settings.tileServerOptions() == nullptr) {
return std::move(mbgl::ResourceOptions()
.withAssetPath(settings.assetPath().toStdString())
.withCachePath(settings.cacheDatabasePath().toStdString())
.withMaximumCacheSize(settings.cacheDatabaseMaximumSize()));
}

return std::move(mbgl::ResourceOptions()
.withApiKey(settings.apiKey().toStdString())
.withAssetPath(settings.assetPath().toStdString())
.withTileServerOptions(*settings.tileServerOptionsInternal())
.withTileServerOptions(*settings.tileServerOptions())
.withCachePath(settings.cacheDatabasePath().toStdString())
.withMaximumCacheSize(settings.cacheDatabaseMaximumSize()));
}
Expand Down Expand Up @@ -1236,14 +1243,6 @@ void Map::connectionEstablished() {
mbgl::NetworkStatus::Reachable();
}

/*!
Returns a list containing a pair of string objects, representing the style
URL and name, respectively.
*/
const QVector<QPair<QString, QString>> &Map::defaultStyles() const {
return d_ptr->defaultStyles;
}

/*!
\fn void QMapLibre::Map::needsRendering()
Expand Down Expand Up @@ -1303,11 +1302,6 @@ MapPrivate::MapPrivate(Map *q, const Settings &settings, const QSize &size, qrea
connect(m_mapObserver.get(), &MapObserver::copyrightsChanged, q, &Map::copyrightsChanged);

auto resourceOptions = resourceOptionsFromSettings(settings);
for (auto style : resourceOptions.tileServerOptions().defaultStyles()) {
defaultStyles.append(
QPair<QString, QString>(QString::fromStdString(style.getUrl()), QString::fromStdString(style.getName())));
}

auto clientOptions = clientOptionsFromSettings(settings);

// Setup the Map object.
Expand Down
2 changes: 0 additions & 2 deletions src/core/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ class Q_MAPLIBRE_CORE_EXPORT Map : public QObject {
void destroyRenderer();
void setFramebufferObject(quint32 fbo, const QSize &size);

const QVector<QPair<QString, QString>> &defaultStyles() const;

public slots:
void render();
void connectionEstablished();
Expand Down
1 change: 0 additions & 1 deletion src/core/map_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class MapPrivate : public QObject, public mbgl::RendererFrontend {

mbgl::EdgeInsets margins;
std::unique_ptr<mbgl::Map> mapObj{};
QVector<QPair<QString, QString>> defaultStyles;

public slots:
void requestRendering();
Expand Down
Loading

0 comments on commit 1451c42

Please sign in to comment.