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

[core] Restore support for *-transition properties #8008

Merged
merged 1 commit into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,16 @@ set(MBGL_CORE_FILES
include/mbgl/style/conversion/property_value.hpp
include/mbgl/style/conversion/source.hpp
include/mbgl/style/conversion/tileset.hpp
include/mbgl/style/conversion/transition_options.hpp
src/mbgl/style/conversion/stringify.hpp

# style/function
include/mbgl/style/function/camera_function.hpp
include/mbgl/style/function/categorical_stops.hpp
include/mbgl/style/function/composite_categorical_stops.hpp
include/mbgl/style/function/composite_exponential_stops.hpp
include/mbgl/style/function/composite_function.hpp
include/mbgl/style/function/composite_interval_stops.hpp
include/mbgl/style/function/exponential_stops.hpp
include/mbgl/style/function/identity_stops.hpp
include/mbgl/style/function/interval_stops.hpp
Expand Down
1 change: 1 addition & 0 deletions cmake/test-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ set(MBGL_TEST_FILES
# style/conversion
test/style/conversion/function.test.cpp
test/style/conversion/geojson_options.test.cpp
test/style/conversion/layer.test.cpp
test/style/conversion/stringify.test.cpp

# style
Expand Down
58 changes: 58 additions & 0 deletions include/mbgl/style/conversion/make_property_setters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,69 +77,127 @@ auto makePaintPropertySetters() {
std::unordered_map<std::string, PaintPropertySetter<V>> result;

result["fill-antialias"] = makePropertySetter<V>(&FillLayer::setFillAntialias);
result["fill-antialias-transition"] = makeTransitionSetter<V>(&FillLayer::setFillAntialiasTransition);
result["fill-opacity"] = makePropertySetter<V>(&FillLayer::setFillOpacity);
result["fill-opacity-transition"] = makeTransitionSetter<V>(&FillLayer::setFillOpacityTransition);
result["fill-color"] = makePropertySetter<V>(&FillLayer::setFillColor);
result["fill-color-transition"] = makeTransitionSetter<V>(&FillLayer::setFillColorTransition);
result["fill-outline-color"] = makePropertySetter<V>(&FillLayer::setFillOutlineColor);
result["fill-outline-color-transition"] = makeTransitionSetter<V>(&FillLayer::setFillOutlineColorTransition);
result["fill-translate"] = makePropertySetter<V>(&FillLayer::setFillTranslate);
result["fill-translate-transition"] = makeTransitionSetter<V>(&FillLayer::setFillTranslateTransition);
result["fill-translate-anchor"] = makePropertySetter<V>(&FillLayer::setFillTranslateAnchor);
result["fill-translate-anchor-transition"] = makeTransitionSetter<V>(&FillLayer::setFillTranslateAnchorTransition);
result["fill-pattern"] = makePropertySetter<V>(&FillLayer::setFillPattern);
result["fill-pattern-transition"] = makeTransitionSetter<V>(&FillLayer::setFillPatternTransition);

result["line-opacity"] = makePropertySetter<V>(&LineLayer::setLineOpacity);
result["line-opacity-transition"] = makeTransitionSetter<V>(&LineLayer::setLineOpacityTransition);
result["line-color"] = makePropertySetter<V>(&LineLayer::setLineColor);
result["line-color-transition"] = makeTransitionSetter<V>(&LineLayer::setLineColorTransition);
result["line-translate"] = makePropertySetter<V>(&LineLayer::setLineTranslate);
result["line-translate-transition"] = makeTransitionSetter<V>(&LineLayer::setLineTranslateTransition);
result["line-translate-anchor"] = makePropertySetter<V>(&LineLayer::setLineTranslateAnchor);
result["line-translate-anchor-transition"] = makeTransitionSetter<V>(&LineLayer::setLineTranslateAnchorTransition);
result["line-width"] = makePropertySetter<V>(&LineLayer::setLineWidth);
result["line-width-transition"] = makeTransitionSetter<V>(&LineLayer::setLineWidthTransition);
result["line-gap-width"] = makePropertySetter<V>(&LineLayer::setLineGapWidth);
result["line-gap-width-transition"] = makeTransitionSetter<V>(&LineLayer::setLineGapWidthTransition);
result["line-offset"] = makePropertySetter<V>(&LineLayer::setLineOffset);
result["line-offset-transition"] = makeTransitionSetter<V>(&LineLayer::setLineOffsetTransition);
result["line-blur"] = makePropertySetter<V>(&LineLayer::setLineBlur);
result["line-blur-transition"] = makeTransitionSetter<V>(&LineLayer::setLineBlurTransition);
result["line-dasharray"] = makePropertySetter<V>(&LineLayer::setLineDasharray);
result["line-dasharray-transition"] = makeTransitionSetter<V>(&LineLayer::setLineDasharrayTransition);
result["line-pattern"] = makePropertySetter<V>(&LineLayer::setLinePattern);
result["line-pattern-transition"] = makeTransitionSetter<V>(&LineLayer::setLinePatternTransition);

result["icon-opacity"] = makePropertySetter<V>(&SymbolLayer::setIconOpacity);
result["icon-opacity-transition"] = makeTransitionSetter<V>(&SymbolLayer::setIconOpacityTransition);
result["icon-color"] = makePropertySetter<V>(&SymbolLayer::setIconColor);
result["icon-color-transition"] = makeTransitionSetter<V>(&SymbolLayer::setIconColorTransition);
result["icon-halo-color"] = makePropertySetter<V>(&SymbolLayer::setIconHaloColor);
result["icon-halo-color-transition"] = makeTransitionSetter<V>(&SymbolLayer::setIconHaloColorTransition);
result["icon-halo-width"] = makePropertySetter<V>(&SymbolLayer::setIconHaloWidth);
result["icon-halo-width-transition"] = makeTransitionSetter<V>(&SymbolLayer::setIconHaloWidthTransition);
result["icon-halo-blur"] = makePropertySetter<V>(&SymbolLayer::setIconHaloBlur);
result["icon-halo-blur-transition"] = makeTransitionSetter<V>(&SymbolLayer::setIconHaloBlurTransition);
result["icon-translate"] = makePropertySetter<V>(&SymbolLayer::setIconTranslate);
result["icon-translate-transition"] = makeTransitionSetter<V>(&SymbolLayer::setIconTranslateTransition);
result["icon-translate-anchor"] = makePropertySetter<V>(&SymbolLayer::setIconTranslateAnchor);
result["icon-translate-anchor-transition"] = makeTransitionSetter<V>(&SymbolLayer::setIconTranslateAnchorTransition);
result["text-opacity"] = makePropertySetter<V>(&SymbolLayer::setTextOpacity);
result["text-opacity-transition"] = makeTransitionSetter<V>(&SymbolLayer::setTextOpacityTransition);
result["text-color"] = makePropertySetter<V>(&SymbolLayer::setTextColor);
result["text-color-transition"] = makeTransitionSetter<V>(&SymbolLayer::setTextColorTransition);
result["text-halo-color"] = makePropertySetter<V>(&SymbolLayer::setTextHaloColor);
result["text-halo-color-transition"] = makeTransitionSetter<V>(&SymbolLayer::setTextHaloColorTransition);
result["text-halo-width"] = makePropertySetter<V>(&SymbolLayer::setTextHaloWidth);
result["text-halo-width-transition"] = makeTransitionSetter<V>(&SymbolLayer::setTextHaloWidthTransition);
result["text-halo-blur"] = makePropertySetter<V>(&SymbolLayer::setTextHaloBlur);
result["text-halo-blur-transition"] = makeTransitionSetter<V>(&SymbolLayer::setTextHaloBlurTransition);
result["text-translate"] = makePropertySetter<V>(&SymbolLayer::setTextTranslate);
result["text-translate-transition"] = makeTransitionSetter<V>(&SymbolLayer::setTextTranslateTransition);
result["text-translate-anchor"] = makePropertySetter<V>(&SymbolLayer::setTextTranslateAnchor);
result["text-translate-anchor-transition"] = makeTransitionSetter<V>(&SymbolLayer::setTextTranslateAnchorTransition);

result["circle-radius"] = makePropertySetter<V>(&CircleLayer::setCircleRadius);
result["circle-radius-transition"] = makeTransitionSetter<V>(&CircleLayer::setCircleRadiusTransition);
result["circle-color"] = makePropertySetter<V>(&CircleLayer::setCircleColor);
result["circle-color-transition"] = makeTransitionSetter<V>(&CircleLayer::setCircleColorTransition);
result["circle-blur"] = makePropertySetter<V>(&CircleLayer::setCircleBlur);
result["circle-blur-transition"] = makeTransitionSetter<V>(&CircleLayer::setCircleBlurTransition);
result["circle-opacity"] = makePropertySetter<V>(&CircleLayer::setCircleOpacity);
result["circle-opacity-transition"] = makeTransitionSetter<V>(&CircleLayer::setCircleOpacityTransition);
result["circle-translate"] = makePropertySetter<V>(&CircleLayer::setCircleTranslate);
result["circle-translate-transition"] = makeTransitionSetter<V>(&CircleLayer::setCircleTranslateTransition);
result["circle-translate-anchor"] = makePropertySetter<V>(&CircleLayer::setCircleTranslateAnchor);
result["circle-translate-anchor-transition"] = makeTransitionSetter<V>(&CircleLayer::setCircleTranslateAnchorTransition);
result["circle-pitch-scale"] = makePropertySetter<V>(&CircleLayer::setCirclePitchScale);
result["circle-pitch-scale-transition"] = makeTransitionSetter<V>(&CircleLayer::setCirclePitchScaleTransition);
result["circle-stroke-width"] = makePropertySetter<V>(&CircleLayer::setCircleStrokeWidth);
result["circle-stroke-width-transition"] = makeTransitionSetter<V>(&CircleLayer::setCircleStrokeWidthTransition);
result["circle-stroke-color"] = makePropertySetter<V>(&CircleLayer::setCircleStrokeColor);
result["circle-stroke-color-transition"] = makeTransitionSetter<V>(&CircleLayer::setCircleStrokeColorTransition);
result["circle-stroke-opacity"] = makePropertySetter<V>(&CircleLayer::setCircleStrokeOpacity);
result["circle-stroke-opacity-transition"] = makeTransitionSetter<V>(&CircleLayer::setCircleStrokeOpacityTransition);

result["fill-extrusion-opacity"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionOpacity);
result["fill-extrusion-opacity-transition"] = makeTransitionSetter<V>(&FillExtrusionLayer::setFillExtrusionOpacityTransition);
result["fill-extrusion-color"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionColor);
result["fill-extrusion-color-transition"] = makeTransitionSetter<V>(&FillExtrusionLayer::setFillExtrusionColorTransition);
result["fill-extrusion-translate"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionTranslate);
result["fill-extrusion-translate-transition"] = makeTransitionSetter<V>(&FillExtrusionLayer::setFillExtrusionTranslateTransition);
result["fill-extrusion-translate-anchor"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionTranslateAnchor);
result["fill-extrusion-translate-anchor-transition"] = makeTransitionSetter<V>(&FillExtrusionLayer::setFillExtrusionTranslateAnchorTransition);
result["fill-extrusion-pattern"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionPattern);
result["fill-extrusion-pattern-transition"] = makeTransitionSetter<V>(&FillExtrusionLayer::setFillExtrusionPatternTransition);
result["fill-extrusion-height"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionHeight);
result["fill-extrusion-height-transition"] = makeTransitionSetter<V>(&FillExtrusionLayer::setFillExtrusionHeightTransition);
result["fill-extrusion-base"] = makePropertySetter<V>(&FillExtrusionLayer::setFillExtrusionBase);
result["fill-extrusion-base-transition"] = makeTransitionSetter<V>(&FillExtrusionLayer::setFillExtrusionBaseTransition);

result["raster-opacity"] = makePropertySetter<V>(&RasterLayer::setRasterOpacity);
result["raster-opacity-transition"] = makeTransitionSetter<V>(&RasterLayer::setRasterOpacityTransition);
result["raster-hue-rotate"] = makePropertySetter<V>(&RasterLayer::setRasterHueRotate);
result["raster-hue-rotate-transition"] = makeTransitionSetter<V>(&RasterLayer::setRasterHueRotateTransition);
result["raster-brightness-min"] = makePropertySetter<V>(&RasterLayer::setRasterBrightnessMin);
result["raster-brightness-min-transition"] = makeTransitionSetter<V>(&RasterLayer::setRasterBrightnessMinTransition);
result["raster-brightness-max"] = makePropertySetter<V>(&RasterLayer::setRasterBrightnessMax);
result["raster-brightness-max-transition"] = makeTransitionSetter<V>(&RasterLayer::setRasterBrightnessMaxTransition);
result["raster-saturation"] = makePropertySetter<V>(&RasterLayer::setRasterSaturation);
result["raster-saturation-transition"] = makeTransitionSetter<V>(&RasterLayer::setRasterSaturationTransition);
result["raster-contrast"] = makePropertySetter<V>(&RasterLayer::setRasterContrast);
result["raster-contrast-transition"] = makeTransitionSetter<V>(&RasterLayer::setRasterContrastTransition);
result["raster-fade-duration"] = makePropertySetter<V>(&RasterLayer::setRasterFadeDuration);
result["raster-fade-duration-transition"] = makeTransitionSetter<V>(&RasterLayer::setRasterFadeDurationTransition);

result["background-color"] = makePropertySetter<V>(&BackgroundLayer::setBackgroundColor);
result["background-color-transition"] = makeTransitionSetter<V>(&BackgroundLayer::setBackgroundColorTransition);
result["background-pattern"] = makePropertySetter<V>(&BackgroundLayer::setBackgroundPattern);
result["background-pattern-transition"] = makeTransitionSetter<V>(&BackgroundLayer::setBackgroundPatternTransition);
result["background-opacity"] = makePropertySetter<V>(&BackgroundLayer::setBackgroundOpacity);
result["background-opacity-transition"] = makeTransitionSetter<V>(&BackgroundLayer::setBackgroundOpacityTransition);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ auto makePaintPropertySetters() {
<% for (const layer of locals.layers) { -%>
<% for (const property of layer.paintProperties) { -%>
result["<%- property.name %>"] = makePropertySetter<V>(&<%- camelize(layer.type) %>Layer::set<%- camelize(property.name) %>);
result["<%- property.name %>-transition"] = makeTransitionSetter<V>(&<%- camelize(layer.type) %>Layer::set<%- camelize(property.name) %>Transition);
<% } -%>

<% } -%>
Expand Down
19 changes: 19 additions & 0 deletions include/mbgl/style/conversion/property_setter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <mbgl/style/conversion/constant.hpp>
#include <mbgl/style/conversion/property_value.hpp>
#include <mbgl/style/conversion/data_driven_property_value.hpp>
#include <mbgl/style/conversion/transition_options.hpp>

#include <functional>
#include <string>
Expand Down Expand Up @@ -37,6 +38,24 @@ auto makePropertySetter(void (L::*setter)(PropertyValue, const Args&...args)) {
};
}

template <class V, class L, class...Args>
auto makeTransitionSetter(void (L::*setter)(const TransitionOptions&, const Args&...args)) {
return [setter] (Layer& layer, const V& value, const Args&...args) -> optional<Error> {
L* typedLayer = layer.as<L>();
if (!typedLayer) {
return Error { "layer doesn't support this property" };
}

Result<TransitionOptions> transition = convert<TransitionOptions>(value);
if (!transition) {
return transition.error();
}

(typedLayer->*setter)(*transition, args...);
return {};
};
}

template <class V>
optional<Error> setVisibility(Layer& layer, const V& value) {
if (isUndefined(value)) {
Expand Down
45 changes: 45 additions & 0 deletions include/mbgl/style/conversion/transition_options.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/conversion.hpp>

namespace mbgl {
namespace style {
namespace conversion {

template <>
struct Converter<TransitionOptions> {
public:
template <class V>
Result<TransitionOptions> operator()(const V& value) const {
if (!isObject(value)) {
return Error { "transition must be an object" };
}

TransitionOptions result;

auto duration = objectMember(value, "duration");
if (duration) {
auto number = toNumber(*duration);
if (!number) {
return Error { "duration must be a number" };
}
result.duration = { std::chrono::milliseconds(int64_t(*number)) };
}

auto delay = objectMember(value, "delay");
if (delay) {
auto number = toNumber(*delay);
if (!number) {
return Error { "delay must be a number" };
}
result.delay = { std::chrono::milliseconds(int64_t(*number)) };
}

return result;
}
};

} // namespace conversion
} // namespace style
} // namespace mbgl
5 changes: 5 additions & 0 deletions include/mbgl/style/layers/background_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace mbgl {
namespace style {

class TransitionOptions;

class BackgroundLayer : public Layer {
public:
BackgroundLayer(const std::string& layerID);
Expand All @@ -22,14 +24,17 @@ class BackgroundLayer : public Layer {
static PropertyValue<Color> getDefaultBackgroundColor();
PropertyValue<Color> getBackgroundColor(const optional<std::string>& klass = {}) const;
void setBackgroundColor(PropertyValue<Color>, const optional<std::string>& klass = {});
void setBackgroundColorTransition(const TransitionOptions&, const optional<std::string>& klass = {});

static PropertyValue<std::string> getDefaultBackgroundPattern();
PropertyValue<std::string> getBackgroundPattern(const optional<std::string>& klass = {}) const;
void setBackgroundPattern(PropertyValue<std::string>, const optional<std::string>& klass = {});
void setBackgroundPatternTransition(const TransitionOptions&, const optional<std::string>& klass = {});

static PropertyValue<float> getDefaultBackgroundOpacity();
PropertyValue<float> getBackgroundOpacity(const optional<std::string>& klass = {}) const;
void setBackgroundOpacity(PropertyValue<float>, const optional<std::string>& klass = {});
void setBackgroundOpacityTransition(const TransitionOptions&, const optional<std::string>& klass = {});

// Private implementation

Expand Down
Loading