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

Commit

Permalink
[core] add MapChangeDidFinishLoadingStyle signal
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed Sep 19, 2016
1 parent 1014a50 commit 2f62f97
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/mbgl/map/change.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum MapChange : uint8_t {
MapChangeWillStartRenderingMap = 11,
MapChangeDidFinishRenderingMap = 12,
MapChangeDidFinishRenderingMapFullyRendered = 13,
MapChangeDidFinishLoadingStyle = 14
};

} // namespace mbgl
5 changes: 5 additions & 0 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Map::Impl : public style::Observer {
Impl(View&, FileSource&, MapMode, GLContextMode, ConstrainMode, ViewportMode);

void onUpdate(Update) override;
void onStyleLoaded() override;
void onStyleError() override;
void onResourceError(std::exception_ptr) override;

Expand Down Expand Up @@ -965,6 +966,10 @@ void Map::Impl::onUpdate(Update flags) {
updateFlags |= flags;
asyncUpdate.send();
}

void Map::Impl::onStyleLoaded() {
view.notifyMapChange(MapChangeDidFinishLoadingStyle);
}

void Map::Impl::onStyleError() {
view.notifyMapChange(MapChangeDidFailLoadingMap);
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/style/observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Observer : public GlyphStoreObserver,
public:
virtual void onUpdate(Update) {}
virtual void onStyleError() {}
virtual void onStyleLoaded() {}
virtual void onResourceError(std::exception_ptr) {}
};

Expand Down
2 changes: 2 additions & 0 deletions src/mbgl/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ void Style::setJSON(const std::string& json) {
observer->onResourceError(error);

return;
} else {
observer->onStyleLoaded();
}

for (auto& source : parser.sources) {
Expand Down
20 changes: 20 additions & 0 deletions test/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,26 @@ TEST(Map, StyleEarlyMutation) {
EXPECT_NE(nullptr, map.getLayer("water"));
}

TEST(Map, StyleLoadedSignal) {
MapTest test;
Map map(test.view, test.fileSource, MapMode::Still);

// The map should emit a signal on style loaded
bool emitted = false;
test.view.setMapChangeCallback([&](MapChange change) {
if (change == mbgl::MapChangeDidFinishLoadingStyle) {
emitted = true;
}
});
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
EXPECT_TRUE(emitted);

// But not when the style couldn't be parsed
emitted = false;
map.setStyleJSON("invalid");
EXPECT_FALSE(emitted);
}

TEST(Map, AddLayer) {
MapTest test;

Expand Down

0 comments on commit 2f62f97

Please sign in to comment.