[core] Separate transition options accessors from class API
Now the style class transition options have its own getter/setter, which persists for each style until a new style is set.
This commit is contained in:
@@ -51,9 +51,12 @@ public:
|
||||
void update(Update update);
|
||||
|
||||
// Styling
|
||||
void addClass(const std::string&, const style::TransitionOptions& = {});
|
||||
void removeClass(const std::string&, const style::TransitionOptions& = {});
|
||||
void setClasses(const std::vector<std::string>&, const style::TransitionOptions& = {});
|
||||
void addClass(const std::string&);
|
||||
void removeClass(const std::string&);
|
||||
void setClasses(const std::vector<std::string>&);
|
||||
|
||||
style::TransitionOptions getTransitionOptions() const;
|
||||
void setTransitionOptions(const style::TransitionOptions&);
|
||||
|
||||
bool hasClass(const std::string&) const;
|
||||
std::vector<std::string> getClasses() const;
|
||||
|
||||
@@ -896,25 +896,38 @@ bool Map::isFullyLoaded() const {
|
||||
return impl->style ? impl->style->isLoaded() : false;
|
||||
}
|
||||
|
||||
void Map::addClass(const std::string& className, const TransitionOptions& properties) {
|
||||
if (impl->style && impl->style->addClass(className, properties)) {
|
||||
void Map::addClass(const std::string& className) {
|
||||
if (impl->style && impl->style->addClass(className)) {
|
||||
update(Update::Classes);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::removeClass(const std::string& className, const TransitionOptions& properties) {
|
||||
if (impl->style && impl->style->removeClass(className, properties)) {
|
||||
void Map::removeClass(const std::string& className) {
|
||||
if (impl->style && impl->style->removeClass(className)) {
|
||||
update(Update::Classes);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::setClasses(const std::vector<std::string>& classNames, const TransitionOptions& properties) {
|
||||
void Map::setClasses(const std::vector<std::string>& classNames) {
|
||||
if (impl->style) {
|
||||
impl->style->setClasses(classNames, properties);
|
||||
impl->style->setClasses(classNames);
|
||||
update(Update::Classes);
|
||||
}
|
||||
}
|
||||
|
||||
style::TransitionOptions Map::getTransitionOptions() const {
|
||||
if (impl->style) {
|
||||
return impl->style->getTransitionOptions();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void Map::setTransitionOptions(const style::TransitionOptions& options) {
|
||||
if (impl->style) {
|
||||
impl->style->setTransitionOptions(options);
|
||||
}
|
||||
}
|
||||
|
||||
bool Map::hasClass(const std::string& className) const {
|
||||
return impl->style ? impl->style->hasClass(className) : false;
|
||||
}
|
||||
|
||||
@@ -58,10 +58,9 @@ Style::~Style() {
|
||||
spriteStore->setObserver(nullptr);
|
||||
}
|
||||
|
||||
bool Style::addClass(const std::string& className, const TransitionOptions& properties) {
|
||||
bool Style::addClass(const std::string& className) {
|
||||
if (hasClass(className)) return false;
|
||||
classes.push_back(className);
|
||||
transitionProperties = properties;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -69,29 +68,36 @@ bool Style::hasClass(const std::string& className) const {
|
||||
return std::find(classes.begin(), classes.end(), className) != classes.end();
|
||||
}
|
||||
|
||||
bool Style::removeClass(const std::string& className, const TransitionOptions& properties) {
|
||||
bool Style::removeClass(const std::string& className) {
|
||||
const auto it = std::find(classes.begin(), classes.end(), className);
|
||||
if (it != classes.end()) {
|
||||
classes.erase(it);
|
||||
transitionProperties = properties;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Style::setClasses(const std::vector<std::string>& classNames, const TransitionOptions& properties) {
|
||||
void Style::setClasses(const std::vector<std::string>& classNames) {
|
||||
classes = classNames;
|
||||
transitionProperties = properties;
|
||||
}
|
||||
|
||||
std::vector<std::string> Style::getClasses() const {
|
||||
return classes;
|
||||
}
|
||||
|
||||
void Style::setTransitionOptions(const TransitionOptions& options) {
|
||||
transitionOptions = options;
|
||||
}
|
||||
|
||||
TransitionOptions Style::getTransitionOptions() const {
|
||||
return transitionOptions;
|
||||
}
|
||||
|
||||
void Style::setJSON(const std::string& json) {
|
||||
sources.clear();
|
||||
layers.clear();
|
||||
classes.clear();
|
||||
transitionOptions = {};
|
||||
updateBatch = {};
|
||||
|
||||
Parser parser;
|
||||
@@ -249,11 +255,9 @@ void Style::cascade(const TimePoint& timePoint, MapMode mode) {
|
||||
const CascadeParameters parameters {
|
||||
classIDs,
|
||||
mode == MapMode::Continuous ? timePoint : Clock::time_point::max(),
|
||||
mode == MapMode::Continuous ? transitionProperties.value_or(immediateTransition) : immediateTransition
|
||||
mode == MapMode::Continuous ? transitionOptions : immediateTransition
|
||||
};
|
||||
|
||||
transitionProperties = {};
|
||||
|
||||
for (const auto& layer : layers) {
|
||||
layer->baseImpl->cascade(parameters);
|
||||
}
|
||||
|
||||
@@ -79,10 +79,14 @@ public:
|
||||
double getDefaultBearing() const;
|
||||
double getDefaultPitch() const;
|
||||
|
||||
bool addClass(const std::string&, const TransitionOptions& = {});
|
||||
bool removeClass(const std::string&, const TransitionOptions& = {});
|
||||
bool addClass(const std::string&);
|
||||
bool removeClass(const std::string&);
|
||||
void setClasses(const std::vector<std::string>&);
|
||||
|
||||
TransitionOptions getTransitionOptions() const;
|
||||
void setTransitionOptions(const TransitionOptions&);
|
||||
|
||||
bool hasClass(const std::string&) const;
|
||||
void setClasses(const std::vector<std::string>&, const TransitionOptions& = {});
|
||||
std::vector<std::string> getClasses() const;
|
||||
|
||||
RenderData getRenderData(MapDebugOptions) const;
|
||||
@@ -107,7 +111,7 @@ private:
|
||||
std::vector<std::unique_ptr<Source>> sources;
|
||||
std::vector<std::unique_ptr<Layer>> layers;
|
||||
std::vector<std::string> classes;
|
||||
optional<TransitionOptions> transitionProperties;
|
||||
TransitionOptions transitionOptions;
|
||||
|
||||
// Defaults
|
||||
std::string name;
|
||||
|
||||
Reference in New Issue
Block a user