diff --git a/benchmark/api/query.benchmark.cpp b/benchmark/api/query.benchmark.cpp index 5d4e48fbe..05732e0e9 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("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 82d851d01..51c6faef5 100644 --- a/bin/render.cpp +++ b/bin/render.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #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 85c95d649..dd29d444b 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); + // Transition void cancelTransitions(); void setGestureInProgress(bool); diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp index 82ff1b307..cb84922b4 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 e09a58d25..13d5be01b 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(env, map->getStyleURL()); + return jni::Make(env, map->getStyle().getURL()); } void NativeMapView::setStyleUrl(jni::JNIEnv& env, jni::String url) { - map->setStyleURL(jni::Make(env, url)); + map->getStyle().loadURL(jni::Make(env, url)); } jni::String NativeMapView::getStyleJson(jni::JNIEnv& env) { - return jni::Make(env, map->getStyleJSON()); + return jni::Make(env, map->getStyle().getJSON()); } void NativeMapView::setStyleJson(jni::JNIEnv& env, jni::String json) { - map->setStyleJSON(jni::Make(env, json)); + map->getStyle().loadJSON(jni::Make(env, json)); } void NativeMapView::setLatLngBounds(jni::JNIEnv& env, jni::Object jBounds) { diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 6d9a12c3e..2365641f0 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 97c77b374..719247583 100644 --- a/platform/glfw/main.cpp +++ b/platform/glfw/main.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -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 0d00fe75f..6c6d8d298 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 756f237fb..0a567a851 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -24,6 +24,7 @@ #import #import +#import #import #import #import @@ -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 324b53f84..9ba88193c 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& 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& info) { } void NodeMap::cancel() { - auto style = map->getStyleJSON(); + auto style = map->getStyle().getJSON(); map = std::make_unique(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 cb4830868..f094e2a0e 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 3aed91cda..37442770f 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -13,9 +13,6 @@ #include #include #include -#include -#include -#include #include #include #include @@ -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