summaryrefslogtreecommitdiff
path: root/src/mbgl/style
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-05-15 14:09:06 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-05-16 12:26:35 -0700
commitcc1ea759a681cadcfd06fd7bdda79ca6deb38c62 (patch)
tree97ece422b0516b11979c84b8136f95aeabb1aa91 /src/mbgl/style
parentc0f6e5ccefc67dbdaa6ab7c7ea75a2a2d0c3f2ae (diff)
downloadqtlocation-mapboxgl-cc1ea759a681cadcfd06fd7bdda79ca6deb38c62.tar.gz
[core, node, darwin, android, qt] Make image ID part of Image
More like Source and Layer.
Diffstat (limited to 'src/mbgl/style')
-rw-r--r--src/mbgl/style/image.cpp9
-rw-r--r--src/mbgl/style/image_impl.cpp10
-rw-r--r--src/mbgl/style/image_impl.hpp4
-rw-r--r--src/mbgl/style/style.cpp22
-rw-r--r--src/mbgl/style/style.hpp4
5 files changed, 25 insertions, 24 deletions
diff --git a/src/mbgl/style/image.cpp b/src/mbgl/style/image.cpp
index 606d9907a4..3b35fa76f1 100644
--- a/src/mbgl/style/image.cpp
+++ b/src/mbgl/style/image.cpp
@@ -5,10 +5,15 @@
namespace mbgl {
namespace style {
-Image::Image(PremultipliedImage &&image,
+Image::Image(std::string id,
+ PremultipliedImage &&image,
const float pixelRatio,
bool sdf)
- : impl(makeMutable<Impl>(std::move(image), pixelRatio, sdf)) {
+ : impl(makeMutable<Impl>(std::move(id), std::move(image), pixelRatio, sdf)) {
+}
+
+std::string Image::getID() const {
+ return impl->id;
}
const PremultipliedImage& Image::getImage() const {
diff --git a/src/mbgl/style/image_impl.cpp b/src/mbgl/style/image_impl.cpp
index 910bffa905..ce327262e8 100644
--- a/src/mbgl/style/image_impl.cpp
+++ b/src/mbgl/style/image_impl.cpp
@@ -4,10 +4,12 @@
namespace mbgl {
namespace style {
-Image::Impl::Impl(PremultipliedImage&& image_,
- const float pixelRatio_,
- bool sdf_)
- : image(std::move(image_)),
+Image::Impl::Impl(std::string id_,
+ PremultipliedImage&& image_,
+ const float pixelRatio_,
+ bool sdf_)
+ : id(std::move(id_)),
+ image(std::move(image_)),
pixelRatio(pixelRatio_),
sdf(sdf_) {
diff --git a/src/mbgl/style/image_impl.hpp b/src/mbgl/style/image_impl.hpp
index dce4a6e4c0..b088a23261 100644
--- a/src/mbgl/style/image_impl.hpp
+++ b/src/mbgl/style/image_impl.hpp
@@ -7,7 +7,9 @@ namespace style {
class Image::Impl {
public:
- Impl(PremultipliedImage&&, float pixelRatio, bool sdf = false);
+ Impl(std::string id, PremultipliedImage&&, float pixelRatio, bool sdf = false);
+
+ const std::string id;
PremultipliedImage image;
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index f601c4126c..84ee841c06 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -505,9 +505,9 @@ bool Style::isLoaded() const {
return true;
}
-void Style::addImage(const std::string& id, std::unique_ptr<style::Image> image) {
- addSpriteImage(spriteImages, id, std::move(image), [&](style::Image& added) {
- spriteAtlas->addImage(id, added.impl);
+void Style::addImage(std::unique_ptr<style::Image> image) {
+ addSpriteImage(spriteImages, std::move(image), [&](style::Image& added) {
+ spriteAtlas->addImage(added.impl);
observer->onUpdate(Update::Repaint);
});
}
@@ -735,19 +735,11 @@ void Style::onTileError(RenderSource& source, const OverscaledTileID& tileID, st
observer->onResourceError(error);
}
-void Style::onSpriteLoaded(SpriteLoader::Images&& images) {
- // Add images to collection
- Images addedImages;
- for (auto& entry : images) {
- addSpriteImage(spriteImages, entry.first, std::move(entry.second), [&] (style::Image& added) {
- addedImages.emplace(entry.first, std::make_unique<Image>(added));
- });
+void Style::onSpriteLoaded(std::vector<std::unique_ptr<Image>>&& images) {
+ for (auto& image : images) {
+ addImage(std::move(image));
}
-
- // Update render sprite atlas
- spriteAtlas->onSpriteLoaded(std::move(addedImages));
-
- // Update observer
+ spriteAtlas->onSpriteLoaded();
observer->onUpdate(Update::Repaint); // For *-pattern properties.
}
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index b4ff4f9ac4..bc1d52eed8 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -101,7 +101,7 @@ public:
const RenderLight& getRenderLight() const;
const style::Image* getImage(const std::string&) const;
- void addImage(const std::string&, std::unique_ptr<style::Image>);
+ void addImage(std::unique_ptr<style::Image>);
void removeImage(const std::string&);
RenderData getRenderData(MapDebugOptions, float angle) const;
@@ -151,7 +151,7 @@ private:
// SpriteLoaderObserver implementation.
std::unordered_map<std::string, std::unique_ptr<style::Image>> spriteImages;
- void onSpriteLoaded(SpriteLoaderObserver::Images&&) override;
+ void onSpriteLoaded(std::vector<std::unique_ptr<Image>>&&) override;
void onSpriteError(std::exception_ptr) override;
// SourceObserver implementation.