Skip to content

Commit

Permalink
Properly handle layer ID separately (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntadej authored Jan 7, 2024
1 parent 9a8d36a commit 14943f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/core/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,19 +1039,21 @@ void Map::addCustomLayer(const QString &id, std::unique_ptr<CustomLayerHostInter
\code
QVariantMap route;
route["id"] = "route";
route["type"] = "line";
route["source"] = "routeSource";
map->addLayer(route);
map->addLayer("route", route);
\endcode
/note The source must exist prior to adding a layer.
*/
void Map::addLayer(const QString &id, const QVariantMap &params, const QString &before) {
QVariantMap parameters = params;
parameters["id"] = id;

mbgl::style::conversion::Error error;
std::optional<std::unique_ptr<mbgl::style::Layer>> layer =
mbgl::style::conversion::convert<std::unique_ptr<mbgl::style::Layer>>(QVariant(params), error);
mbgl::style::conversion::convert<std::unique_ptr<mbgl::style::Layer>>(QVariant(parameters), error);
if (!layer) {
qWarning() << "Unable to add layer with id" << id << ":" << error.message.c_str();
return;
Expand Down
1 change: 0 additions & 1 deletion src/core/style/layer_style_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ StyleAddLayer::StyleAddLayer(const Feature &feature, const std::vector<FeaturePr
StyleAddLayer::StyleAddLayer(const LayerParameter *parameter, QString before)
: m_id(parameter->styleId()),
m_before(std::move(before)) {
m_params[QStringLiteral("id")] = m_id;
m_params[QStringLiteral("type")] = parameter->type();

const QList<QByteArray> propertyNames = StyleChangeUtils::allPropertyNamesList(parameter);
Expand Down

0 comments on commit 14943f6

Please sign in to comment.