Files
MapLibreParticleLab/platform/darwin/src/MLNStyleValue.mm
Bart Louwers 2a8ebc4906 core: rename mbgl directories to mln (#4511)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-08-22 20:50:14 +02:00

58 lines
2.3 KiB
Plaintext

#import "MLNStyleValue_Private.h"
#include <mln/style/expression/expression.hpp>
const MLNStyleFunctionOption MLNStyleFunctionOptionInterpolationBase =
@"MLNStyleFunctionOptionInterpolationBase";
const MLNStyleFunctionOption MLNStyleFunctionOptionDefaultValue =
@"MLNStyleFunctionOptionDefaultValue";
id MLNJSONObjectFromMBGLValue(const mln::Value &value) {
return value.match(
[](const mln::NullValue) -> id { return [NSNull null]; },
[](const bool value) { return @(value); }, [](const float value) { return @(value); },
[](const int64_t value) { return @(value); }, [](const uint64_t value) { return @(value); },
[](const double value) { return @(value); },
[](const std::string &value) { return @(value.c_str()); },
[](const mln::Color &value) { return [MLNColor mgl_colorWithColor:value]; },
[](const mln::style::Position &value) {
std::array<float, 3> spherical = value.getSpherical();
MLNSphericalPosition position =
MLNSphericalPositionMake(spherical[0], spherical[1], spherical[2]);
return [NSValue valueWithMLNSphericalPosition:position];
},
[&](const std::vector<mln::Value> &vector) {
NSMutableArray *array = [NSMutableArray arrayWithCapacity:vector.size()];
for (auto value : vector) {
[array addObject:MLNJSONObjectFromMBGLValue(value)];
}
return array;
},
[&](const std::unordered_map<std::string, mln::Value> &map) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:map.size()];
for (auto &item : map) {
dictionary[@(item.first.c_str())] = MLNJSONObjectFromMBGLValue(item.second);
}
return dictionary;
},
[](const auto &) -> id { return nil; });
}
id MLNJSONObjectFromMBGLExpression(const mln::style::expression::Expression &mbglExpression) {
return MLNJSONObjectFromMBGLValue(mbglExpression.serialize());
}
std::unique_ptr<mln::style::expression::Expression> MLNClusterPropertyFromNSExpression(
NSExpression *expression) {
if (!expression) {
return nullptr;
}
NSArray *jsonExpression = expression.mgl_jsonExpressionObject;
auto expr = mln::style::expression::dsl::createExpression(
mln::style::conversion::makeConvertible(jsonExpression));
return expr;
}