summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuha Alanen <juha.alanen@mapbox.com>2019-09-09 15:39:29 +0300
committerJuha Alanen <juha.alanen@mapbox.com>2019-09-10 16:28:47 +0300
commitc90aa3988045eed4b724088a4a4a2df60995f9bc (patch)
treeac69647b969069363899bcbcdc1bc0925284b8de
parent151ea331f87a8d3655b0b1a36f3e74de4ff708b9 (diff)
downloadqtlocation-mapboxgl-upstream/jmalanen-camerainit.tar.gz
[core] Add API to set camera when initializing mapupstream/jmalanen-camerainit
-rw-r--r--include/mbgl/map/map_options.hpp16
-rw-r--r--include/mbgl/style/style.hpp1
-rw-r--r--src/mbgl/map/map_impl.cpp2
-rw-r--r--src/mbgl/map/map_options.cpp10
-rw-r--r--src/mbgl/style/style.cpp4
-rw-r--r--src/mbgl/style/style_impl.cpp5
-rw-r--r--src/mbgl/style/style_impl.hpp1
7 files changed, 38 insertions, 1 deletions
diff --git a/include/mbgl/map/map_options.hpp b/include/mbgl/map/map_options.hpp
index fcb8c8f32f..52c06a600f 100644
--- a/include/mbgl/map/map_options.hpp
+++ b/include/mbgl/map/map_options.hpp
@@ -3,6 +3,7 @@
#include <mbgl/map/mode.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/size.hpp>
+#include <mbgl/map/camera.hpp>
#include <memory>
@@ -134,6 +135,21 @@ public:
*/
float pixelRatio() const;
+ /**
+ * @brief Sets the camera options.
+ *
+ * @param camera_ Camera options.
+ * @return reference to MapOptions for chaining options together.
+ */
+ MapOptions& withCamera(CameraOptions camera_);
+
+ /**
+ * @brief Gets the previously set camera options.
+ *
+ * @return Camera options.
+ */
+ const CameraOptions& camera() const;
+
private:
class Impl;
std::unique_ptr<Impl> impl_;
diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp
index 4a6a542b88..da8ddd53e7 100644
--- a/include/mbgl/style/style.hpp
+++ b/include/mbgl/style/style.hpp
@@ -22,6 +22,7 @@ class Layer;
class Style {
public:
Style(FileSource&, float pixelRatio);
+ Style(FileSource&, float pixelRatio, CameraOptions camera);
~Style();
void loadJSON(const std::string&);
diff --git a/src/mbgl/map/map_impl.cpp b/src/mbgl/map/map_impl.cpp
index ea55dfd1a8..1a60881f14 100644
--- a/src/mbgl/map/map_impl.cpp
+++ b/src/mbgl/map/map_impl.cpp
@@ -18,7 +18,7 @@ Map::Impl::Impl(RendererFrontend& frontend_,
pixelRatio(mapOptions.pixelRatio()),
crossSourceCollisions(mapOptions.crossSourceCollisions()),
fileSource(std::move(fileSource_)),
- style(std::make_unique<style::Style>(*fileSource, pixelRatio)),
+ style(std::make_unique<style::Style>(*fileSource, pixelRatio, mapOptions.camera())),
annotationManager(*style) {
transform.setNorthOrientation(mapOptions.northOrientation());
style->impl->setObserver(this);
diff --git a/src/mbgl/map/map_options.cpp b/src/mbgl/map/map_options.cpp
index 4cebb6adab..d177da5fd5 100644
--- a/src/mbgl/map/map_options.cpp
+++ b/src/mbgl/map/map_options.cpp
@@ -11,6 +11,7 @@ public:
bool crossSourceCollisions = true;
Size size = { 64, 64 };
float pixelRatio = 1.0;
+ CameraOptions camera;
};
// These requires the complete type of Impl.
@@ -81,4 +82,13 @@ float MapOptions::pixelRatio() const {
return impl_->pixelRatio;
}
+MapOptions& MapOptions::withCamera(CameraOptions camera_) {
+ impl_->camera = std::move(camera_);
+ return *this;
+}
+
+const CameraOptions& MapOptions::camera() const {
+ return impl_->camera;
+}
+
} // namespace mbgl
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index 783c850097..e58461926b 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -12,6 +12,10 @@ Style::Style(FileSource& fileSource, float pixelRatio)
: impl(std::make_unique<Impl>(fileSource, pixelRatio)) {
}
+Style::Style(FileSource& fileSource, float pixelRatio, CameraOptions camera)
+ : impl(std::make_unique<Impl>(fileSource, pixelRatio, std::move(camera))) {
+}
+
Style::~Style() = default;
void Style::loadJSON(const std::string& json) {
diff --git a/src/mbgl/style/style_impl.cpp b/src/mbgl/style/style_impl.cpp
index d3298c5cac..d465f84827 100644
--- a/src/mbgl/style/style_impl.cpp
+++ b/src/mbgl/style/style_impl.cpp
@@ -36,6 +36,11 @@ Style::Impl::Impl(FileSource& fileSource_, float pixelRatio)
light->setObserver(this);
}
+Style::Impl::Impl(FileSource& fileSource_, float pixelRatio, CameraOptions camera)
+ : Impl(fileSource_, pixelRatio) {
+ defaultCamera = std::move(camera);
+}
+
Style::Impl::~Impl() = default;
void Style::Impl::loadJSON(const std::string& json_) {
diff --git a/src/mbgl/style/style_impl.hpp b/src/mbgl/style/style_impl.hpp
index 4c56f6785b..5dccba5171 100644
--- a/src/mbgl/style/style_impl.hpp
+++ b/src/mbgl/style/style_impl.hpp
@@ -38,6 +38,7 @@ class Style::Impl : public SpriteLoaderObserver,
public util::noncopyable {
public:
Impl(FileSource&, float pixelRatio);
+ Impl(FileSource&, float pixelRatio, CameraOptions camera);
~Impl() override;
void loadJSON(const std::string&);