diff options
-rw-r--r-- | src/mbgl/style/style.cpp | 4 | ||||
-rw-r--r-- | test/api/custom_layer.cpp | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 010f0aeafd..b239ac20dc 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -70,7 +70,9 @@ Style::Style(FileSource& fileSource_, float pixelRatio) void Style::setJSON(const std::string& json, const std::string&) { sources.clear(); - layers.clear(); + layers.erase(std::remove_if(layers.begin(), layers.end(), [](const auto& layer) { + return !layer->template is<CustomLayer>(); + }), layers.end()); classes.clear(); StyleParser parser; diff --git a/test/api/custom_layer.cpp b/test/api/custom_layer.cpp index 4ad25bbfd5..beffa749d1 100644 --- a/test/api/custom_layer.cpp +++ b/test/api/custom_layer.cpp @@ -90,4 +90,8 @@ TEST(CustomLayer, Basic) { }, new TestLayer()); test::checkImage("test/fixtures/custom_layer/basic", test::render(map)); + + // Custom layer should be preserved when switching styles + map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), ""); + test::checkImage("test/fixtures/custom_layer/basic", test::render(map)); } |