* [ios, macos] Eviscerate mbgl expression to Foundation JSON object conversion * [ios, macos] Remove literal special case MGLJSONObjectFromMBGLValue() is just a literal translation from C++ types to Foundation types; no need for expression-specific literal wrapping. * [ios, macos] Implemented RGB(A) operators * [ios, macos] More robust color conversion * [macos] Create calibrated RGB from expression on Sierra * [macos] Calibrate colors in expressions at runtime * [ios, macos] Special-case number conversion without fallbacks * [ios, macos] Test mgl_number expressions * [ios, macos] Updated tests for aftermarket expressions * [ios, macos] Relax roundtripping requirement for serialize() * [ios, macos] Fixed interpolation expression tests * [ios, macos] Removed dead code * [ios, macos] Fixed color conversion on Sierra
47 lines
1.9 KiB
Plaintext
47 lines
1.9 KiB
Plaintext
#import "MGLStyleValue_Private.h"
|
|
|
|
#include <mbgl/style/expression/expression.hpp>
|
|
|
|
const MGLStyleFunctionOption MGLStyleFunctionOptionInterpolationBase = @"MGLStyleFunctionOptionInterpolationBase";
|
|
const MGLStyleFunctionOption MGLStyleFunctionOptionDefaultValue = @"MGLStyleFunctionOptionDefaultValue";
|
|
|
|
id MGLJSONObjectFromMBGLValue(const mbgl::Value &value) {
|
|
return value.match([](const mbgl::NullValue) -> id {
|
|
return [NSNull null];
|
|
}, [](const bool value) {
|
|
return @(value);
|
|
}, [](const float value) {
|
|
return @(value);
|
|
}, [](const int64_t value) {
|
|
return @(value);
|
|
}, [](const double value) {
|
|
return @(value);
|
|
}, [](const std::string &value) {
|
|
return @(value.c_str());
|
|
}, [](const mbgl::Color &value) {
|
|
return [MGLColor mgl_colorWithColor:value];
|
|
}, [](const mbgl::style::Position &value) {
|
|
std::array<float, 3> spherical = value.getSpherical();
|
|
MGLSphericalPosition position = MGLSphericalPositionMake(spherical[0], spherical[1], spherical[2]);
|
|
return [NSValue valueWithMGLSphericalPosition:position];
|
|
}, [&](const std::vector<mbgl::Value> &vector) {
|
|
NSMutableArray *array = [NSMutableArray arrayWithCapacity:vector.size()];
|
|
for (auto value : vector) {
|
|
[array addObject:MGLJSONObjectFromMBGLValue(value)];
|
|
}
|
|
return array;
|
|
}, [&](const std::unordered_map<std::string, mbgl::Value> &map) {
|
|
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:map.size()];
|
|
for (auto &item : map) {
|
|
dictionary[@(item.first.c_str())] = MGLJSONObjectFromMBGLValue(item.second);
|
|
}
|
|
return dictionary;
|
|
}, [](const auto &) -> id {
|
|
return nil;
|
|
});
|
|
}
|
|
|
|
id MGLJSONObjectFromMBGLExpression(const mbgl::style::expression::Expression &mbglExpression) {
|
|
return MGLJSONObjectFromMBGLValue(mbglExpression.serialize());
|
|
}
|