From 486bdddb23c93572c29068a229041b2575f383e8 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Tue, 13 Sep 2016 18:32:45 -0700 Subject: [PATCH] [core] Add interface to add sprites to the style Unlike annotations, they will go away when we change the style. --- include/mbgl/map/map.hpp | 4 ++++ src/mbgl/map/map.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 6c478c17f..914c2cd0b 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -161,6 +161,10 @@ public: void addLayer(std::unique_ptr, const optional& beforeLayerID = {}); void removeLayer(const std::string& layerID); + // Add image, bound to the style + void addImage(const std::string&, std::unique_ptr); + void removeImage(const std::string&); + // Defaults std::string getStyleName() const; LatLng getDefaultLatLng() const; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 1c376e40a..3ff02aae7 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -823,6 +823,30 @@ void Map::removeLayer(const std::string& id) { impl->view.deactivate(); } +void Map::addImage(const std::string& name, std::unique_ptr image) { + if (!impl->style) { + return; + } + + impl->styleMutated = true; + impl->style->spriteAtlas->setSprite(name, std::move(image)); + impl->style->spriteAtlas->updateDirty(); + + update(Update::Repaint); +} + +void Map::removeImage(const std::string& name) { + if (!impl->style) { + return; + } + + impl->styleMutated = true; + impl->style->spriteAtlas->removeSprite(name); + impl->style->spriteAtlas->updateDirty(); + + update(Update::Repaint); +} + #pragma mark - Defaults std::string Map::getStyleName() const {