Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 486bddd

Browse files
committed
[core] Add interface to add sprites to the style
Unlike annotations, they will go away when we change the style.
1 parent e8d4726 commit 486bddd

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

include/mbgl/map/map.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ class Map : private util::noncopyable {
161161
void addLayer(std::unique_ptr<style::Layer>, const optional<std::string>& beforeLayerID = {});
162162
void removeLayer(const std::string& layerID);
163163

164+
// Add image, bound to the style
165+
void addImage(const std::string&, std::unique_ptr<const SpriteImage>);
166+
void removeImage(const std::string&);
167+
164168
// Defaults
165169
std::string getStyleName() const;
166170
LatLng getDefaultLatLng() const;

src/mbgl/map/map.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,30 @@ void Map::removeLayer(const std::string& id) {
823823
impl->view.deactivate();
824824
}
825825

826+
void Map::addImage(const std::string& name, std::unique_ptr<const SpriteImage> image) {
827+
if (!impl->style) {
828+
return;
829+
}
830+
831+
impl->styleMutated = true;
832+
impl->style->spriteAtlas->setSprite(name, std::move(image));
833+
impl->style->spriteAtlas->updateDirty();
834+
835+
update(Update::Repaint);
836+
}
837+
838+
void Map::removeImage(const std::string& name) {
839+
if (!impl->style) {
840+
return;
841+
}
842+
843+
impl->styleMutated = true;
844+
impl->style->spriteAtlas->removeSprite(name);
845+
impl->style->spriteAtlas->updateDirty();
846+
847+
update(Update::Repaint);
848+
}
849+
826850
#pragma mark - Defaults
827851

828852
std::string Map::getStyleName() const {

0 commit comments

Comments
 (0)