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

Commit 0d224b5

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 1014a50 commit 0d224b5

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 icon, bound to the style
165+
void addIcon(const std::string&, std::shared_ptr<const SpriteImage>);
166+
void removeIcon(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
@@ -822,6 +822,30 @@ void Map::removeLayer(const std::string& id) {
822822
impl->view.deactivate();
823823
}
824824

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

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

0 commit comments

Comments
 (0)