summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-06-20 17:12:58 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-06-22 08:04:39 -0700
commit40e47556214e999c952c1e88e026d673cdd96c72 (patch)
treee8d15795cbecc07c94908a8ebed31b73def64614
parent1520a56813f82bbe875774fdc2b3df26392278d6 (diff)
downloadqtlocation-mapboxgl-40e47556214e999c952c1e88e026d673cdd96c72.tar.gz
[core] Move setStyleJSON/URL to Style; add Map::setStyle
-rw-r--r--benchmark/api/query.benchmark.cpp2
-rw-r--r--bin/render.cpp3
-rw-r--r--include/mbgl/map/map.hpp8
-rw-r--r--include/mbgl/style/style.hpp6
-rwxr-xr-xplatform/android/src/native_map_view.cpp8
-rw-r--r--platform/darwin/src/MGLStyle.mm2
-rw-r--r--platform/glfw/main.cpp5
-rw-r--r--platform/ios/src/MGLMapView.mm6
-rw-r--r--platform/macos/src/MGLMapView.mm9
-rw-r--r--platform/node/src/node_map.cpp6
-rw-r--r--platform/qt/src/qmapboxgl.cpp8
-rw-r--r--src/mbgl/map/map.cpp114
-rw-r--r--src/mbgl/style/observer.hpp3
-rw-r--r--src/mbgl/style/style.cpp16
-rw-r--r--src/mbgl/style/style_impl.cpp80
-rw-r--r--src/mbgl/style/style_impl.hpp16
-rw-r--r--test/api/annotations.test.cpp51
-rw-r--r--test/api/custom_layer.test.cpp2
-rw-r--r--test/api/query.test.cpp2
-rw-r--r--test/api/render_missing.test.cpp3
-rw-r--r--test/api/repeated_render.test.cpp5
-rw-r--r--test/map/map.test.cpp46
-rw-r--r--test/style/style.test.cpp16
-rw-r--r--test/style/style_layer.test.cpp2
-rw-r--r--test/util/memory.test.cpp7
25 files changed, 219 insertions, 207 deletions
diff --git a/benchmark/api/query.benchmark.cpp b/benchmark/api/query.benchmark.cpp
index 5d4e48fbe0..05732e0e9a 100644
--- a/benchmark/api/query.benchmark.cpp
+++ b/benchmark/api/query.benchmark.cpp
@@ -24,7 +24,7 @@ public:
NetworkStatus::Set(NetworkStatus::Status::Offline);
fileSource.setAccessToken("foobar");
- map.setStyleJSON(util::read_file("benchmark/fixtures/api/query_style.json"));
+ map.getStyle().loadJSON(util::read_file("benchmark/fixtures/api/query_style.json"));
map.setLatLngZoom({ 40.726989, -73.992857 }, 15); // Manhattan
map.getStyle().addImage(std::make_unique<style::Image>("test-icon",
decodeImage(util::read_file("benchmark/fixtures/api/default_marker.png")), 1.0));
diff --git a/bin/render.cpp b/bin/render.cpp
index 82d851d015..51c6faef56 100644
--- a/bin/render.cpp
+++ b/bin/render.cpp
@@ -7,6 +7,7 @@
#include <mbgl/gl/offscreen_view.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/storage/default_file_source.hpp>
+#include <mbgl/style/style.hpp>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
@@ -93,7 +94,7 @@ int main(int argc, char *argv[]) {
style_path = std::string("file://") + style_path;
}
- map.setStyleURL(style_path);
+ map.getStyle().loadURL(style_path);
map.setLatLngZoom({ lat, lon }, zoom);
map.setBearing(bearing);
map.setPitch(pitch);
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 85c95d6491..dd29d444bd 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -55,15 +55,11 @@ public:
// Main render function.
void render(View&);
- // Style
- void setStyleURL(const std::string&);
- void setStyleJSON(const std::string&);
- std::string getStyleURL() const;
- std::string getStyleJSON() const;
-
style::Style& getStyle();
const style::Style& getStyle() const;
+ void setStyle(std::unique_ptr<style::Style>);
+
// Transition
void cancelTransitions();
void setGestureInProgress(bool);
diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp
index 82ff1b3078..cb84922b4d 100644
--- a/include/mbgl/style/style.hpp
+++ b/include/mbgl/style/style.hpp
@@ -24,6 +24,12 @@ public:
Style(Scheduler&, FileSource&, float pixelRatio);
~Style();
+ void loadJSON(const std::string&);
+ void loadURL(const std::string&);
+
+ std::string getJSON() const;
+ std::string getURL() const;
+
// Defaults
std::string getName() const;
LatLng getDefaultLatLng() const;
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index e09a58d25f..13d5be01b9 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -344,19 +344,19 @@ void NativeMapView::resizeFramebuffer(jni::JNIEnv&, int w, int h) {
}
jni::String NativeMapView::getStyleUrl(jni::JNIEnv& env) {
- return jni::Make<jni::String>(env, map->getStyleURL());
+ return jni::Make<jni::String>(env, map->getStyle().getURL());
}
void NativeMapView::setStyleUrl(jni::JNIEnv& env, jni::String url) {
- map->setStyleURL(jni::Make<std::string>(env, url));
+ map->getStyle().loadURL(jni::Make<std::string>(env, url));
}
jni::String NativeMapView::getStyleJson(jni::JNIEnv& env) {
- return jni::Make<jni::String>(env, map->getStyleJSON());
+ return jni::Make<jni::String>(env, map->getStyle().getJSON());
}
void NativeMapView::setStyleJson(jni::JNIEnv& env, jni::String json) {
- map->setStyleJSON(jni::Make<std::string>(env, json));
+ map->getStyle().loadJSON(jni::Make<std::string>(env, json));
}
void NativeMapView::setLatLngBounds(jni::JNIEnv& env, jni::Object<mbgl::android::LatLngBounds> jBounds) {
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm
index 6d9a12c3e0..2365641f02 100644
--- a/platform/darwin/src/MGLStyle.mm
+++ b/platform/darwin/src/MGLStyle.mm
@@ -124,7 +124,7 @@ static NSURL *MGLStyleURL_emerald;
}
- (NSURL *)URL {
- return [NSURL URLWithString:@(self.mapView.mbglMap->getStyleURL().c_str())];
+ return [NSURL URLWithString:@(self.rawStyle->getURL().c_str())];
}
- (NSString *)name {
diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp
index 97c77b3742..7192475835 100644
--- a/platform/glfw/main.cpp
+++ b/platform/glfw/main.cpp
@@ -6,6 +6,7 @@
#include <mbgl/util/platform.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/storage/default_file_source.hpp>
+#include <mbgl/style/style.hpp>
#include <csignal>
#include <getopt.h>
@@ -147,7 +148,7 @@ int main(int argc, char *argv[]) {
}
mbgl::util::default_styles::DefaultStyle newStyle = mbgl::util::default_styles::orderedStyles[currentStyleIndex];
- map.setStyleURL(newStyle.url);
+ map.getStyle().loadURL(newStyle.url);
view->setWindowTitle(newStyle.name);
mbgl::Log::Info(mbgl::Event::Setup, "Changed style to: %s", newStyle.name);
@@ -178,7 +179,7 @@ int main(int argc, char *argv[]) {
}
}
- map.setStyleURL(style);
+ map.getStyle().loadURL(style);
view->run();
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 0d00fe75fb..6c6d8d2980 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -373,7 +373,7 @@ public:
- (nonnull NSURL *)styleURL
{
- NSString *styleURLString = @(_mbglMap->getStyleURL().c_str()).mgl_stringOrNilIfEmpty;
+ NSString *styleURLString = @(_mbglMap->getStyle().getURL().c_str()).mgl_stringOrNilIfEmpty;
NSAssert(styleURLString || _isTargetingInterfaceBuilder, @"Invalid style URL string %@", styleURLString);
return styleURLString ? [NSURL URLWithString:styleURLString] : nil;
}
@@ -389,12 +389,12 @@ public:
styleURL = styleURL.mgl_URLByStandardizingScheme;
self.style = nil;
- _mbglMap->setStyleURL([[styleURL absoluteString] UTF8String]);
+ _mbglMap->getStyle().loadURL([[styleURL absoluteString] UTF8String]);
}
- (IBAction)reloadStyle:(__unused id)sender {
NSURL *styleURL = self.styleURL;
- _mbglMap->setStyleURL("");
+ _mbglMap->getStyle().loadURL("");
self.styleURL = styleURL;
}
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 756f237fba..0a567a8510 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -24,6 +24,7 @@
#import <mbgl/map/map.hpp>
#import <mbgl/map/view.hpp>
+#import <mbgl/style/style.hpp>
#import <mbgl/annotation/annotation.hpp>
#import <mbgl/map/camera.hpp>
#import <mbgl/storage/reachability.h>
@@ -239,7 +240,7 @@ public:
// If the Style URL inspectable was not set, make sure to go through
// -setStyleURL: to load the default style.
- if (_mbglMap->getStyleURL().empty()) {
+ if (_mbglMap->getStyle().getURL().empty()) {
self.styleURL = nil;
}
}
@@ -607,7 +608,7 @@ public:
}
- (nonnull NSURL *)styleURL {
- NSString *styleURLString = @(_mbglMap->getStyleURL().c_str()).mgl_stringOrNilIfEmpty;
+ NSString *styleURLString = @(_mbglMap->getStyle().getURL().c_str()).mgl_stringOrNilIfEmpty;
return styleURLString ? [NSURL URLWithString:styleURLString] : [MGLStyle streetsStyleURLWithVersion:MGLStyleDefaultVersion];
}
@@ -629,12 +630,12 @@ public:
styleURL = styleURL.mgl_URLByStandardizingScheme;
self.style = nil;
- _mbglMap->setStyleURL(styleURL.absoluteString.UTF8String);
+ _mbglMap->getStyle().loadURL(styleURL.absoluteString.UTF8String);
}
- (IBAction)reloadStyle:(__unused id)sender {
NSURL *styleURL = self.styleURL;
- _mbglMap->setStyleURL("");
+ _mbglMap->getStyle().loadURL("");
self.styleURL = styleURL;
}
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index 324b53f843..9ba88193c9 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -214,7 +214,7 @@ void NodeMap::Load(const Nan::FunctionCallbackInfo<v8::Value>& info) {
}
try {
- nodeMap->map->setStyleJSON(style);
+ nodeMap->map->getStyle().loadJSON(style);
} catch (const std::exception &ex) {
return Nan::ThrowError(ex.what());
}
@@ -528,7 +528,7 @@ void NodeMap::Cancel(const Nan::FunctionCallbackInfo<v8::Value>& info) {
}
void NodeMap::cancel() {
- auto style = map->getStyleJSON();
+ auto style = map->getStyle().getJSON();
map = std::make_unique<mbgl::Map>(backend, mbgl::Size{ 256, 256 },
pixelRatio, *this, threadpool, mbgl::MapMode::Still);
@@ -536,7 +536,7 @@ void NodeMap::cancel() {
// FIXME: Reload the style after recreating the map. We need to find
// a better way of canceling an ongoing rendering on the core level
// without resetting the map, which is way too expensive.
- map->setStyleJSON(style);
+ map->getStyle().loadJSON(style);
error = std::make_exception_ptr(std::runtime_error("Canceled"));
renderFinished();
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index cb48308682..f094e2a0ec 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -475,12 +475,12 @@ void QMapboxGL::cycleDebugOptions()
*/
QString QMapboxGL::styleJson() const
{
- return QString::fromStdString(d_ptr->mapObj->getStyleJSON());
+ return QString::fromStdString(d_ptr->mapObj->getStyle().getJSON());
}
void QMapboxGL::setStyleJson(const QString &style)
{
- d_ptr->mapObj->setStyleJSON(style.toStdString());
+ d_ptr->mapObj->getStyle().loadJSON(style.toStdString());
}
/*!
@@ -500,12 +500,12 @@ void QMapboxGL::setStyleJson(const QString &style)
*/
QString QMapboxGL::styleUrl() const
{
- return QString::fromStdString(d_ptr->mapObj->getStyleURL());
+ return QString::fromStdString(d_ptr->mapObj->getStyle().getURL());
}
void QMapboxGL::setStyleUrl(const QString &url)
{
- d_ptr->mapObj->setStyleURL(url.toStdString());
+ d_ptr->mapObj->getStyle().loadURL(url.toStdString());
}
/*!
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 3aed91cda4..37442770fa 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -13,9 +13,6 @@
#include <mbgl/renderer/render_source.hpp>
#include <mbgl/renderer/render_style.hpp>
#include <mbgl/renderer/render_style_observer.hpp>
-#include <mbgl/storage/file_source.hpp>
-#include <mbgl/storage/resource.hpp>
-#include <mbgl/storage/response.hpp>
#include <mbgl/util/exception.hpp>
#include <mbgl/util/math.hpp>
#include <mbgl/util/exception.hpp>
@@ -63,6 +60,7 @@ public:
void onSourceChanged(style::Source&) override;
void onUpdate(Update) override;
void onInvalidate() override;
+ void onStyleLoading() override;
void onStyleLoaded() override;
void onStyleError(std::exception_ptr) override;
void onResourceError(std::exception_ptr) override;
@@ -70,8 +68,6 @@ public:
void render(View&);
void renderStill();
- void loadStyleJSON(const std::string&);
-
Map& map;
MapObserver& observer;
Backend& backend;
@@ -95,12 +91,8 @@ public:
std::unique_ptr<Style> style;
std::unique_ptr<RenderStyle> renderStyle;
- std::string styleURL;
- std::string styleJSON;
bool cameraMutated = false;
- std::unique_ptr<AsyncRequest> styleRequest;
-
size_t sourceCacheSize;
bool loading = false;
@@ -167,8 +159,6 @@ Map::Impl::Impl(Map& map_,
Map::~Map() {
BackendScope guard(impl->backend);
- impl->styleRequest = nullptr;
-
// Explicit resets currently necessary because these abandon resources that need to be
// cleaned up by context.reset();
impl->renderStyle.reset();
@@ -323,88 +313,6 @@ void Map::Impl::render(View& view) {
#pragma mark - Style
-void Map::setStyleURL(const std::string& url) {
- if (impl->styleURL == url) {
- return;
- }
-
- impl->loading = true;
- impl->observer.onWillStartLoadingMap();
-
- impl->styleRequest = nullptr;
- impl->styleURL = url;
- impl->styleJSON.clear();
- impl->style->impl->loaded = false;
-
- impl->styleRequest = impl->fileSource.request(Resource::style(impl->styleURL), [this](Response res) {
- // Once we get a fresh style, or the style is mutated, stop revalidating.
- if (res.isFresh() || impl->style->impl->mutated) {
- impl->styleRequest.reset();
- }
-
- // Don't allow a loaded, mutated style to be overwritten with a new version.
- if (impl->style->impl->mutated && impl->style->impl->loaded) {
- return;
- }
-
- if (res.error) {
- if (res.error->reason == Response::Error::Reason::NotFound &&
- util::mapbox::isMapboxURL(impl->styleURL)) {
- const std::string message = "style " + impl->styleURL + " could not be found or is an incompatible legacy map or style";
- Log::Error(Event::Setup, message.c_str());
- impl->onStyleError(std::make_exception_ptr(util::NotFoundException(message)));
- } else {
- const std::string message = "loading style failed: " + res.error->message;
- Log::Error(Event::Setup, message.c_str());
- impl->onStyleError(std::make_exception_ptr(util::StyleLoadException(message)));
- }
- impl->onResourceError(std::make_exception_ptr(std::runtime_error(res.error->message)));
- } else if (res.notModified || res.noContent) {
- return;
- } else {
- impl->loadStyleJSON(*res.data);
- }
- });
-}
-
-void Map::setStyleJSON(const std::string& json) {
- if (impl->styleJSON == json) {
- return;
- }
-
- impl->loading = true;
- impl->observer.onWillStartLoadingMap();
-
- impl->styleURL.clear();
- impl->styleJSON.clear();
- impl->style->impl->mutated = false;
-
- impl->loadStyleJSON(json);
-}
-
-void Map::Impl::loadStyleJSON(const std::string& json) {
- style->impl->setJSON(json);
- styleJSON = json;
-
- if (!cameraMutated) {
- // Zoom first because it may constrain subsequent operations.
- map.setZoom(style->getDefaultZoom());
- map.setLatLng(style->getDefaultLatLng());
- map.setBearing(style->getDefaultBearing());
- map.setPitch(style->getDefaultPitch());
- }
-
- onUpdate(Update::AnnotationStyle);
-}
-
-std::string Map::getStyleURL() const {
- return impl->styleURL;
-}
-
-std::string Map::getStyleJSON() const {
- return impl->styleJSON;
-}
-
style::Style& Map::getStyle() {
return *impl->style;
}
@@ -413,6 +321,11 @@ const style::Style& Map::getStyle() const {
return *impl->style;
}
+void Map::setStyle(std::unique_ptr<Style> style) {
+ impl->onStyleLoading();
+ impl->style = std::move(style);
+}
+
#pragma mark - Transitions
void Map::cancelTransitions() {
@@ -943,7 +856,21 @@ void Map::Impl::onInvalidate() {
onUpdate(Update::Repaint);
}
+void Map::Impl::onStyleLoading() {
+ loading = true;
+ observer.onWillStartLoadingMap();
+}
+
void Map::Impl::onStyleLoaded() {
+ if (!cameraMutated) {
+ // Zoom first because it may constrain subsequent operations.
+ map.setZoom(style->getDefaultZoom());
+ map.setLatLng(style->getDefaultLatLng());
+ map.setBearing(style->getDefaultBearing());
+ map.setPitch(style->getDefaultPitch());
+ }
+
+ onUpdate(Update::AnnotationStyle);
observer.onDidFinishLoadingStyle();
}
@@ -960,7 +887,6 @@ void Map::Impl::onResourceError(std::exception_ptr error) {
void Map::dumpDebugLogs() const {
Log::Info(Event::General, "--------------------------------------------------------------------------------");
- Log::Info(Event::General, "MapContext::styleURL: %s", impl->styleURL.c_str());
impl->style->impl->dumpDebugLogs();
if (impl->renderStyle) {
impl->renderStyle->dumpDebugLogs();
diff --git a/src/mbgl/style/observer.hpp b/src/mbgl/style/observer.hpp
index 3b2c0db3c0..ea19c599e9 100644
--- a/src/mbgl/style/observer.hpp
+++ b/src/mbgl/style/observer.hpp
@@ -10,9 +10,10 @@ namespace style {
class Observer : public SourceObserver {
public:
+ virtual void onStyleLoading() {}
+ virtual void onStyleLoaded() {}
virtual void onUpdate(Update) {}
virtual void onStyleError(std::exception_ptr) {}
- virtual void onStyleLoaded() {}
virtual void onResourceError(std::exception_ptr) {}
};
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index f8dfd48b5c..5fe1ab4a06 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -14,6 +14,22 @@ Style::Style(Scheduler& scheduler, FileSource& fileSource, float pixelRatio)
Style::~Style() = default;
+void Style::loadJSON(const std::string& json) {
+ impl->loadJSON(json);
+}
+
+void Style::loadURL(const std::string& url) {
+ impl->loadURL(url);
+}
+
+std::string Style::getJSON() const {
+ return impl->getJSON();
+}
+
+std::string Style::getURL() const {
+ return impl->getURL();
+}
+
std::string Style::getName() const {
return impl->getName();
}
diff --git a/src/mbgl/style/style_impl.cpp b/src/mbgl/style/style_impl.cpp
index 7235226f84..2d42afd086 100644
--- a/src/mbgl/style/style_impl.cpp
+++ b/src/mbgl/style/style_impl.cpp
@@ -16,6 +16,9 @@
#include <mbgl/util/exception.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/logging.hpp>
+#include <mbgl/storage/file_source.hpp>
+#include <mbgl/storage/resource.hpp>
+#include <mbgl/storage/response.hpp>
namespace mbgl {
namespace style {
@@ -34,26 +37,47 @@ Style::Impl::Impl(Scheduler& scheduler_, FileSource& fileSource_, float pixelRat
Style::Impl::~Impl() = default;
-void Style::Impl::setTransitionOptions(const TransitionOptions& options) {
- transitionOptions = options;
-}
+void Style::Impl::loadJSON(const std::string& json_) {
+ observer->onStyleLoading();
-TransitionOptions Style::Impl::getTransitionOptions() const {
- return transitionOptions;
+ url.clear();
+ parse(json_);
}
-void Style::Impl::setJSON(const std::string& json) {
- sources.clear();
- layers.clear();
- images.clear();
+void Style::Impl::loadURL(const std::string& url_) {
+ observer->onStyleLoading();
- transitionOptions = {};
- transitionOptions.duration = util::DEFAULT_TRANSITION_DURATION;
+ loaded = false;
+ url = url_;
+ styleRequest = fileSource.request(Resource::style(url), [this](Response res) {
+ // Once we get a fresh style, or the style is mutated, stop revalidating.
+ if (res.isFresh() || mutated) {
+ styleRequest.reset();
+ }
+
+ // Don't allow a loaded, mutated style to be overwritten with a new version.
+ if (mutated && loaded) {
+ return;
+ }
+
+ if (res.error) {
+ const std::string message = "loading style failed: " + res.error->message;
+ Log::Error(Event::Setup, message.c_str());
+ observer->onStyleError(std::make_exception_ptr(util::StyleLoadException(message)));
+ observer->onResourceError(std::make_exception_ptr(std::runtime_error(res.error->message)));
+ } else if (res.notModified || res.noContent) {
+ return;
+ } else {
+ parse(*res.data);
+ }
+ });
+}
+
+void Style::Impl::parse(const std::string& json_) {
Parser parser;
- auto error = parser.parse(json);
- if (error) {
+ if (auto error = parser.parse(json_)) {
std::string message = "Failed to parse style: " + util::toString(error);
Log::Error(Event::ParseStyle, message.c_str());
observer->onStyleError(std::make_exception_ptr(util::StyleParseException(message)));
@@ -61,6 +85,17 @@ void Style::Impl::setJSON(const std::string& json) {
return;
}
+ mutated = false;
+ loaded = true;
+ json = json_;
+
+ sources.clear();
+ layers.clear();
+ images.clear();
+
+ transitionOptions = {};
+ transitionOptions.duration = util::DEFAULT_TRANSITION_DURATION;
+
for (auto& source : parser.sources) {
addSource(std::move(source));
}
@@ -79,11 +114,25 @@ void Style::Impl::setJSON(const std::string& json) {
spriteLoader->load(parser.spriteURL, scheduler, fileSource);
glyphURL = parser.glyphURL;
- loaded = true;
-
observer->onStyleLoaded();
}
+std::string Style::Impl::getJSON() const {
+ return json;
+}
+
+std::string Style::Impl::getURL() const {
+ return url;
+}
+
+void Style::Impl::setTransitionOptions(const TransitionOptions& options) {
+ transitionOptions = options;
+}
+
+TransitionOptions Style::Impl::getTransitionOptions() const {
+ return transitionOptions;
+}
+
void Style::Impl::addSource(std::unique_ptr<Source> source) {
if (sources.get(source->getID())) {
std::string msg = "Source " + source->getID() + " already exists";
@@ -296,6 +345,7 @@ void Style::Impl::onLightChanged(const Light&) {
}
void Style::Impl::dumpDebugLogs() const {
+ Log::Info(Event::General, "styleURL: %s", url.c_str());
for (const auto& source : sources) {
source->dumpDebugLogs();
}
diff --git a/src/mbgl/style/style_impl.hpp b/src/mbgl/style/style_impl.hpp
index 2bdb51a26c..76f244d5a4 100644
--- a/src/mbgl/style/style_impl.hpp
+++ b/src/mbgl/style/style_impl.hpp
@@ -25,6 +25,7 @@ namespace mbgl {
class Scheduler;
class FileSource;
+class AsyncRequest;
class SpriteLoader;
namespace style {
@@ -38,7 +39,11 @@ public:
Impl(Scheduler&, FileSource&, float pixelRatio);
~Impl() override;
- void setJSON(const std::string&);
+ void loadJSON(const std::string&);
+ void loadURL(const std::string&);
+
+ std::string getJSON() const;
+ std::string getURL() const;
void setObserver(Observer*);
@@ -92,11 +97,18 @@ public:
bool spriteLoaded = false;
private:
+ void parse(const std::string&);
+
Scheduler& scheduler;
FileSource& fileSource;
+
+ std::string url;
+ std::string json;
+
+ std::unique_ptr<AsyncRequest> styleRequest;
std::unique_ptr<SpriteLoader> spriteLoader;
- std::string glyphURL;
+ std::string glyphURL;
Collection<style::Image> images;
Collection<Source> sources;
Collection<Layer> layers;
diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp
index 12acdbca2f..7594d5ed73 100644
--- a/test/api/annotations.test.cpp
+++ b/test/api/annotations.test.cpp
@@ -3,6 +3,7 @@
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/annotation/annotation.hpp>
+#include <mbgl/style/style.hpp>
#include <mbgl/style/image.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/map/backend_scope.hpp>
@@ -45,7 +46,7 @@ public:
TEST(Annotations, SymbolAnnotation) {
AnnotationTest test;
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double>(0, 0), "default_marker" });
test.checkRendering("point_annotation");
@@ -67,7 +68,7 @@ TEST(Annotations, LineAnnotation) {
annotation.color = Color::red();
annotation.width = { 5 };
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotation(annotation);
test.checkRendering("line_annotation");
@@ -82,7 +83,7 @@ TEST(Annotations, FillAnnotation) {
FillAnnotation annotation { polygon };
annotation.color = Color::red();
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotation(annotation);
test.checkRendering("fill_annotation");
@@ -95,7 +96,7 @@ TEST(Annotations, AntimeridianAnnotationSmall) {
double antimeridian = 180;
test.map.setLatLngZoom(mbgl::LatLng(0, antimeridian), 0);
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
LineString<double> line = {{ { antimeridian, 20 }, { antimeridian, -20 } }};
LineAnnotation lineAnnotation { line };
@@ -116,7 +117,7 @@ TEST(Annotations, AntimeridianAnnotationLarge) {
double antimeridian = 180;
test.map.setLatLngZoom(mbgl::LatLng(0, antimeridian), 0);
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
LineString<double> line = {{ { antimeridian, 20 }, { antimeridian, -20 } }};
LineAnnotation lineAnnotation { line };
@@ -141,7 +142,7 @@ TEST(Annotations, OverlappingFillAnnotation) {
FillAnnotation overlaidAnnotation { polygon };
overlaidAnnotation.color = Color::red();
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotation(underlaidAnnotation);
test.map.addAnnotation(overlaidAnnotation);
test.checkRendering("overlapping_fill_annotation");
@@ -150,7 +151,7 @@ TEST(Annotations, OverlappingFillAnnotation) {
TEST(Annotations, AddMultiple) {
AnnotationTest test;
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double> { -10, 0 }, "default_marker" });
@@ -163,7 +164,7 @@ TEST(Annotations, AddMultiple) {
TEST(Annotations, NonImmediateAdd) {
AnnotationTest test;
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test::render(test.map, test.view);
Polygon<double> polygon = { {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} };
@@ -177,7 +178,7 @@ TEST(Annotations, NonImmediateAdd) {
TEST(Annotations, UpdateSymbolAnnotationGeometry) {
AnnotationTest test;
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotationImage(namedMarker("flipped_marker"));
AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
@@ -191,7 +192,7 @@ TEST(Annotations, UpdateSymbolAnnotationGeometry) {
TEST(Annotations, UpdateSymbolAnnotationIcon) {
AnnotationTest test;
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotationImage(namedMarker("flipped_marker"));
AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
@@ -209,7 +210,7 @@ TEST(Annotations, UpdateLineAnnotationGeometry) {
annotation.color = Color::red();
annotation.width = { 5 };
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
AnnotationID line = test.map.addAnnotation(annotation);
test::render(test.map, test.view);
@@ -226,7 +227,7 @@ TEST(Annotations, UpdateLineAnnotationStyle) {
annotation.color = Color::red();
annotation.width = { 5 };
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
AnnotationID line = test.map.addAnnotation(annotation);
test::render(test.map, test.view);
@@ -243,7 +244,7 @@ TEST(Annotations, UpdateFillAnnotationGeometry) {
FillAnnotation annotation { Polygon<double> { {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} } };
annotation.color = Color::red();
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
AnnotationID fill = test.map.addAnnotation(annotation);
test::render(test.map, test.view);
@@ -260,7 +261,7 @@ TEST(Annotations, UpdateFillAnnotationStyle) {
FillAnnotation annotation { polygon };
annotation.color = Color::red();
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
AnnotationID fill = test.map.addAnnotation(annotation);
test::render(test.map, test.view);
@@ -273,7 +274,7 @@ TEST(Annotations, UpdateFillAnnotationStyle) {
TEST(Annotations, RemovePoint) {
AnnotationTest test;
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
AnnotationID point = test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
@@ -291,7 +292,7 @@ TEST(Annotations, RemoveShape) {
annotation.color = Color::red();
annotation.width = { 5 };
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
AnnotationID shape = test.map.addAnnotation(annotation);
test::render(test.map, test.view);
@@ -304,7 +305,7 @@ TEST(Annotations, ImmediateRemoveShape) {
AnnotationTest test;
test.map.removeAnnotation(test.map.addAnnotation(LineAnnotation { LineString<double>() }));
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test::render(test.map, test.view);
}
@@ -312,20 +313,20 @@ TEST(Annotations, ImmediateRemoveShape) {
TEST(Annotations, SwitchStyle) {
AnnotationTest test;
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
test::render(test.map, test.view);
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.checkRendering("switch_style");
}
TEST(Annotations, ReaddImage) {
AnnotationTest test;
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
@@ -338,7 +339,7 @@ TEST(Annotations, ReaddImage) {
TEST(Annotations, QueryRenderedFeatures) {
AnnotationTest test;
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 0 }, "default_marker" });
test.map.addAnnotation(SymbolAnnotation { Point<double> { 0, 50 }, "default_marker" });
@@ -362,7 +363,7 @@ TEST(Annotations, QueryFractionalZoomLevels) {
auto viewSize = test.view.getSize();
auto box = ScreenBox { {}, { double(viewSize.width), double(viewSize.height) } };
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
std::vector<mbgl::AnnotationID> ids;
@@ -394,7 +395,7 @@ TEST(Annotations, VisibleFeatures) {
auto viewSize = test.view.getSize();
auto box = ScreenBox { {}, { double(viewSize.width), double(viewSize.height) } };
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotationImage(namedMarker("default_marker"));
test.map.setLatLngZoom({ 5, 5 }, 3);
@@ -438,7 +439,7 @@ TEST(Annotations, DebugEmpty) {
// should not render them.
AnnotationTest test;
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.setDebug(MapDebugOptions::TileBorders);
test.map.setZoom(1);
@@ -451,7 +452,7 @@ TEST(Annotations, DebugSparse) {
// tiles because they're all empty.
AnnotationTest test;
- test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.setDebug(MapDebugOptions::TileBorders);
test.map.setZoom(1);
test.map.addAnnotationImage(namedMarker("default_marker"));
diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp
index e11ed299a6..2b1138a1d3 100644
--- a/test/api/custom_layer.test.cpp
+++ b/test/api/custom_layer.test.cpp
@@ -94,7 +94,7 @@ TEST(CustomLayer, Basic) {
ThreadPool threadPool(4);
Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still);
- map.setStyleJSON(util::read_file("test/fixtures/api/water.json"));
+ map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
map.setLatLngZoom({ 37.8, -122.5 }, 10);
map.getStyle().addLayer(std::make_unique<CustomLayer>(
"custom",
diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp
index ad4dc6f4de..0b6d75ec4f 100644
--- a/test/api/query.test.cpp
+++ b/test/api/query.test.cpp
@@ -20,7 +20,7 @@ namespace {
class QueryTest {
public:
QueryTest() {
- map.setStyleJSON(util::read_file("test/fixtures/api/query_style.json"));
+ map.getStyle().loadJSON(util::read_file("test/fixtures/api/query_style.json"));
map.getStyle().addImage(std::make_unique<style::Image>("test-icon",
decodeImage(util::read_file("test/fixtures/sprites/default_marker.png")), 1.0));
diff --git a/test/api/render_missing.test.cpp b/test/api/render_missing.test.cpp
index 6e99501708..2e0c4401f4 100644
--- a/test/api/render_missing.test.cpp
+++ b/test/api/render_missing.test.cpp
@@ -10,6 +10,7 @@
#include <mbgl/util/image.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
+#include <mbgl/style/style.hpp>
#include <future>
@@ -40,7 +41,7 @@ TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) {
// This host does not respond (== connection error).
// Are you seeing this test fail? Make sure you don't have a server running on port 3001!
- map.setStyleJSON(style);
+ map.getStyle().loadJSON(style);
map.renderStill(view, [&](std::exception_ptr err) {
ASSERT_TRUE(err.operator bool());
try {
diff --git a/test/api/repeated_render.test.cpp b/test/api/repeated_render.test.cpp
index 0b9726d3fa..b6565dbf23 100644
--- a/test/api/repeated_render.test.cpp
+++ b/test/api/repeated_render.test.cpp
@@ -10,6 +10,7 @@
#include <mbgl/util/image.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
+#include <mbgl/style/style.hpp>
#include <future>
@@ -33,7 +34,7 @@ TEST(API, RepeatedRender) {
Map map(backend, view.getSize(), 1, fileSource, threadPool, MapMode::Still);
{
- map.setStyleJSON(style);
+ map.getStyle().loadJSON(style);
PremultipliedImage result;
map.renderStill(view, [&](std::exception_ptr) {
result = view.readStillImage();
@@ -51,7 +52,7 @@ TEST(API, RepeatedRender) {
}
{
- map.setStyleJSON(style);
+ map.getStyle().loadJSON(style);
PremultipliedImage result;
map.renderStill(view, [&](std::exception_ptr) {
result = view.readStillImage();
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index 9045f1c8c2..bed46f2c3e 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -80,8 +80,6 @@ TEST(Map, LatLngBehavior) {
MapTest test;
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
- map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
-
map.setLatLngZoom({ 1, 1 }, 0);
auto latLng1 = map.getLatLng();
@@ -146,7 +144,7 @@ TEST(Map, Offline) {
NetworkStatus::Set(NetworkStatus::Status::Offline);
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
- map.setStyleURL(prefix + "style.json");
+ map.getStyle().loadURL(prefix + "style.json");
test::checkImage("test/fixtures/map/offline",
test::render(map, test.view),
@@ -169,7 +167,7 @@ TEST(Map, SetStyleInvalidJSON) {
{
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool,
MapMode::Still);
- map.setStyleJSON("invalid");
+ map.getStyle().loadJSON("invalid");
}
EXPECT_TRUE(fail);
@@ -198,7 +196,7 @@ TEST(Map, SetStyleInvalidURL) {
};
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
- map.setStyleURL("mapbox://bar");
+ map.getStyle().loadURL("mapbox://bar");
test.runLoop.run();
}
@@ -207,8 +205,8 @@ TEST(Map, DoubleStyleLoad) {
MapTest test;
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
- map.setStyleJSON("");
- map.setStyleJSON("");
+ map.getStyle().loadJSON("");
+ map.getStyle().loadJSON("");
}
TEST(Map, StyleFresh) {
@@ -218,7 +216,7 @@ TEST(Map, StyleFresh) {
FakeFileSource fileSource;
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
- map.setStyleURL("mapbox://styles/test");
+ map.getStyle().loadURL("mapbox://styles/test");
EXPECT_EQ(1u, fileSource.requests.size());
Response response;
@@ -238,7 +236,7 @@ TEST(Map, StyleExpired) {
FakeFileSource fileSource;
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
- map.setStyleURL("mapbox://styles/test");
+ map.getStyle().loadURL("mapbox://styles/test");
EXPECT_EQ(1u, fileSource.requests.size());
Response response;
@@ -265,7 +263,7 @@ TEST(Map, StyleExpiredWithAnnotations) {
FakeFileSource fileSource;
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
- map.setStyleURL("mapbox://styles/test");
+ map.getStyle().loadURL("mapbox://styles/test");
EXPECT_EQ(1u, fileSource.requests.size());
Response response;
@@ -289,7 +287,7 @@ TEST(Map, StyleEarlyMutation) {
FakeFileSource fileSource;
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
- map.setStyleURL("mapbox://styles/test");
+ map.getStyle().loadURL("mapbox://styles/test");
map.getStyle().addLayer(std::make_unique<style::BackgroundLayer>("bg"));
Response response;
@@ -308,7 +306,7 @@ TEST(Map, MapLoadingSignal) {
test.backend.onWillStartLoadingMapCallback = [&]() {
emitted = true;
};
- map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
EXPECT_TRUE(emitted);
}
@@ -324,7 +322,7 @@ TEST(Map, MapLoadedSignal) {
map.render(test.view);
};
- map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.runLoop.run();
}
@@ -337,12 +335,12 @@ TEST(Map, StyleLoadedSignal) {
test.backend.didFinishLoadingStyleCallback = [&]() {
emitted = true;
};
- map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
EXPECT_TRUE(emitted);
// But not when the style couldn't be parsed
emitted = false;
- map.setStyleJSON("invalid");
+ map.getStyle().loadJSON("invalid");
EXPECT_FALSE(emitted);
}
@@ -352,7 +350,7 @@ TEST(Map, TEST_REQUIRES_SERVER(StyleNetworkErrorRetry)) {
OnlineFileSource fileSource;
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
- map.setStyleURL("http://127.0.0.1:3000/style-fail-once-500");
+ map.getStyle().loadURL("http://127.0.0.1:3000/style-fail-once-500");
test.backend.didFinishLoadingStyleCallback = [&]() {
test.runLoop.stop();
@@ -366,7 +364,7 @@ TEST(Map, TEST_REQUIRES_SERVER(StyleNotFound)) {
OnlineFileSource fileSource;
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
- map.setStyleURL("http://127.0.0.1:3000/style-fail-once-404");
+ map.getStyle().loadURL("http://127.0.0.1:3000/style-fail-once-404");
using namespace std::chrono_literals;
util::Timer timer;
@@ -385,7 +383,7 @@ TEST(Map, TEST_REQUIRES_SERVER(StyleNotFound)) {
test.runLoop.run();
// Should also not retry if the response has cache headers.
- map.setStyleURL("http://127.0.0.1:3000/style-fail-once-404-cache");
+ map.getStyle().loadURL("http://127.0.0.1:3000/style-fail-once-404-cache");
test.runLoop.run();
}
@@ -393,7 +391,7 @@ TEST(Map, AddLayer) {
MapTest test;
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
- map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
auto layer = std::make_unique<BackgroundLayer>("background");
layer->setBackgroundColor({ { 1, 0, 0, 1 } });
@@ -410,7 +408,7 @@ TEST(Map, WithoutVAOExtension) {
DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
Map map(test.backend, test.view.getSize(), 1, fileSource, test.threadPool, MapMode::Still);
- map.setStyleJSON(util::read_file("test/fixtures/api/water.json"));
+ map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
test::checkImage("test/fixtures/map/no_vao", test::render(map, test.view), 0.002);
}
@@ -419,7 +417,7 @@ TEST(Map, RemoveLayer) {
MapTest test;
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
- map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
+ map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
auto layer = std::make_unique<BackgroundLayer>("background");
layer->setBackgroundColor({{ 1, 0, 0, 1 }});
@@ -451,7 +449,7 @@ TEST(Map, DisabledSources) {
// to an opacity of 0.5). Then, we are zooming back out to a zoom level of 0.5 and rerender.
// The "raster1" layer should not be visible anymore since it has minzoom 1, while "raster2"
// should still be there. Both layers have a distinct color through "raster-hue-rotate".
- map.setStyleJSON(R"STYLE(
+ map.getStyle().loadJSON(R"STYLE(
{
"version": 8,
"name": "Test",
@@ -494,7 +492,7 @@ TEST(Map, DontLoadUnneededTiles) {
MapTest test;
Map map(test.backend, test.view.getSize(), 1, test.fileSource, test.threadPool, MapMode::Still);
- map.setStyleJSON(R"STYLE({
+ map.getStyle().loadJSON(R"STYLE({
"sources": {
"a": { "type": "vector", "tiles": [ "a/{z}/{x}/{y}" ] }
},
@@ -591,6 +589,6 @@ TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) {
render.send();
};
- map.setStyleJSON(util::read_file("test/fixtures/api/water.json"));
+ map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
util::RunLoop::Get()->run();
}
diff --git a/test/style/style.test.cpp b/test/style/style.test.cpp
index 701e4a6434..ab58eb1024 100644
--- a/test/style/style.test.cpp
+++ b/test/style/style.test.cpp
@@ -23,27 +23,27 @@ TEST(Style, Properties) {
StubFileSource fileSource;
Style::Impl style { threadPool, fileSource, 1.0 };
- style.setJSON(R"STYLE({"name": "Test"})STYLE");
+ style.loadJSON(R"STYLE({"name": "Test"})STYLE");
ASSERT_EQ("Test", style.getName());
- style.setJSON(R"STYLE({"center": [10, 20]})STYLE");
+ style.loadJSON(R"STYLE({"center": [10, 20]})STYLE");
ASSERT_EQ("", style.getName());
ASSERT_EQ((LatLng{20, 10}), style.getDefaultLatLng());
- style.setJSON(R"STYLE({"bearing": 24})STYLE");
+ style.loadJSON(R"STYLE({"bearing": 24})STYLE");
ASSERT_EQ("", style.getName());
ASSERT_EQ((LatLng{0, 0}), style.getDefaultLatLng());
ASSERT_EQ(24, style.getDefaultBearing());
- style.setJSON(R"STYLE({"zoom": 13.3})STYLE");
+ style.loadJSON(R"STYLE({"zoom": 13.3})STYLE");
ASSERT_EQ("", style.getName());
ASSERT_EQ(13.3, style.getDefaultZoom());
- style.setJSON(R"STYLE({"pitch": 60})STYLE");
+ style.loadJSON(R"STYLE({"pitch": 60})STYLE");
ASSERT_EQ("", style.getName());
ASSERT_EQ(60, style.getDefaultPitch());
- style.setJSON(R"STYLE({"name": 23, "center": {}, "bearing": "north", "zoom": null, "pitch": "wide"})STYLE");
+ style.loadJSON(R"STYLE({"name": 23, "center": {}, "bearing": "north", "zoom": null, "pitch": "wide"})STYLE");
ASSERT_EQ("", style.getName());
ASSERT_EQ((LatLng{0, 0}), style.getDefaultLatLng());
ASSERT_EQ(0, style.getDefaultBearing());
@@ -58,7 +58,7 @@ TEST(Style, DuplicateSource) {
StubFileSource fileSource;
Style::Impl style { threadPool, fileSource, 1.0 };
- style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
+ style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
style.addSource(std::make_unique<VectorSource>("sourceId", "mapbox://mapbox.mapbox-terrain-v2"));
@@ -80,7 +80,7 @@ TEST(Style, RemoveSourceInUse) {
StubFileSource fileSource;
Style::Impl style { threadPool, fileSource, 1.0 };
- style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
+ style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
style.addSource(std::make_unique<VectorSource>("sourceId", "mapbox://mapbox.mapbox-terrain-v2"));
style.addLayer(std::make_unique<LineLayer>("layerId", "sourceId"));
diff --git a/test/style/style_layer.test.cpp b/test/style/style_layer.test.cpp
index 0e7957c490..77acca2868 100644
--- a/test/style/style_layer.test.cpp
+++ b/test/style/style_layer.test.cpp
@@ -276,7 +276,7 @@ TEST(Layer, DuplicateLayer) {
ThreadPool threadPool{ 1 };
StubFileSource fileSource;
Style::Impl style { threadPool, fileSource, 1.0 };
- style.setJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
+ style.loadJSON(util::read_file("test/fixtures/resources/style-unused-sources.json"));
// Add initial layer
style.addLayer(std::make_unique<LineLayer>("line", "unusedsource"));
diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp
index 97eabf9cb3..bca538c6c6 100644
--- a/test/util/memory.test.cpp
+++ b/test/util/memory.test.cpp
@@ -9,6 +9,7 @@
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
+#include <mbgl/style/style.hpp>
#include <algorithm>
#include <iostream>
@@ -75,7 +76,7 @@ TEST(Memory, Vector) {
Map map(test.backend, { 256, 256 }, 2, test.fileSource, test.threadPool, MapMode::Still);
map.setZoom(16); // more map features
- map.setStyleURL("mapbox://streets");
+ map.getStyle().loadURL("mapbox://streets");
test::render(map, test.view);
}
@@ -84,7 +85,7 @@ TEST(Memory, Raster) {
MemoryTest test;
Map map(test.backend, { 256, 256 }, 2, test.fileSource, test.threadPool, MapMode::Still);
- map.setStyleURL("mapbox://satellite");
+ map.getStyle().loadURL("mapbox://satellite");
test::render(map, test.view);
}
@@ -118,7 +119,7 @@ TEST(Memory, Footprint) {
auto renderMap = [&](Map& map, const char* style){
map.setZoom(16);
- map.setStyleURL(style);
+ map.getStyle().loadURL(style);
test::render(map, test.view);
};