diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-15 14:53:25 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-06-16 13:27:15 -0700 |
commit | 5254127e8c9d2f9dbfb19c2245717c3461107c50 (patch) | |
tree | ffbb215c3ea56ab72df1f7df99b5104d056eae44 /src | |
parent | 9d6b50828e2cbce2d0e8a9611b1dccad5123a4bd (diff) | |
download | qtlocation-mapboxgl-5254127e8c9d2f9dbfb19c2245717c3461107c50.tar.gz |
[core] Runtime source API: Map methods
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/map.cpp | 13 | ||||
-rw-r--r-- | src/mbgl/style/style.cpp | 9 | ||||
-rw-r--r-- | src/mbgl/style/style.hpp | 1 |
3 files changed, 23 insertions, 0 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index ae9330abae..b599268bf3 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -5,6 +5,7 @@ #include <mbgl/map/transform_state.hpp> #include <mbgl/annotation/annotation_manager.hpp> #include <mbgl/style/style.hpp> +#include <mbgl/style/source.hpp> #include <mbgl/style/layer.hpp> #include <mbgl/style/observer.hpp> #include <mbgl/style/transition_options.hpp> @@ -736,6 +737,18 @@ std::vector<Feature> Map::queryRenderedFeatures(const ScreenBox& box, const opti #pragma mark - Style API +style::Source* Map::getSource(const std::string& sourceID) { + return impl->style ? impl->style->getSource(sourceID) : nullptr; +} + +void Map::addSource(std::unique_ptr<style::Source> source) { + impl->style->addSource(std::move(source)); +} + +void Map::removeSource(const std::string& sourceID) { + impl->style->removeSource(sourceID); +} + style::Layer* Map::getLayer(const std::string& layerID) { return impl->style ? impl->style->getLayer(layerID) : nullptr; } diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index a75133f82d..d825e57640 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -111,6 +111,15 @@ void Style::addSource(std::unique_ptr<Source> source) { sources.emplace_back(std::move(source)); } +void Style::removeSource(const std::string& id) { + auto it = std::find_if(sources.begin(), sources.end(), [&](const auto& source) { + return source->getID() == id; + }); + if (it == sources.end()) + throw std::runtime_error("no such source"); + sources.erase(it); +} + std::vector<std::unique_ptr<Layer>> Style::getLayers() const { std::vector<std::unique_ptr<Layer>> result; result.reserve(layers.size()); diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 6059c87555..e83cab8050 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -60,6 +60,7 @@ public: Source* getSource(const std::string& id) const; void addSource(std::unique_ptr<Source>); + void removeSource(const std::string& sourceID); std::vector<std::unique_ptr<Layer>> getLayers() const; Layer* getLayer(const std::string& id) const; |