[core] Source-driven attribution

Implemented observer callbacks so the style knows when the source’s attribution changes and the map knows when the style’s attribution changes. Also implemented a getter for a tile source’s attribution.

Fixes #2723.
This commit is contained in:
Minh Nguyễn
2016-08-13 11:30:15 -07:00
committed by Minh Nguyễn
parent 78af55f30a
commit f307652548
13 changed files with 103 additions and 6 deletions

View File

@@ -82,6 +82,7 @@ void TileSourceImpl::loadDescription(FileSource& fileSource) {
}
// Check whether previous information specifies different tile
bool attributionChanged = false;
if (tileset.tiles != newTileset.tiles) {
// Tile URLs changed: force tiles to be reloaded.
invalidateTiles();
@@ -95,8 +96,8 @@ void TileSourceImpl::loadDescription(FileSource& fileSource) {
// This is done automatically when we trigger the onSourceLoaded observer below.
// Attribution changed: We need to notify the embedding application that this
// changed. See https://github.com/mapbox/mapbox-gl-native/issues/2723
// This is not yet implemented.
// changed.
attributionChanged = true;
// Center/bounds changed: We're not using these values currently
}
@@ -105,6 +106,9 @@ void TileSourceImpl::loadDescription(FileSource& fileSource) {
loaded = true;
observer->onSourceLoaded(base);
if (attributionChanged) {
observer->onSourceAttributionChanged(base, newTileset.attribution);
}
}
});
}
@@ -114,5 +118,9 @@ Range<uint8_t> TileSourceImpl::getZoomRange() {
return tileset.zoomRange;
}
std::string TileSourceImpl::getAttribution() const {
return loaded ? tileset.attribution : "";
}
} // namespace style
} // namespace mbgl