summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSudarsana Babu Nagineni <sudarsana.babu@mapbox.com>2019-03-07 14:29:19 +0200
committerSudarsana Babu Nagineni <sudarsana.babu@mapbox.com>2019-03-07 15:08:23 +0200
commit76dd8bb15539f29cd5e4cd6860d5cf26395a44ee (patch)
tree967ebbbc38f5874074bb46c68aadaed1d251360a
parentfa4fa5d9fe41874d463ba8df29db61ba4bc1b89e (diff)
downloadqtlocation-mapboxgl-upstream/nagineni-mapoptions.tar.gz
[core] Add MapOptions to define properties of Mapupstream/nagineni-mapoptions
To simplify the Map constructor, introduce MapOptions interface to define the properties that can be set on a Map.
-rw-r--r--benchmark/api/query.benchmark.cpp4
-rw-r--r--benchmark/api/render.benchmark.cpp10
-rw-r--r--bin/render.cpp4
-rw-r--r--include/mbgl/map/map.hpp6
-rw-r--r--include/mbgl/map/map_options.hpp139
-rwxr-xr-xplatform/android/src/native_map_view.cpp11
-rw-r--r--platform/default/src/mbgl/map/map_snapshotter.cpp3
-rw-r--r--platform/glfw/main.cpp2
-rw-r--r--platform/ios/src/MGLMapView.mm11
-rw-r--r--platform/macos/src/MGLMapView.mm9
-rw-r--r--platform/node/src/node_map.cpp18
-rw-r--r--platform/qt/src/qmapboxgl.cpp9
-rw-r--r--src/core-files.json2
-rw-r--r--src/mbgl/map/map.cpp13
-rw-r--r--src/mbgl/map/map_options.cpp85
-rw-r--r--test/api/annotations.test.cpp4
-rw-r--r--test/api/api_misuse.test.cpp4
-rw-r--r--test/api/custom_geometry_source.test.cpp3
-rw-r--r--test/api/custom_layer.test.cpp3
-rw-r--r--test/api/query.test.cpp3
-rw-r--r--test/api/recycle_map.cpp4
-rw-r--r--test/gl/context.test.cpp4
-rw-r--r--test/map/map.test.cpp10
-rw-r--r--test/map/prefetch.test.cpp4
-rw-r--r--test/text/local_glyph_rasterizer.test.cpp3
-rw-r--r--test/util/memory.test.cpp8
26 files changed, 326 insertions, 50 deletions
diff --git a/benchmark/api/query.benchmark.cpp b/benchmark/api/query.benchmark.cpp
index 8d060087de..275a79372c 100644
--- a/benchmark/api/query.benchmark.cpp
+++ b/benchmark/api/query.benchmark.cpp
@@ -1,6 +1,7 @@
#include <benchmark/benchmark.h>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/renderer/renderer.hpp>
@@ -34,7 +35,8 @@ public:
DefaultFileSource fileSource{ "benchmark/fixtures/api/cache.db", "." };
ThreadPool threadPool{ 4 };
HeadlessFrontend frontend { { 1000, 1000 }, 1, fileSource, threadPool };
- Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), 1, fileSource, threadPool, MapMode::Static};
+ Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), 1,
+ fileSource, threadPool, MapOptions().withMapMode(MapMode::Static) };
ScreenBox box{{ 0, 0 }, { 1000, 1000 }};
};
diff --git a/benchmark/api/render.benchmark.cpp b/benchmark/api/render.benchmark.cpp
index 3362da1a4f..8709f18d9c 100644
--- a/benchmark/api/render.benchmark.cpp
+++ b/benchmark/api/render.benchmark.cpp
@@ -2,6 +2,7 @@
#include <mbgl/map/map.hpp>
#include <mbgl/map/map_observer.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/renderer/renderer.hpp>
@@ -41,7 +42,8 @@ static void prepare(Map& map, optional<std::string> json = {}) {
static void API_renderStill_reuse_map(::benchmark::State& state) {
RenderBenchmark bench;
HeadlessFrontend frontend { { 1000, 1000 }, 1, bench.fileSource, bench.threadPool };
- Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), 1, bench.fileSource, bench.threadPool, MapMode::Static};
+ Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), 1,
+ bench.fileSource, bench.threadPool, MapOptions().withMapMode(MapMode::Static) };
prepare(map);
while (state.KeepRunning()) {
@@ -52,7 +54,8 @@ static void API_renderStill_reuse_map(::benchmark::State& state) {
static void API_renderStill_reuse_map_switch_styles(::benchmark::State& state) {
RenderBenchmark bench;
HeadlessFrontend frontend { { 1000, 1000 }, 1, bench.fileSource, bench.threadPool };
- Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), 1, bench.fileSource, bench.threadPool, MapMode::Static};
+ Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), 1,
+ bench.fileSource, bench.threadPool, MapOptions().withMapMode(MapMode::Static) };
while (state.KeepRunning()) {
prepare(map, { "{}" });
@@ -67,7 +70,8 @@ static void API_renderStill_recreate_map(::benchmark::State& state) {
while (state.KeepRunning()) {
HeadlessFrontend frontend { { 1000, 1000 }, 1, bench.fileSource, bench.threadPool };
- Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), 1, bench.fileSource, bench.threadPool, MapMode::Static};
+ Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), 1,
+ bench.fileSource, bench.threadPool, MapOptions().withMapMode(MapMode::Static) };
prepare(map);
frontend.render(map);
}
diff --git a/bin/render.cpp b/bin/render.cpp
index bf64570965..fbf32f9a40 100644
--- a/bin/render.cpp
+++ b/bin/render.cpp
@@ -1,4 +1,5 @@
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/default_styles.hpp>
@@ -84,7 +85,8 @@ int main(int argc, char *argv[]) {
ThreadPool threadPool(4);
HeadlessFrontend frontend({ width, height }, pixelRatio, fileSource, threadPool);
- Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource, threadPool, MapMode::Static);
+ Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio,
+ fileSource, threadPool, MapOptions().withMapMode(MapMode::Static));
if (style.find("://") == std::string::npos) {
style = std::string("file://") + style;
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 55f2ab2895..ed604dbe91 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -3,6 +3,7 @@
#include <mbgl/util/optional.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/map/map_observer.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/size.hpp>
@@ -35,10 +36,7 @@ public:
float pixelRatio,
FileSource&,
Scheduler&,
- MapMode mapMode = MapMode::Continuous,
- ConstrainMode constrainMode = ConstrainMode::HeightOnly,
- ViewportMode viewportMode = ViewportMode::Default,
- bool crossSourceCollisions = true);
+ const MapOptions&);
~Map();
// Register a callback that will get called (on the render thread) when all resources have
diff --git a/include/mbgl/map/map_options.hpp b/include/mbgl/map/map_options.hpp
new file mode 100644
index 0000000000..13772332a8
--- /dev/null
+++ b/include/mbgl/map/map_options.hpp
@@ -0,0 +1,139 @@
+#pragma once
+
+#include <mbgl/map/mode.hpp>
+
+#include <memory>
+#include <string>
+
+namespace mbgl {
+
+/**
+ * @brief Holds values for Map options.
+ */
+class MapOptions {
+public:
+ /**
+ * @brief Constructs a MapOptions object with default values.
+ */
+ MapOptions();
+ ~MapOptions();
+
+ /**
+ * @brief Sets the map rendering mode. By default, it is set to Continuous
+ * so the map will render as data arrives from the network and react
+ * immediately to state changes.
+ *
+ * @param mode Map rendering mode.
+ * @return reference to MapOptions for chaining options together.
+ */
+ MapOptions& withMapMode(MapMode mode);
+
+ /**
+ * @brief Gets the previously set (or default) map mode.
+ *
+ * @return map mode.
+ */
+ MapMode mapMode() const;
+
+ /**
+ * @brief Sets the map constrain mode. This can be used to limit the map
+ * to wrap around the globe horizontally. By default, it is set to
+ * HeightOnly.
+ *
+ * @param mode Map constrain mode.
+ * @return reference to MapOptions for chaining options together.
+ */
+ MapOptions& withConstrainMode(ConstrainMode mode);
+
+ /**
+ * @brief Gets the previously set (or default) constrain mode.
+ *
+ * @return constrain mode.
+ */
+ ConstrainMode constrainMode() const;
+
+ /**
+ * @brief Sets the viewport mode. This can be used to flip the vertical
+ * orientation of the map as some devices may use inverted orientation.
+ *
+ * @param mode Viewport mode.
+ * @return reference to MapOptions for chaining options together.
+ */
+ MapOptions& withViewportMode(ViewportMode mode);
+
+ /**
+ * @brief Gets the previously set (or default) viewport mode.
+ *
+ * @return viewport mode.
+ */
+ ViewportMode viewportMode() const;
+
+ /**
+ * @brief Sets the cache path.
+ *
+ * @param path Cache path.
+ * @return reference to MapOptions for chaining options together.
+ */
+ MapOptions& withCachePath(std::string path);
+
+ /**
+ * @brief Gets the previously set (or default) cache path.
+ *
+ * @return cache path
+ */
+ const std::string& cachePath() const;
+
+ /**
+ * @brief Sets the asset path, which is the root directory from where
+ * the asset:// scheme gets resolved in a style.
+ *
+ * @param path Asset path.
+ * @return reference to MapOptions for chaining options together.
+ */
+ MapOptions& withAssetRoot(std::string path);
+
+ /**
+ * @brief Gets the previously set (or default) asset path.
+ *
+ * @return asset path
+ */
+ const std::string& assetRoot() const;
+
+ /**
+ * @brief Sets the maximum cache size.
+ *
+ * @param size Cache maximum size in bytes.
+ * @return reference to MapOptions for chaining options together.
+ */
+ MapOptions& withMaximumCacheSize(uint64_t size);
+
+ /**
+ * @brief Gets the previously set (or default) maximum allowed cache size.
+ *
+ * @return maximum allowed cache database size in bytes.
+ */
+ uint64_t maximumCacheSize() const;
+
+ /**
+ * @brief Specify whether to enable cross-source symbol collision detection
+ * or not. By default, it is set to true.
+ *
+ * @param enableCollisions true to enable, false to disable
+ * @return reference to MapOptions for chaining options together.
+ */
+ MapOptions& withCrossSourceCollisions(bool enableCollisions);
+
+ /**
+ * @brief Gets the previously set (or default) crossSourceCollisions value.
+ *
+ * @return true if ecross-source symbol collision detection enabled,
+ * false otherwise.
+ */
+ bool crossSourceCollisions() const;
+
+private:
+ class Impl;
+ std::shared_ptr<Impl> impl_;
+};
+
+} // namespace mbgl
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index d8eba09e9a..2f23f0b7d9 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -13,6 +13,7 @@
#include <jni/jni.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/math/minmax.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/event.hpp>
@@ -79,12 +80,18 @@ NativeMapView::NativeMapView(jni::JNIEnv& _env,
// Create a renderer frontend
rendererFrontend = std::make_unique<AndroidRendererFrontend>(mapRenderer);
+ // Create Map options
+ MapOptions options;
+ options.withMapMode(MapMode::Continuous)
+ .withConstrainMode(ConstrainMode::HeightOnly)
+ .withViewportMode(ViewportMode::Default)
+ .withCrossSourceCollisions(_crossSourceCollisions);
+
// Create the core map
map = std::make_unique<mbgl::Map>(*rendererFrontend, *this,
mbgl::Size{ static_cast<uint32_t>(width),
static_cast<uint32_t>(height) }, pixelRatio,
- fileSource, *threadPool, MapMode::Continuous,
- ConstrainMode::HeightOnly, ViewportMode::Default, _crossSourceCollisions);
+ fileSource, *threadPool, options);
}
/**
diff --git a/platform/default/src/mbgl/map/map_snapshotter.cpp b/platform/default/src/mbgl/map/map_snapshotter.cpp
index 926c51b60f..56bc9bdb88 100644
--- a/platform/default/src/mbgl/map/map_snapshotter.cpp
+++ b/platform/default/src/mbgl/map/map_snapshotter.cpp
@@ -3,6 +3,7 @@
#include <mbgl/actor/actor_ref.hpp>
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/style/style.hpp>
@@ -57,7 +58,7 @@ MapSnapshotter::Impl::Impl(FileSource* fileSource,
const optional<std::string> localFontFamily)
: scheduler(std::move(scheduler_))
, frontend(size, pixelRatio, *fileSource, *scheduler, programCacheDir, GLContextMode::Unique, localFontFamily)
- , map(frontend, MapObserver::nullObserver(), size, pixelRatio, *fileSource, *scheduler, MapMode::Static) {
+ , map(frontend, MapObserver::nullObserver(), size, pixelRatio, *fileSource, *scheduler, MapOptions().withMapMode(MapMode::Static)) {
if (style.first) {
map.getStyle().loadJSON(style.second);
diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp
index c52ea92512..8e6905f948 100644
--- a/platform/glfw/main.cpp
+++ b/platform/glfw/main.cpp
@@ -109,7 +109,7 @@ int main(int argc, char *argv[]) {
mbgl::ThreadPool threadPool(4);
GLFWRendererFrontend rendererFrontend { std::make_unique<mbgl::Renderer>(backend, view->getPixelRatio(), fileSource, threadPool), backend };
- mbgl::Map map(rendererFrontend, backend, view->getSize(), view->getPixelRatio(), fileSource, threadPool);
+ mbgl::Map map(rendererFrontend, backend, view->getSize(), view->getPixelRatio(), fileSource, threadPool, mbgl::MapOptions());
backend.setMap(&map);
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 0c6632f229..59bb1c6666 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -4,6 +4,7 @@
#import <OpenGLES/EAGL.h>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/annotation/annotation.hpp>
#include <mbgl/map/camera.hpp>
#include <mbgl/map/mode.hpp>
@@ -472,9 +473,15 @@ public:
auto renderer = std::make_unique<mbgl::Renderer>(*_mbglView, config.scaleFactor, *config.fileSource, *_mbglThreadPool, config.contextMode, config.cacheDir, config.localFontFamilyName);
BOOL enableCrossSourceCollisions = !config.perSourceCollisions;
_rendererFrontend = std::make_unique<MGLRenderFrontend>(std::move(renderer), self, *_mbglView);
-
+
+ mbgl::MapOptions mapOptions;
+ mapOptions.withMapMode(mbgl::MapMode::Continuous)
+ .withConstrainMode(mbgl::ConstrainMode::None)
+ .withViewportMode(mbgl::ViewportMode::Default)
+ .withCrossSourceCollisions(enableCrossSourceCollisions);
+
NSAssert(!_mbglMap, @"_mbglMap should be NULL");
- _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, self.size, config.scaleFactor, *[config fileSource], *_mbglThreadPool, mbgl::MapMode::Continuous, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default, enableCrossSourceCollisions);
+ _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, self.size, config.scaleFactor, *[config fileSource], *_mbglThreadPool, mapOptions);
// start paused if in IB
if (_isTargetingInterfaceBuilder || background) {
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 8ebf6356cb..045a0c9f98 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -26,6 +26,7 @@
#import "MGLImageSource.h"
#import <mbgl/map/map.hpp>
+#import <mbgl/map/map_options.hpp>
#import <mbgl/style/style.hpp>
#import <mbgl/annotation/annotation.hpp>
#import <mbgl/map/camera.hpp>
@@ -288,7 +289,13 @@ public:
auto renderer = std::make_unique<mbgl::Renderer>(*_mbglView, config.scaleFactor, *config.fileSource, *_mbglThreadPool, config.contextMode, config.cacheDir, config.localFontFamilyName);
BOOL enableCrossSourceCollisions = !config.perSourceCollisions;
_rendererFrontend = std::make_unique<MGLRenderFrontend>(std::move(renderer), self, *_mbglView, true);
- _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, self.size, config.scaleFactor, *config.fileSource, *_mbglThreadPool, mbgl::MapMode::Continuous, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default, enableCrossSourceCollisions);
+
+ mbgl::MapOptions mapOptions;
+ mapOptions.withMapMode(mbgl::MapMode::Continuous)
+ .withConstrainMode(mbgl::ConstrainMode::None)
+ .withViewportMode(mbgl::ViewportMode::Default)
+ .withCrossSourceCollisions(enableCrossSourceCollisions);
+ _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, self.size, config.scaleFactor, *config.fileSource, *_mbglThreadPool, mapOptions);
// Install the OpenGL layer. Interface Builder’s synchronous drawing means
// we can’t display a map, so don’t even bother to have a map layer.
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index 068fc57a5c..121a00696e 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -620,11 +620,13 @@ void NodeMap::cancel() {
});
frontend = std::make_unique<mbgl::HeadlessFrontend>(mbgl::Size{ 256, 256 }, pixelRatio, *this, threadpool);
+ mbgl::MapOptions options;
+ options.withMapMode(mode)
+ .withConstrainMode(mbgl::ConstrainMode::HeightOnly)
+ .withViewportMode(mbgl::ViewportMode::Default)
+ .withCrossSourceCollisions(crossSourceCollisions);
map = std::make_unique<mbgl::Map>(*frontend, mapObserver, frontend->getSize(), pixelRatio,
- *this, threadpool, mode,
- mbgl::ConstrainMode::HeightOnly,
- mbgl::ViewportMode::Default,
- crossSourceCollisions);
+ *this, threadpool, options);
// FIXME: Reload the style after recreating the map. We need to find
// a better way of canceling an ongoing rendering on the core level
@@ -1206,10 +1208,10 @@ NodeMap::NodeMap(v8::Local<v8::Object> options)
pixelRatio,
*this,
threadpool,
- mode,
- mbgl::ConstrainMode::HeightOnly,
- mbgl::ViewportMode::Default,
- crossSourceCollisions)),
+ mbgl::MapOptions().withMapMode(mode)
+ .withConstrainMode(mbgl::ConstrainMode::HeightOnly)
+ .withViewportMode(mbgl::ViewportMode::Default)
+ .withCrossSourceCollisions(crossSourceCollisions))),
async(new uv_async_t) {
async->data = this;
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index fd4a210229..49b0dc021c 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -1767,15 +1767,18 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin
connect(m_mapObserver.get(), SIGNAL(mapLoadingFailed(QMapboxGL::MapLoadingFailure,QString)), q, SIGNAL(mapLoadingFailed(QMapboxGL::MapLoadingFailure,QString)));
connect(m_mapObserver.get(), SIGNAL(copyrightsChanged(QString)), q, SIGNAL(copyrightsChanged(QString)));
+ mbgl::MapOptions options;
+ options.withMapMode(static_cast<mbgl::MapMode>(settings.mapMode()))
+ .withConstrainMode(static_cast<mbgl::ConstrainMode>(settings.constrainMode()))
+ .withViewportMode(static_cast<mbgl::ViewportMode>(settings.viewportMode()));
+
// Setup the Map object
mapObj = std::make_unique<mbgl::Map>(
*this, // RendererFrontend
*m_mapObserver,
sanitizedSize(size),
m_pixelRatio, *m_fileSourceObj, *m_threadPool,
- static_cast<mbgl::MapMode>(settings.mapMode()),
- static_cast<mbgl::ConstrainMode>(settings.constrainMode()),
- static_cast<mbgl::ViewportMode>(settings.viewportMode()));
+ options);
// Needs to be Queued to give time to discard redundant draw calls via the `renderQueued` flag.
connect(this, SIGNAL(needsRendering()), q, SIGNAL(needsRendering()), Qt::QueuedConnection);
diff --git a/src/core-files.json b/src/core-files.json
index ab43e6b409..34049eedef 100644
--- a/src/core-files.json
+++ b/src/core-files.json
@@ -44,6 +44,7 @@
"src/mbgl/layout/symbol_projection.cpp",
"src/mbgl/map/map.cpp",
"src/mbgl/map/map_impl.cpp",
+ "src/mbgl/map/map_options.cpp",
"src/mbgl/map/transform.cpp",
"src/mbgl/map/transform_state.cpp",
"src/mbgl/math/log2.cpp",
@@ -329,6 +330,7 @@
"mbgl/map/change.hpp": "include/mbgl/map/change.hpp",
"mbgl/map/map.hpp": "include/mbgl/map/map.hpp",
"mbgl/map/map_observer.hpp": "include/mbgl/map/map_observer.hpp",
+ "mbgl/map/map_options.hpp": "include/mbgl/map/map_options.hpp",
"mbgl/map/mode.hpp": "include/mbgl/map/mode.hpp",
"mbgl/math/clamp.hpp": "include/mbgl/math/clamp.hpp",
"mbgl/math/log2.hpp": "include/mbgl/math/log2.hpp",
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 7fe99e3867..4113a7ed22 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -33,10 +33,7 @@ Map::Map(RendererFrontend& rendererFrontend,
const float pixelRatio,
FileSource& fileSource,
Scheduler& scheduler,
- MapMode mapMode,
- ConstrainMode constrainMode,
- ViewportMode viewportMode,
- bool crossSourceCollisions)
+ const MapOptions& options)
: impl(std::make_unique<Impl>(*this,
rendererFrontend,
mapObserver,
@@ -44,10 +41,10 @@ Map::Map(RendererFrontend& rendererFrontend,
scheduler,
size,
pixelRatio,
- mapMode,
- constrainMode,
- viewportMode,
- crossSourceCollisions)) {}
+ options.mapMode(),
+ options.constrainMode(),
+ options.viewportMode(),
+ options.crossSourceCollisions())) {}
Map::~Map() = default;
diff --git a/src/mbgl/map/map_options.cpp b/src/mbgl/map/map_options.cpp
new file mode 100644
index 0000000000..118fcaf3df
--- /dev/null
+++ b/src/mbgl/map/map_options.cpp
@@ -0,0 +1,85 @@
+#include <mbgl/map/map_options.hpp>
+#include <mbgl/util/constants.hpp>
+
+#include <cassert>
+
+namespace mbgl {
+
+class MapOptions::Impl {
+public:
+ MapMode mapMode = MapMode::Continuous;
+ ConstrainMode constrainMode = ConstrainMode::HeightOnly;
+ ViewportMode viewportMode = ViewportMode::Default;
+ std::string cachePath;
+ std::string assetRoot;
+ uint64_t maximumSize{mbgl::util::DEFAULT_MAX_CACHE_SIZE};
+ bool crossSourceCollisions = true;
+};
+
+MapOptions::MapOptions() : impl_(std::make_shared<MapOptions::Impl>()) {}
+MapOptions::~MapOptions() = default;
+
+MapOptions& MapOptions::withMapMode(MapMode mode) {
+ impl_->mapMode = mode;
+ return *this;
+}
+
+MapMode MapOptions::mapMode() const {
+ return impl_->mapMode;
+}
+
+MapOptions& MapOptions::withConstrainMode(ConstrainMode mode) {
+ impl_->constrainMode = mode;
+ return *this;
+}
+
+ConstrainMode MapOptions::constrainMode() const {
+ return impl_->constrainMode;
+}
+
+MapOptions& MapOptions::withViewportMode(ViewportMode mode) {
+ impl_->viewportMode = mode;
+ return *this;
+}
+
+ViewportMode MapOptions::viewportMode() const {
+ return impl_->viewportMode;
+}
+
+MapOptions& MapOptions::withCachePath(std::string path) {
+ impl_->cachePath = std::move(path);
+ return *this;
+}
+
+const std::string& MapOptions::cachePath() const {
+ return impl_->cachePath;
+}
+
+MapOptions& MapOptions::withAssetRoot(std::string path) {
+ impl_->assetRoot = std::move(path);
+ return *this;
+}
+
+const std::string& MapOptions::assetRoot() const {
+ return impl_->assetRoot;
+}
+
+MapOptions& MapOptions::withMaximumCacheSize(uint64_t size) {
+ impl_->maximumSize = size;
+ return *this;
+}
+
+uint64_t MapOptions::maximumCacheSize() const {
+ return impl_->maximumSize;
+}
+
+MapOptions& MapOptions::withCrossSourceCollisions(bool enableCollisions) {
+ impl_->crossSourceCollisions = enableCollisions;
+ return *this;
+}
+
+bool MapOptions::crossSourceCollisions() const {
+ return impl_->crossSourceCollisions;
+}
+
+} // namespace mbgl
diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp
index 8d2dae177b..a81d9ff990 100644
--- a/test/api/annotations.test.cpp
+++ b/test/api/annotations.test.cpp
@@ -6,6 +6,7 @@
#include <mbgl/style/style.hpp>
#include <mbgl/style/image.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/color.hpp>
@@ -31,8 +32,9 @@ public:
ThreadPool threadPool { 4 };
float pixelRatio { 1 };
HeadlessFrontend frontend { pixelRatio, fileSource, threadPool };
+
Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
- threadPool, MapMode::Static};
+ threadPool, MapOptions().withMapMode(MapMode::Static)};
void checkRendering(const char * name) {
test::checkImage(std::string("test/fixtures/annotations/") + name,
diff --git a/test/api/api_misuse.test.cpp b/test/api/api_misuse.test.cpp
index 363958451b..8899173071 100644
--- a/test/api/api_misuse.test.cpp
+++ b/test/api/api_misuse.test.cpp
@@ -3,6 +3,7 @@
#include <mbgl/test/fixture_log_observer.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/renderer/backend_scope.hpp>
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/storage/online_file_source.hpp>
@@ -27,7 +28,8 @@ TEST(API, RenderWithoutCallback) {
HeadlessFrontend frontend { pixelRatio, fileSource, threadPool };
auto map = std::make_unique<Map>(frontend, MapObserver::nullObserver(), frontend.getSize(),
- pixelRatio, fileSource, threadPool, MapMode::Static);
+ pixelRatio, fileSource, threadPool,
+ MapOptions().withMapMode(MapMode::Static));
map->renderStill(nullptr);
// Force Map thread to join.
diff --git a/test/api/custom_geometry_source.test.cpp b/test/api/custom_geometry_source.test.cpp
index 3e18cca01a..4eeca9104b 100644
--- a/test/api/custom_geometry_source.test.cpp
+++ b/test/api/custom_geometry_source.test.cpp
@@ -1,6 +1,7 @@
#include <mbgl/test/util.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/util/shared_thread_pool.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/gl/headless_frontend.hpp>
@@ -24,7 +25,7 @@ TEST(CustomGeometrySource, Grid) {
float pixelRatio { 1 };
HeadlessFrontend frontend { pixelRatio, fileSource, *threadPool };
Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
- *threadPool, MapMode::Static);
+ *threadPool, MapOptions().withMapMode(MapMode::Static));
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
map.jumpTo(CameraOptions().withCenter(LatLng { 37.8, -122.5 }).withZoom(10.0));
diff --git a/test/api/custom_layer.test.cpp b/test/api/custom_layer.test.cpp
index 114b88398a..d840925206 100644
--- a/test/api/custom_layer.test.cpp
+++ b/test/api/custom_layer.test.cpp
@@ -2,6 +2,7 @@
#include <mbgl/platform/gl_functions.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/gl/defines.hpp>
@@ -94,7 +95,7 @@ TEST(CustomLayer, Basic) {
float pixelRatio { 1 };
HeadlessFrontend frontend { pixelRatio, fileSource, threadPool };
Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
- threadPool, MapMode::Static);
+ threadPool, MapOptions().withMapMode(MapMode::Static));
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
map.jumpTo(CameraOptions().withCenter(LatLng { 37.8, -122.5 }).withZoom(10.0));
map.getStyle().addLayer(std::make_unique<CustomLayer>(
diff --git a/test/api/query.test.cpp b/test/api/query.test.cpp
index efda84baa9..b9fc3a4a62 100644
--- a/test/api/query.test.cpp
+++ b/test/api/query.test.cpp
@@ -1,4 +1,5 @@
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/test/util.hpp>
@@ -37,7 +38,7 @@ public:
float pixelRatio { 1 };
HeadlessFrontend frontend { pixelRatio, fileSource, threadPool };
Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
- threadPool, MapMode::Static};
+ threadPool, MapOptions().withMapMode(MapMode::Static)};
};
std::vector<Feature> getTopClusterFeature(QueryTest& test) {
diff --git a/test/api/recycle_map.cpp b/test/api/recycle_map.cpp
index fc7e5223ec..0883241274 100644
--- a/test/api/recycle_map.cpp
+++ b/test/api/recycle_map.cpp
@@ -3,6 +3,7 @@
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/renderer/backend_scope.hpp>
#include <mbgl/storage/online_file_source.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
@@ -29,7 +30,8 @@ TEST(API, RecycleMapUpdateImages) {
HeadlessFrontend frontend { pixelRatio, fileSource, threadPool };
auto map = std::make_unique<Map>(frontend, MapObserver::nullObserver(), frontend.getSize(),
- pixelRatio, fileSource, threadPool, MapMode::Static);
+ pixelRatio, fileSource, threadPool,
+ MapOptions().withMapMode(MapMode::Static));
EXPECT_TRUE(map);
diff --git a/test/gl/context.test.cpp b/test/gl/context.test.cpp
index a5f9807a8e..f260555f55 100644
--- a/test/gl/context.test.cpp
+++ b/test/gl/context.test.cpp
@@ -3,6 +3,7 @@
#include <mbgl/platform/gl_functions.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/gl/defines.hpp>
@@ -91,7 +92,8 @@ TEST(GLContextMode, Shared) {
HeadlessFrontend frontend { pixelRatio, fileSource, threadPool, {}, GLContextMode::Shared };
- Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource, threadPool, MapMode::Static);
+ Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio,
+ fileSource, threadPool, MapOptions().withMapMode(MapMode::Static));
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
map.jumpTo(CameraOptions().withCenter(LatLng { 37.8, -122.5 }).withZoom(10.0));
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index 6d1650b82c..5e7981cec2 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -5,6 +5,7 @@
#include <mbgl/test/fixture_log_observer.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/util/default_thread_pool.hpp>
@@ -38,7 +39,8 @@ public:
MapTest(float pixelRatio = 1, MapMode mode = MapMode::Static)
: frontend(pixelRatio, fileSource, threadPool)
- , map(frontend, observer, frontend.getSize(), pixelRatio, fileSource, threadPool, mode) {
+ , map(frontend, observer, frontend.getSize(), pixelRatio,
+ fileSource, threadPool, MapOptions().withMapMode(mode)) {
}
template <typename T = FileSource>
@@ -47,7 +49,8 @@ public:
typename std::enable_if<std::is_same<T, DefaultFileSource>::value>::type* = 0)
: fileSource { cachePath, assetRoot }
, frontend(pixelRatio, fileSource, threadPool)
- , map(frontend, observer, frontend.getSize(), pixelRatio, fileSource, threadPool, mode) {
+ , map(frontend, observer, frontend.getSize(), pixelRatio,
+ fileSource, threadPool, MapOptions().withMapMode(mode)) {
}
};
@@ -683,7 +686,8 @@ TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) {
});
};
- Map map(frontend, observer, frontend.getSize(), pixelRatio, fileSource, threadPool, MapMode::Continuous);
+ Map map(frontend, observer, frontend.getSize(), pixelRatio, fileSource,
+ threadPool, MapOptions().withMapMode(MapMode::Continuous));
map.getStyle().loadJSON(util::read_file("test/fixtures/api/water.json"));
runLoop.run();
diff --git a/test/map/prefetch.test.cpp b/test/map/prefetch.test.cpp
index 9e513d61cd..9b7d620739 100644
--- a/test/map/prefetch.test.cpp
+++ b/test/map/prefetch.test.cpp
@@ -3,6 +3,7 @@
#include <mbgl/test/stub_map_observer.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/style/style.hpp>
@@ -37,7 +38,8 @@ TEST(Map, PrefetchTiles) {
};
HeadlessFrontend frontend { { 512, 512 }, 1, fileSource, threadPool };
- Map map(frontend, observer, frontend.getSize(), 1, fileSource, threadPool, MapMode::Continuous);
+ Map map(frontend, observer, frontend.getSize(), 1, fileSource, threadPool,
+ MapOptions().withMapMode(MapMode::Continuous));
std::vector<int> tiles;
diff --git a/test/text/local_glyph_rasterizer.test.cpp b/test/text/local_glyph_rasterizer.test.cpp
index 0dfec1689a..20f825c935 100644
--- a/test/text/local_glyph_rasterizer.test.cpp
+++ b/test/text/local_glyph_rasterizer.test.cpp
@@ -1,6 +1,7 @@
#include <mbgl/test/util.hpp>
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/color.hpp>
@@ -42,7 +43,7 @@ public:
float pixelRatio { 1 };
HeadlessFrontend frontend;
Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
- threadPool, MapMode::Static};
+ threadPool, MapOptions().withMapMode(MapMode::Static)};
void checkRendering(const char * name) {
test::checkImage(std::string("test/fixtures/local_glyphs/") + name,
diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp
index e92311226b..a0e64a6704 100644
--- a/test/util/memory.test.cpp
+++ b/test/util/memory.test.cpp
@@ -3,6 +3,7 @@
#include <mbgl/test/util.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/map_options.hpp>
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/util/io.hpp>
@@ -72,7 +73,7 @@ TEST(Memory, Vector) {
HeadlessFrontend frontend { { 256, 256 }, ratio, test.fileSource, test.threadPool };
Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), ratio, test.fileSource,
- test.threadPool, MapMode::Static);
+ test.threadPool, MapOptions().withMapMode(MapMode::Static));
map.jumpTo(CameraOptions().withZoom(16));
map.getStyle().loadURL("mapbox://streets");
@@ -85,7 +86,7 @@ TEST(Memory, Raster) {
HeadlessFrontend frontend { { 256, 256 }, ratio, test.fileSource, test.threadPool };
Map map(frontend, MapObserver::nullObserver(), frontend.getSize(), ratio, test.fileSource,
- test.threadPool, MapMode::Static);
+ test.threadPool, MapOptions().withMapMode(MapMode::Static));
map.getStyle().loadURL("mapbox://satellite");
frontend.render(map);
@@ -122,7 +123,8 @@ TEST(Memory, Footprint) {
public:
FrontendAndMap(MemoryTest& test_, const char* style)
: frontend(Size{ 256, 256 }, 2, test_.fileSource, test_.threadPool)
- , map(frontend, MapObserver::nullObserver(), frontend.getSize(), 2, test_.fileSource, test_.threadPool, MapMode::Static) {
+ , map(frontend, MapObserver::nullObserver(), frontend.getSize(), 2, test_.fileSource
+ , test_.threadPool, MapOptions().withMapMode(MapMode::Static)) {
map.jumpTo(CameraOptions().withZoom(16));
map.getStyle().loadURL(style);
frontend.render(map);