* [core] Bump gl-js version * [core] Implement image expression * [core] Use new image expression * [core] Coerce image expression to / from string * [core] Serialize evaluated image * [core] Pass available images to layout * [core] Pass images to evaluation context * [core] Set available flag value based on image availability * [core] Allow image coercion to boolean to indicate image availability * [core] Coalesce image expression * [core] Add image expression to next build system * [core] Align serialization format and evaluated type with gl-js * [core] Add images to expression evaluation method * [core] Add support for Image expression to expression test runner * [core] Unskip image expression tests * [core] Update unit tests * [core] Use image expression in annotation manager * [core] Add string to ImageExpression conversion * [core] Add image expression to expression dsl * [core] Convert tokens for implicitly created Image literal * [core] Fix clang format * [core] Split generated style code lines that are over 120 characters * [core] Add unit test for image expression equality * [core] Add image property expression evaluation unit test * [core] Unskip image expression render test * [core] Skip 'in' expression tests * [core] Ignore fill-pattern/update-feature-state render test * [core] Rename Image::serialize to Image::toValue
176 lines
4.5 KiB
C++
176 lines
4.5 KiB
C++
#pragma once
|
|
|
|
#include <mbgl/style/filter.hpp>
|
|
#include <mbgl/style/property_value.hpp>
|
|
#include <mbgl/style/expression/value.hpp>
|
|
#include <mbgl/style/expression/formatted.hpp>
|
|
#include <mbgl/util/enum.hpp>
|
|
#include <mbgl/util/color.hpp>
|
|
#include <mbgl/util/feature.hpp>
|
|
#include <mbgl/util/ignore.hpp>
|
|
#include <mbgl/util/rapidjson.hpp>
|
|
|
|
#include <array>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
|
|
namespace mbgl {
|
|
namespace style {
|
|
namespace conversion {
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, NullValue) {
|
|
writer.Null();
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, bool v) {
|
|
writer.Bool(v);
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, uint64_t v) {
|
|
writer.Uint64(v);
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, int64_t v) {
|
|
writer.Int64(v);
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, double v) {
|
|
writer.Double(v);
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, const std::string& v) {
|
|
writer.String(v);
|
|
}
|
|
|
|
template <class Writer, class T, class Enable = std::enable_if_t<std::is_enum<T>::value>>
|
|
void stringify(Writer& writer, const T& v) {
|
|
writer.String(Enum<T>::toString(v));
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, const Color& v) {
|
|
writer.String(v.stringify());
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, const std::array<float, 2>& v) {
|
|
writer.StartArray();
|
|
writer.Double(v[0]);
|
|
writer.Double(v[1]);
|
|
writer.EndArray();
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, const std::array<float, 4>& v) {
|
|
writer.StartArray();
|
|
writer.Double(v[0]);
|
|
writer.Double(v[1]);
|
|
writer.Double(v[2]);
|
|
writer.Double(v[3]);
|
|
writer.EndArray();
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer&, const Value&);
|
|
|
|
template <class Writer, class T>
|
|
void stringify(Writer& writer, const std::vector<T>& v) {
|
|
writer.StartArray();
|
|
for (const auto& e : v) {
|
|
stringify(writer, e);
|
|
}
|
|
writer.EndArray();
|
|
}
|
|
|
|
template <class Writer, class T>
|
|
void stringify(Writer& writer, const std::unordered_map<std::string, T>& m) {
|
|
writer.StartObject();
|
|
for (const auto& p : m) {
|
|
writer.Key(p.first.data(), static_cast<unsigned>(p.first.size()));
|
|
stringify(writer, p.second);
|
|
}
|
|
writer.EndObject();
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, const Value& v) {
|
|
Value::visit(v, [&] (const auto& v_) { stringify(writer, v_); });
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, FeatureType type) {
|
|
switch (type) {
|
|
case FeatureType::Unknown:
|
|
writer.String("Unknown");
|
|
break;
|
|
case FeatureType::Point:
|
|
writer.String("Point");
|
|
break;
|
|
case FeatureType::LineString:
|
|
writer.String("LineString");
|
|
break;
|
|
case FeatureType::Polygon:
|
|
writer.String("Polygon");
|
|
break;
|
|
}
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, const FeatureIdentifier& id) {
|
|
FeatureIdentifier::visit(id, [&] (const auto& id_) { stringify(writer, id_); });
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, const Filter& filter) {
|
|
if (!filter.expression) writer.Null();
|
|
else stringify(writer, (*filter.expression)->serialize());
|
|
}
|
|
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, const expression::Formatted& v) {
|
|
// Convert to mbgl::Value and then use the existing stringify
|
|
// Serialization strategy for Formatted objects is to return the constant
|
|
// expression that would generate them.
|
|
stringify(writer, expression::ValueConverter<mbgl::Value>::fromExpressionValue(v));
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, const expression::Image& v) {
|
|
stringify(writer, expression::ValueConverter<mbgl::Value>::fromExpressionValue(v));
|
|
}
|
|
|
|
template <class Writer>
|
|
void stringify(Writer& writer, const Undefined&) {
|
|
assert(false); // Should be omitted entirely instead.
|
|
writer.Null();
|
|
}
|
|
|
|
template <class Writer, class T>
|
|
void stringify(Writer& writer, const PropertyExpression<T>& fn) {
|
|
stringify(writer, fn.getExpression().serialize());
|
|
}
|
|
|
|
template <class Writer, class T>
|
|
void stringify(Writer& writer, const PropertyValue<T>& v) {
|
|
v.evaluate([&] (const auto& v_) { stringify(writer, v_); });
|
|
}
|
|
|
|
template <class Property, class Writer, class T>
|
|
void stringify(Writer& writer, const PropertyValue<T>& value) {
|
|
if (!value.isUndefined()) {
|
|
writer.Key(Property::name());
|
|
stringify(writer, value);
|
|
}
|
|
}
|
|
|
|
} // namespace conversion
|
|
} // namespace style
|
|
} // namespace mbgl
|