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

Commit

Permalink
[core] Add support for data-driven styling
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Jan 6, 2017
1 parent 0760d7e commit 4dedfbe
Show file tree
Hide file tree
Showing 124 changed files with 3,113 additions and 1,020 deletions.
23 changes: 21 additions & 2 deletions cmake/core-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ set(MBGL_CORE_FILES
src/mbgl/gl/framebuffer.hpp
src/mbgl/gl/gl.cpp
src/mbgl/gl/index_buffer.hpp
src/mbgl/gl/normalization.hpp
src/mbgl/gl/object.cpp
src/mbgl/gl/object.hpp
src/mbgl/gl/primitives.hpp
src/mbgl/gl/program.hpp
src/mbgl/gl/renderbuffer.hpp
src/mbgl/gl/segment.cpp
src/mbgl/gl/segment.hpp
src/mbgl/gl/state.hpp
src/mbgl/gl/stencil_mode.cpp
Expand Down Expand Up @@ -205,22 +207,23 @@ set(MBGL_CORE_FILES

# style
include/mbgl/style/conversion.hpp
include/mbgl/style/data_driven_property_value.hpp
include/mbgl/style/filter.hpp
include/mbgl/style/filter_evaluator.hpp
include/mbgl/style/function.hpp
include/mbgl/style/layer.hpp
include/mbgl/style/property_value.hpp
include/mbgl/style/source.hpp
include/mbgl/style/transition_options.hpp
include/mbgl/style/types.hpp
include/mbgl/style/undefined.hpp
src/mbgl/style/bucket_parameters.cpp
src/mbgl/style/bucket_parameters.hpp
src/mbgl/style/cascade_parameters.hpp
src/mbgl/style/class_dictionary.cpp
src/mbgl/style/class_dictionary.hpp
src/mbgl/style/cross_faded_property_evaluator.cpp
src/mbgl/style/cross_faded_property_evaluator.hpp
src/mbgl/style/function.cpp
src/mbgl/style/data_driven_property_evaluator.hpp
src/mbgl/style/group_by_layout.cpp
src/mbgl/style/group_by_layout.hpp
src/mbgl/style/layer.cpp
Expand All @@ -230,8 +233,10 @@ set(MBGL_CORE_FILES
src/mbgl/style/layout_property.hpp
src/mbgl/style/observer.hpp
src/mbgl/style/paint_property.hpp
src/mbgl/style/paint_property_binder.hpp
src/mbgl/style/parser.cpp
src/mbgl/style/parser.hpp
src/mbgl/style/possibly_evaluated_property_value.hpp
src/mbgl/style/property_evaluation_parameters.hpp
src/mbgl/style/property_evaluator.hpp
src/mbgl/style/property_parsing.cpp
Expand All @@ -252,6 +257,7 @@ set(MBGL_CORE_FILES

# style/conversion
include/mbgl/style/conversion/constant.hpp
include/mbgl/style/conversion/data_driven_property_value.hpp
include/mbgl/style/conversion/filter.hpp
include/mbgl/style/conversion/function.hpp
include/mbgl/style/conversion/geojson.hpp
Expand All @@ -264,6 +270,17 @@ set(MBGL_CORE_FILES
include/mbgl/style/conversion/tileset.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_function.hpp
include/mbgl/style/function/exponential_stops.hpp
include/mbgl/style/function/identity_stops.hpp
include/mbgl/style/function/interval_stops.hpp
include/mbgl/style/function/source_function.hpp
src/mbgl/style/function/categorical_stops.cpp
src/mbgl/style/function/identity_stops.cpp

# style/layers
include/mbgl/style/layers/background_layer.hpp
include/mbgl/style/layers/circle_layer.hpp
Expand Down Expand Up @@ -437,6 +454,7 @@ set(MBGL_CORE_FILES
src/mbgl/util/i18n.hpp
src/mbgl/util/ignore.hpp
src/mbgl/util/indexed_tuple.hpp
src/mbgl/util/interpolate.cpp
src/mbgl/util/interpolate.hpp
src/mbgl/util/intersection_tests.cpp
src/mbgl/util/intersection_tests.hpp
Expand Down Expand Up @@ -469,6 +487,7 @@ set(MBGL_CORE_FILES
src/mbgl/util/tile_cover.cpp
src/mbgl/util/tile_cover.hpp
src/mbgl/util/token.hpp
src/mbgl/util/type_list.hpp
src/mbgl/util/url.cpp
src/mbgl/util/url.hpp
src/mbgl/util/utf.hpp
Expand Down
6 changes: 5 additions & 1 deletion cmake/test-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ set(MBGL_TEST_FILES

# style
test/style/filter.test.cpp
test/style/functions.test.cpp

# style/function
test/style/function/camera_function.test.cpp

# style
test/style/group_by_layout.test.cpp
test/style/source.test.cpp
test/style/style.test.cpp
Expand Down
11 changes: 6 additions & 5 deletions include/mbgl/annotation/annotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <mbgl/util/variant.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/data_driven_property_value.hpp>

#include <cstdint>
#include <vector>
Expand All @@ -29,17 +30,17 @@ using ShapeAnnotationGeometry = variant<
class LineAnnotation {
public:
ShapeAnnotationGeometry geometry;
style::PropertyValue<float> opacity { 1.0f };
style::DataDrivenPropertyValue<float> opacity { 1.0f };
style::PropertyValue<float> width { 1.0f };
style::PropertyValue<Color> color { Color::black() };
style::DataDrivenPropertyValue<Color> color { Color::black() };
};

class FillAnnotation {
public:
ShapeAnnotationGeometry geometry;
style::PropertyValue<float> opacity { 1.0f };
style::PropertyValue<Color> color { Color::black() };
style::PropertyValue<Color> outlineColor {};
style::DataDrivenPropertyValue<float> opacity { 1.0f };
style::DataDrivenPropertyValue<Color> color { Color::black() };
style::DataDrivenPropertyValue<Color> outlineColor {};
};

// An annotation whose type and properties are sourced from a style layer.
Expand Down
46 changes: 46 additions & 0 deletions include/mbgl/style/conversion/data_driven_property_value.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

#include <mbgl/style/data_driven_property_value.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/constant.hpp>
#include <mbgl/style/conversion/function.hpp>

namespace mbgl {
namespace style {
namespace conversion {

template <class T>
struct Converter<DataDrivenPropertyValue<T>> {
template <class V>
Result<DataDrivenPropertyValue<T>> operator()(const V& value) const {
if (isUndefined(value)) {
return {};
} else if (!isObject(value)) {
Result<T> constant = convert<T>(value);
if (!constant) {
return constant.error();
}
return DataDrivenPropertyValue<T>(*constant);
} else if (!objectMember(value, "property")) {
Result<CameraFunction<T>> function = convert<CameraFunction<T>>(value);
if (!function) {
return function.error();
}
return DataDrivenPropertyValue<T>(*function);
} else {
Result<CompositeFunction<T>> composite = convert<CompositeFunction<T>>(value);
if (composite) {
return DataDrivenPropertyValue<T>(*composite);
}
Result<SourceFunction<T>> source = convert<SourceFunction<T>>(value);
if (!source) {
return source.error();
}
return DataDrivenPropertyValue<T>(*source);
}
}
};

} // namespace conversion
} // namespace style
} // namespace mbgl
Loading

0 comments on commit 4dedfbe

Please sign in to comment.