diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index a852082aae1..9090bb40e68 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -355,6 +355,9 @@ for (var layer of layers) { allLayoutProperties.push(layer.layoutProperties); allPaintProperties.push(layer.paintProperties); allTypes.push(layer.type); + const containsEnumerationProperties = _.filter(layer.layoutProperties, function(property){ return property["type"] === "enum"; }).length || _.filter(layer.paintProperties, function(property){ return property["type"] === "enum"; }).length; + layer.containsEnumerationProperties = containsEnumerationProperties; + fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.h`, duplicatePlatformDecls(layerH(layer))); fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.mm`, layerM(layer)); fs.writeFileSync(`platform/darwin/test/${prefix}${camelize(layer.type)}${suffix}Tests.m`, testLayers(layer)); diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index bb6ee347eb3..386c6322ebf 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -10,12 +10,6 @@ #include -namespace mbgl { - - using namespace style; - - -} @interface MGLBackgroundStyleLayer () @@ -38,8 +32,6 @@ - (instancetype)initWithIdentifier:(NSString *)identifier return self; } - - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index 67c7fc255e8..4e5f2c7fdfd 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -12,17 +12,16 @@ namespace mbgl { - using namespace style; - - MBGL_DEFINE_ENUM(MGLCircleTranslateAnchor, { { MGLCircleTranslateAnchorMap, "map" }, { MGLCircleTranslateAnchorViewport, "viewport" }, }); + MBGL_DEFINE_ENUM(MGLCirclePitchScale, { { MGLCirclePitchScaleMap, "map" }, { MGLCirclePitchScaleViewport, "viewport" }, }); + } @interface MGLCircleStyleLayer () @@ -45,8 +44,6 @@ - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)so } return self; } - - - (NSString *)sourceLayerIdentifier { auto layerID = _rawLayer->getSourceLayer(); @@ -67,8 +64,6 @@ - (NSPredicate *)predicate { return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } - - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView @@ -146,65 +141,29 @@ - (void)setCircleTranslate:(MGLStyleValue *)circleTranslate { } - (void)setCircleTranslateAnchor:(MGLStyleValue *)circleTranslateAnchor { - if ([circleTranslateAnchor isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)circleTranslateAnchor; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLCircleTranslateAnchor circleTranslateAnchorValue; - [value getValue:&circleTranslateAnchorValue]; - auto str = mbgl::Enum::toString(circleTranslateAnchorValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultCircleTranslateAnchor().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setCircleTranslateAnchor(func); - return; - } - id value = [(MGLStyleConstantValue *)circleTranslateAnchor rawValue]; - MGLCircleTranslateAnchor circleTranslateAnchorValue; - [value getValue:&circleTranslateAnchorValue]; - auto str = mbgl::Enum::toString(circleTranslateAnchorValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultCircleTranslateAnchor().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(circleTranslateAnchor); _rawLayer->setCircleTranslateAnchor(mbglValue); } - (MGLStyleValue *)circleTranslateAnchor { auto propertyValue = _rawLayer->getCircleTranslateAnchor() ?: _rawLayer->getDefaultCircleTranslateAnchor(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setCirclePitchScale:(MGLStyleValue *)circlePitchScale { - if ([circlePitchScale isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)circlePitchScale; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLCirclePitchScale circlePitchScaleValue; - [value getValue:&circlePitchScaleValue]; - auto str = mbgl::Enum::toString(circlePitchScaleValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultCirclePitchScale().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setCirclePitchScale(func); - return; - } - id value = [(MGLStyleConstantValue *)circlePitchScale rawValue]; - MGLCirclePitchScale circlePitchScaleValue; - [value getValue:&circlePitchScaleValue]; - auto str = mbgl::Enum::toString(circlePitchScaleValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultCirclePitchScale().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(circlePitchScale); _rawLayer->setCirclePitchScale(mbglValue); } - (MGLStyleValue *)circlePitchScale { auto propertyValue = _rawLayer->getCirclePitchScale() ?: _rawLayer->getDefaultCirclePitchScale(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index 224c6bd7924..24c8a90f7fe 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -12,13 +12,11 @@ namespace mbgl { - using namespace style; - - MBGL_DEFINE_ENUM(MGLFillTranslateAnchor, { { MGLFillTranslateAnchorMap, "map" }, { MGLFillTranslateAnchorViewport, "viewport" }, }); + } @interface MGLFillStyleLayer () @@ -41,8 +39,6 @@ - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)so } return self; } - - - (NSString *)sourceLayerIdentifier { auto layerID = _rawLayer->getSourceLayer(); @@ -63,8 +59,6 @@ - (NSPredicate *)predicate { return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } - - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView @@ -142,34 +136,16 @@ - (void)setFillTranslate:(MGLStyleValue *)fillTranslate { } - (void)setFillTranslateAnchor:(MGLStyleValue *)fillTranslateAnchor { - if ([fillTranslateAnchor isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)fillTranslateAnchor; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLFillTranslateAnchor fillTranslateAnchorValue; - [value getValue:&fillTranslateAnchorValue]; - auto str = mbgl::Enum::toString(fillTranslateAnchorValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultFillTranslateAnchor().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setFillTranslateAnchor(func); - return; - } - id value = [(MGLStyleConstantValue *)fillTranslateAnchor rawValue]; - MGLFillTranslateAnchor fillTranslateAnchorValue; - [value getValue:&fillTranslateAnchorValue]; - auto str = mbgl::Enum::toString(fillTranslateAnchorValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultFillTranslateAnchor().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(fillTranslateAnchor); _rawLayer->setFillTranslateAnchor(mbglValue); } - (MGLStyleValue *)fillTranslateAnchor { auto propertyValue = _rawLayer->getFillTranslateAnchor() ?: _rawLayer->getDefaultFillTranslateAnchor(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setFillPattern:(MGLStyleValue *)fillPattern { diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index 7c8bb5aa9de..93e3106032c 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -12,13 +12,12 @@ namespace mbgl { - using namespace style; - MBGL_DEFINE_ENUM(MGLLineCap, { { MGLLineCapButt, "butt" }, { MGLLineCapRound, "round" }, { MGLLineCapSquare, "square" }, }); + MBGL_DEFINE_ENUM(MGLLineJoin, { { MGLLineJoinBevel, "bevel" }, { MGLLineJoinRound, "round" }, @@ -29,6 +28,7 @@ { MGLLineTranslateAnchorMap, "map" }, { MGLLineTranslateAnchorViewport, "viewport" }, }); + } @interface MGLLineStyleLayer () @@ -51,8 +51,6 @@ - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)so } return self; } - - - (NSString *)sourceLayerIdentifier { auto layerID = _rawLayer->getSourceLayer(); @@ -73,8 +71,6 @@ - (NSPredicate *)predicate { return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } - - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView @@ -102,65 +98,29 @@ - (void)removeFromMapView:(MGLMapView *)mapView #pragma mark - Accessing the Layout Attributes - (void)setLineCap:(MGLStyleValue *)lineCap { - if ([lineCap isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)lineCap; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLLineCap lineCapValue; - [value getValue:&lineCapValue]; - auto str = mbgl::Enum::toString(lineCapValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultLineCap().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setLineCap(func); - return; - } - id value = [(MGLStyleConstantValue *)lineCap rawValue]; - MGLLineCap lineCapValue; - [value getValue:&lineCapValue]; - auto str = mbgl::Enum::toString(lineCapValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultLineCap().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineCap); _rawLayer->setLineCap(mbglValue); } - (MGLStyleValue *)lineCap { auto propertyValue = _rawLayer->getLineCap() ?: _rawLayer->getDefaultLineCap(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setLineJoin:(MGLStyleValue *)lineJoin { - if ([lineJoin isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)lineJoin; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLLineJoin lineJoinValue; - [value getValue:&lineJoinValue]; - auto str = mbgl::Enum::toString(lineJoinValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultLineJoin().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setLineJoin(func); - return; - } - id value = [(MGLStyleConstantValue *)lineJoin rawValue]; - MGLLineJoin lineJoinValue; - [value getValue:&lineJoinValue]; - auto str = mbgl::Enum::toString(lineJoinValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultLineJoin().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineJoin); _rawLayer->setLineJoin(mbglValue); } - (MGLStyleValue *)lineJoin { auto propertyValue = _rawLayer->getLineJoin() ?: _rawLayer->getDefaultLineJoin(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setLineMiterLimit:(MGLStyleValue *)lineMiterLimit { @@ -216,34 +176,16 @@ - (void)setLineTranslate:(MGLStyleValue *)lineTranslate { } - (void)setLineTranslateAnchor:(MGLStyleValue *)lineTranslateAnchor { - if ([lineTranslateAnchor isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)lineTranslateAnchor; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLLineTranslateAnchor lineTranslateAnchorValue; - [value getValue:&lineTranslateAnchorValue]; - auto str = mbgl::Enum::toString(lineTranslateAnchorValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultLineTranslateAnchor().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setLineTranslateAnchor(func); - return; - } - id value = [(MGLStyleConstantValue *)lineTranslateAnchor rawValue]; - MGLLineTranslateAnchor lineTranslateAnchorValue; - [value getValue:&lineTranslateAnchorValue]; - auto str = mbgl::Enum::toString(lineTranslateAnchorValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultLineTranslateAnchor().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(lineTranslateAnchor); _rawLayer->setLineTranslateAnchor(mbglValue); } - (MGLStyleValue *)lineTranslateAnchor { auto propertyValue = _rawLayer->getLineTranslateAnchor() ?: _rawLayer->getDefaultLineTranslateAnchor(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setLineWidth:(MGLStyleValue *)lineWidth { diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index 0ae2f5f3906..c6283d89ea7 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -10,12 +10,6 @@ #include -namespace mbgl { - - using namespace style; - - -} @interface MGLRasterStyleLayer () @@ -37,9 +31,6 @@ - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)so } return self; } - - - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 49e53c3f5d2..894375e7640 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -2,6 +2,7 @@ const type = locals.type; const layoutProperties = locals.layoutProperties; const paintProperties = locals.paintProperties; + const containsEnumerationProperties = locals.containsEnumerationProperties; -%> // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. @@ -15,10 +16,9 @@ #include _layer.hpp> +<% if (containsEnumerationProperties) { -%> namespace mbgl { - using namespace style; - <% if (layoutProperties.length) { -%> <% for (const property of layoutProperties) { -%> <% if (property.type == "enum") { -%> @@ -27,10 +27,10 @@ namespace mbgl { { MGL<%- camelize(property.name) %><%- camelize(value) %>, "<%-value%>" }, <% } -%> }); + <% } -%> <% } -%> <% } -%> - <% if (paintProperties.length) { -%> <% for (const property of paintProperties) { -%> <% if (property.type == "enum") { -%> @@ -39,10 +39,12 @@ namespace mbgl { { MGL<%- camelize(property.name) %><%- camelize(value) %>, "<%-value%>" }, <% } -%> }); + <% } -%> <% } -%> <% } -%> } +<% } -%> @interface MGL<%- camelize(type) %>StyleLayer () @@ -76,9 +78,7 @@ namespace mbgl { } return self; } - <% } -%> - <% if (type !== 'background' && type !== 'raster') { -%> - (NSString *)sourceLayerIdentifier { @@ -100,9 +100,7 @@ namespace mbgl { { return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } - <% } -%> - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView @@ -133,27 +131,10 @@ namespace mbgl { <% for (const property of layoutProperties) { -%> - (void)set<%- camelize(property.name) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { <% if (property.type == "enum") { -%> - if ([<%- objCName(property) %> isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)<%- objCName(property) %>; - __block std::vector>> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGL<%- camelize(property.name) %> <%- objCName(property) %>Value; - [value getValue:&<%- objCName(property) %>Value]; - auto str = mbgl::Enum>::toString(<%- objCName(property) %>Value); - auto mbglValue = mbgl::Enum>::toEnum(str).value_or(_rawLayer->getDefault<%- camelize(property.name) %>().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue>(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function>({{mbglStops}}, function.base); - _rawLayer->set<%- camelize(property.name) %>(func); - return; - } - id value = [(MGLStyleConstantValue *)<%- objCName(property) %> rawValue]; - MGL<%- camelize(property.name) %> <%- objCName(property) %>Value; - [value getValue:&<%- objCName(property) %>Value]; - auto str = mbgl::Enum>::toString(<%- objCName(property) %>Value); - auto mbglValue = mbgl::Enum>::toEnum(str).value_or(_rawLayer->getDefault<%- camelize(property.name) %>().asConstant()); + auto mbglValue = MGLStyleValueTransformer, + NSValue *, + mbgl::style::<%- mbglType(property) %>, + MGL<%- camelize(property.name) %>>().toEnumPropertyValue(<%- objCName(property) %>); _rawLayer->set<%- camelize(property.name) %>(mbglValue); <% } else { -%> auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue(<%- objCName(property) %>); @@ -163,8 +144,8 @@ namespace mbgl { - (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { auto propertyValue = _rawLayer->get<%- camelize(property.name) %>() ?: _rawLayer->getDefault<%- camelize(property.name) %>(); -<% if (property.type == "enum") { -%> - return MGLStyleEnumerationValueTransformer, MGL<%- camelize(property.name) %>>().propertyValueMGLStyleValue(propertyValue); +<% if (property.type == "enum") { -%> + return MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(property.name) %>>().toEnumStyleValue(propertyValue); <% } else { -%> return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(propertyValue); <% } -%> @@ -178,27 +159,10 @@ namespace mbgl { <% for (const property of paintProperties) { -%> - (void)set<%- camelize(property.name) %>:(MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { <% if (property.type == "enum") { -%> - if ([<%- objCName(property) %> isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)<%- objCName(property) %>; - __block std::vector>> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGL<%- camelize(property.name) %> <%- objCName(property) %>Value; - [value getValue:&<%- objCName(property) %>Value]; - auto str = mbgl::Enum>::toString(<%- objCName(property) %>Value); - auto mbglValue = mbgl::Enum>::toEnum(str).value_or(_rawLayer->getDefault<%- camelize(property.name) %>().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue>(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function>({{mbglStops}}, function.base); - _rawLayer->set<%- camelize(property.name) %>(func); - return; - } - id value = [(MGLStyleConstantValue *)<%- objCName(property) %> rawValue]; - MGL<%- camelize(property.name) %> <%- objCName(property) %>Value; - [value getValue:&<%- objCName(property) %>Value]; - auto str = mbgl::Enum>::toString(<%- objCName(property) %>Value); - auto mbglValue = mbgl::Enum>::toEnum(str).value_or(_rawLayer->getDefault<%- camelize(property.name) %>().asConstant()); + auto mbglValue = MGLStyleValueTransformer, + NSValue *, + mbgl::style::<%- mbglType(property) %>, + MGL<%- camelize(property.name) %>>().toEnumPropertyValue(<%- objCName(property) %>); _rawLayer->set<%- camelize(property.name) %>(mbglValue); <% } else { -%> auto mbglValue = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toPropertyValue(<%- objCName(property) %>); @@ -208,8 +172,8 @@ namespace mbgl { - (MGLStyleValue<<%- propertyType(property, true) %>> *)<%- objCName(property) %> { auto propertyValue = _rawLayer->get<%- camelize(property.name) %>() ?: _rawLayer->getDefault<%- camelize(property.name) %>(); -<% if (property.type == "enum") { -%> - return MGLStyleEnumerationValueTransformer, MGL<%- camelize(property.name) %>>().propertyValueMGLStyleValue(propertyValue); +<% if (property.type == "enum") { -%> + return MGLStyleValueTransformer, NSValue *, mbgl::style::<%- mbglType(property) %>, MGL<%- camelize(property.name) %>>().toEnumStyleValue(propertyValue); <% } else { -%> return MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(propertyValue); <% } -%> diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h index ad5a964d2ac..492ce20f1a9 100644 --- a/platform/darwin/src/MGLStyleValue_Private.h +++ b/platform/darwin/src/MGLStyleValue_Private.h @@ -15,36 +15,7 @@ #include -template -class MGLStyleEnumerationValueTransformer { - -public: - MGLStyleValue * propertyValueMGLStyleValue(mbgl::style::PropertyValue propertyValue) - { - if (propertyValue.isFunction()) - { - const auto &mbglStops = propertyValue.asFunction().getStops(); - NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:mbglStops.size()]; - for (const auto &mbglStop : mbglStops) { - auto str = mbgl::Enum::toString(mbglStop.second); - MGLType mglType; - mglType = mbgl::Enum::toEnum(str).value_or(mglType); - stops[@(mbglStop.first)] = [MGLStyleValue valueWithRawValue:[NSValue value:&mglType withObjCType:@encode(NSUInteger)]]; - } - return [MGLStyleFunction functionWithBase:propertyValue.asFunction().getBase() stops:stops]; - } - else - { - auto str = mbgl::Enum::toString(propertyValue.asConstant()); - MGLType mglType; - mglType = mbgl::Enum::toEnum(str).value_or(mglType); - return [MGLStyleConstantValue valueWithRawValue:[NSValue value:&mglType withObjCType:@encode(NSUInteger)]]; - } - } - -}; - -template +template class MGLStyleValueTransformer { public: @@ -58,6 +29,25 @@ class MGLStyleValueTransformer { } } + template ::value>::type, + typename MGLEnum = ObjCEnum, + class = typename std::enable_if::value>::type> + MGLStyleValue *toEnumStyleValue(const mbgl::style::PropertyValue &mbglValue) { + if (mbglValue.isConstant()) { + return toEnumStyleConstantValue<>(mbglValue.asConstant()); + } else if (mbglValue.isFunction()) { + const auto &mbglStops = mbglValue.asFunction().getStops(); + NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:mbglStops.size()]; + for (const auto &mbglStop : mbglStops) { + stops[@(mbglStop.first)] = toEnumStyleConstantValue<>(mbglStop.second); + } + return [MGLStyleFunction functionWithBase:mbglValue.asFunction().getBase() stops:stops]; + } else { + return nil; + } + } + mbgl::style::PropertyValue toPropertyValue(MGLStyleValue *value) { if ([value isKindOfClass:[MGLStyleConstantValue class]]) { MBGLType mbglValue; @@ -83,9 +73,39 @@ class MGLStyleValueTransformer { return {}; } } - + + template ::value>::type, + typename MGLEnum = ObjCEnum, + class = typename std::enable_if::value>::type> + mbgl::style::PropertyValue toEnumPropertyValue(MGLStyleValue *value) { + if ([value isKindOfClass:[MGLStyleConstantValue class]]) { + MBGLEnum mbglValue; + getMBGLValue([(MGLStyleConstantValue *)value rawValue], mbglValue); + return mbglValue; + } else if ([value isKindOfClass:[MGLStyleFunction class]]) { + MGLStyleFunction *function = (MGLStyleFunction *)value; + __block std::vector> mbglStops; + [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { + NSCAssert([stopValue isKindOfClass:[MGLStyleValue class]], @"Stops should be MGLStyleValues"); + auto mbglStopValue = toEnumPropertyValue(stopValue); + NSCAssert(mbglStopValue.isConstant(), @"Stops must be constant"); + mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); + }]; + return mbgl::style::Function({{mbglStops}}, function.base); + } else if (value) { + [NSException raise:@"MGLAbstractClassException" format: + @"The style value %@ cannot be applied to the style. " + @"Make sure the style value was created as a member of a concrete subclass of MGLStyleValue.", + NSStringFromClass([value class])]; + return {}; + } else { + return {}; + } + } + private: - + MGLStyleConstantValue *toStyleConstantValue(const MBGLType mbglValue) { auto rawValue = toMGLRawStyleValue(mbglValue); return [MGLStyleConstantValue valueWithRawValue:rawValue]; @@ -100,7 +120,17 @@ class MGLStyleValueTransformer { } return [MGLStyleFunction functionWithBase:mbglFunction.getBase() stops:stops]; } - + + template ::value>::type, + typename MGLEnum = ObjCEnum, + class = typename std::enable_if::value>::type> + MGLStyleConstantValue *toEnumStyleConstantValue(const MBGLEnum mbglValue) { + auto str = mbgl::Enum::toString(mbglValue); + MGLEnum mglType = *mbgl::Enum::toEnum(str); + return [MGLStyleConstantValue valueWithRawValue:[NSValue value:&mglType withObjCType:@encode(MGLEnum)]]; + } + NSNumber *toMGLRawStyleValue(const bool mbglStopValue) { return @(mbglStopValue); } @@ -136,7 +166,7 @@ class MGLStyleValueTransformer { } private: - + void getMBGLValue(NSNumber *rawValue, bool &mbglValue) { mbglValue = !!rawValue.boolValue; } @@ -171,4 +201,16 @@ class MGLStyleValueTransformer { mbglValue.push_back(mbglElement); } } + + // Enumerations + template ::value>::type, + typename MGLEnum = ObjCEnum, + class = typename std::enable_if::value>::type> + void getMBGLValue(ObjCType rawValue, MBGLEnum &mbglValue) { + MGLEnum mglEnum; + [rawValue getValue:&mglEnum]; + auto str = mbgl::Enum::toString(mglEnum); + mbglValue = *mbgl::Enum::toEnum(str); + } }; diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index a13d31e356b..636849e87af 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -12,38 +12,42 @@ namespace mbgl { - using namespace style; - MBGL_DEFINE_ENUM(MGLSymbolPlacement, { { MGLSymbolPlacementPoint, "point" }, { MGLSymbolPlacementLine, "line" }, }); + MBGL_DEFINE_ENUM(MGLIconRotationAlignment, { { MGLIconRotationAlignmentMap, "map" }, { MGLIconRotationAlignmentViewport, "viewport" }, { MGLIconRotationAlignmentAuto, "auto" }, }); + MBGL_DEFINE_ENUM(MGLIconTextFit, { { MGLIconTextFitNone, "none" }, { MGLIconTextFitWidth, "width" }, { MGLIconTextFitHeight, "height" }, { MGLIconTextFitBoth, "both" }, }); + MBGL_DEFINE_ENUM(MGLTextPitchAlignment, { { MGLTextPitchAlignmentMap, "map" }, { MGLTextPitchAlignmentViewport, "viewport" }, { MGLTextPitchAlignmentAuto, "auto" }, }); + MBGL_DEFINE_ENUM(MGLTextRotationAlignment, { { MGLTextRotationAlignmentMap, "map" }, { MGLTextRotationAlignmentViewport, "viewport" }, { MGLTextRotationAlignmentAuto, "auto" }, }); + MBGL_DEFINE_ENUM(MGLTextJustify, { { MGLTextJustifyLeft, "left" }, { MGLTextJustifyCenter, "center" }, { MGLTextJustifyRight, "right" }, }); + MBGL_DEFINE_ENUM(MGLTextAnchor, { { MGLTextAnchorCenter, "center" }, { MGLTextAnchorLeft, "left" }, @@ -55,6 +59,7 @@ { MGLTextAnchorBottomLeft, "bottom-left" }, { MGLTextAnchorBottomRight, "bottom-right" }, }); + MBGL_DEFINE_ENUM(MGLTextTransform, { { MGLTextTransformNone, "none" }, { MGLTextTransformUppercase, "uppercase" }, @@ -65,10 +70,12 @@ { MGLIconTranslateAnchorMap, "map" }, { MGLIconTranslateAnchorViewport, "viewport" }, }); + MBGL_DEFINE_ENUM(MGLTextTranslateAnchor, { { MGLTextTranslateAnchorMap, "map" }, { MGLTextTranslateAnchorViewport, "viewport" }, }); + } @interface MGLSymbolStyleLayer () @@ -91,8 +98,6 @@ - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)so } return self; } - - - (NSString *)sourceLayerIdentifier { auto layerID = _rawLayer->getSourceLayer(); @@ -113,8 +118,6 @@ - (NSPredicate *)predicate { return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } - - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView @@ -142,34 +145,16 @@ - (void)removeFromMapView:(MGLMapView *)mapView #pragma mark - Accessing the Layout Attributes - (void)setSymbolPlacement:(MGLStyleValue *)symbolPlacement { - if ([symbolPlacement isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)symbolPlacement; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLSymbolPlacement symbolPlacementValue; - [value getValue:&symbolPlacementValue]; - auto str = mbgl::Enum::toString(symbolPlacementValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultSymbolPlacement().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setSymbolPlacement(func); - return; - } - id value = [(MGLStyleConstantValue *)symbolPlacement rawValue]; - MGLSymbolPlacement symbolPlacementValue; - [value getValue:&symbolPlacementValue]; - auto str = mbgl::Enum::toString(symbolPlacementValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultSymbolPlacement().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(symbolPlacement); _rawLayer->setSymbolPlacement(mbglValue); } - (MGLStyleValue *)symbolPlacement { auto propertyValue = _rawLayer->getSymbolPlacement() ?: _rawLayer->getDefaultSymbolPlacement(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setSymbolSpacing:(MGLStyleValue *)symbolSpacing { @@ -223,34 +208,16 @@ - (void)setIconOptional:(MGLStyleValue *)iconOptional { } - (void)setIconRotationAlignment:(MGLStyleValue *)iconRotationAlignment { - if ([iconRotationAlignment isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)iconRotationAlignment; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLIconRotationAlignment iconRotationAlignmentValue; - [value getValue:&iconRotationAlignmentValue]; - auto str = mbgl::Enum::toString(iconRotationAlignmentValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultIconRotationAlignment().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setIconRotationAlignment(func); - return; - } - id value = [(MGLStyleConstantValue *)iconRotationAlignment rawValue]; - MGLIconRotationAlignment iconRotationAlignmentValue; - [value getValue:&iconRotationAlignmentValue]; - auto str = mbgl::Enum::toString(iconRotationAlignmentValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultIconRotationAlignment().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconRotationAlignment); _rawLayer->setIconRotationAlignment(mbglValue); } - (MGLStyleValue *)iconRotationAlignment { auto propertyValue = _rawLayer->getIconRotationAlignment() ?: _rawLayer->getDefaultIconRotationAlignment(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setIconSize:(MGLStyleValue *)iconSize { @@ -264,34 +231,16 @@ - (void)setIconSize:(MGLStyleValue *)iconSize { } - (void)setIconTextFit:(MGLStyleValue *)iconTextFit { - if ([iconTextFit isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)iconTextFit; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLIconTextFit iconTextFitValue; - [value getValue:&iconTextFitValue]; - auto str = mbgl::Enum::toString(iconTextFitValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultIconTextFit().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setIconTextFit(func); - return; - } - id value = [(MGLStyleConstantValue *)iconTextFit rawValue]; - MGLIconTextFit iconTextFitValue; - [value getValue:&iconTextFitValue]; - auto str = mbgl::Enum::toString(iconTextFitValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultIconTextFit().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconTextFit); _rawLayer->setIconTextFit(mbglValue); } - (MGLStyleValue *)iconTextFit { auto propertyValue = _rawLayer->getIconTextFit() ?: _rawLayer->getDefaultIconTextFit(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setIconTextFitPadding:(MGLStyleValue *)iconTextFitPadding { @@ -355,65 +304,29 @@ - (void)setIconOffset:(MGLStyleValue *)iconOffset { } - (void)setTextPitchAlignment:(MGLStyleValue *)textPitchAlignment { - if ([textPitchAlignment isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)textPitchAlignment; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLTextPitchAlignment textPitchAlignmentValue; - [value getValue:&textPitchAlignmentValue]; - auto str = mbgl::Enum::toString(textPitchAlignmentValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultTextPitchAlignment().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setTextPitchAlignment(func); - return; - } - id value = [(MGLStyleConstantValue *)textPitchAlignment rawValue]; - MGLTextPitchAlignment textPitchAlignmentValue; - [value getValue:&textPitchAlignmentValue]; - auto str = mbgl::Enum::toString(textPitchAlignmentValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultTextPitchAlignment().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textPitchAlignment); _rawLayer->setTextPitchAlignment(mbglValue); } - (MGLStyleValue *)textPitchAlignment { auto propertyValue = _rawLayer->getTextPitchAlignment() ?: _rawLayer->getDefaultTextPitchAlignment(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextRotationAlignment:(MGLStyleValue *)textRotationAlignment { - if ([textRotationAlignment isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)textRotationAlignment; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLTextRotationAlignment textRotationAlignmentValue; - [value getValue:&textRotationAlignmentValue]; - auto str = mbgl::Enum::toString(textRotationAlignmentValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultTextRotationAlignment().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setTextRotationAlignment(func); - return; - } - id value = [(MGLStyleConstantValue *)textRotationAlignment rawValue]; - MGLTextRotationAlignment textRotationAlignmentValue; - [value getValue:&textRotationAlignmentValue]; - auto str = mbgl::Enum::toString(textRotationAlignmentValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultTextRotationAlignment().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textRotationAlignment); _rawLayer->setTextRotationAlignment(mbglValue); } - (MGLStyleValue *)textRotationAlignment { auto propertyValue = _rawLayer->getTextRotationAlignment() ?: _rawLayer->getDefaultTextRotationAlignment(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextField:(MGLStyleValue *)textField { @@ -477,65 +390,29 @@ - (void)setTextLetterSpacing:(MGLStyleValue *)textLetterSpacing { } - (void)setTextJustify:(MGLStyleValue *)textJustify { - if ([textJustify isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)textJustify; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLTextJustify textJustifyValue; - [value getValue:&textJustifyValue]; - auto str = mbgl::Enum::toString(textJustifyValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultTextJustify().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setTextJustify(func); - return; - } - id value = [(MGLStyleConstantValue *)textJustify rawValue]; - MGLTextJustify textJustifyValue; - [value getValue:&textJustifyValue]; - auto str = mbgl::Enum::toString(textJustifyValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultTextJustify().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textJustify); _rawLayer->setTextJustify(mbglValue); } - (MGLStyleValue *)textJustify { auto propertyValue = _rawLayer->getTextJustify() ?: _rawLayer->getDefaultTextJustify(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextAnchor:(MGLStyleValue *)textAnchor { - if ([textAnchor isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)textAnchor; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLTextAnchor textAnchorValue; - [value getValue:&textAnchorValue]; - auto str = mbgl::Enum::toString(textAnchorValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultTextAnchor().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setTextAnchor(func); - return; - } - id value = [(MGLStyleConstantValue *)textAnchor rawValue]; - MGLTextAnchor textAnchorValue; - [value getValue:&textAnchorValue]; - auto str = mbgl::Enum::toString(textAnchorValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultTextAnchor().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textAnchor); _rawLayer->setTextAnchor(mbglValue); } - (MGLStyleValue *)textAnchor { auto propertyValue = _rawLayer->getTextAnchor() ?: _rawLayer->getDefaultTextAnchor(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextMaxAngle:(MGLStyleValue *)textMaxAngle { @@ -579,34 +456,16 @@ - (void)setTextKeepUpright:(MGLStyleValue *)textKeepUpright { } - (void)setTextTransform:(MGLStyleValue *)textTransform { - if ([textTransform isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)textTransform; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLTextTransform textTransformValue; - [value getValue:&textTransformValue]; - auto str = mbgl::Enum::toString(textTransformValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultTextTransform().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setTextTransform(func); - return; - } - id value = [(MGLStyleConstantValue *)textTransform rawValue]; - MGLTextTransform textTransformValue; - [value getValue:&textTransformValue]; - auto str = mbgl::Enum::toString(textTransformValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultTextTransform().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textTransform); _rawLayer->setTextTransform(mbglValue); } - (MGLStyleValue *)textTransform { auto propertyValue = _rawLayer->getTextTransform() ?: _rawLayer->getDefaultTextTransform(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextOffset:(MGLStyleValue *)textOffset { @@ -712,34 +571,16 @@ - (void)setIconTranslate:(MGLStyleValue *)iconTranslate { } - (void)setIconTranslateAnchor:(MGLStyleValue *)iconTranslateAnchor { - if ([iconTranslateAnchor isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)iconTranslateAnchor; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLIconTranslateAnchor iconTranslateAnchorValue; - [value getValue:&iconTranslateAnchorValue]; - auto str = mbgl::Enum::toString(iconTranslateAnchorValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultIconTranslateAnchor().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setIconTranslateAnchor(func); - return; - } - id value = [(MGLStyleConstantValue *)iconTranslateAnchor rawValue]; - MGLIconTranslateAnchor iconTranslateAnchorValue; - [value getValue:&iconTranslateAnchorValue]; - auto str = mbgl::Enum::toString(iconTranslateAnchorValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultIconTranslateAnchor().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(iconTranslateAnchor); _rawLayer->setIconTranslateAnchor(mbglValue); } - (MGLStyleValue *)iconTranslateAnchor { auto propertyValue = _rawLayer->getIconTranslateAnchor() ?: _rawLayer->getDefaultIconTranslateAnchor(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } - (void)setTextOpacity:(MGLStyleValue *)textOpacity { @@ -803,34 +644,16 @@ - (void)setTextTranslate:(MGLStyleValue *)textTranslate { } - (void)setTextTranslateAnchor:(MGLStyleValue *)textTranslateAnchor { - if ([textTranslateAnchor isKindOfClass:[MGLStyleFunction class]]) { - MGLStyleFunction *function = (MGLStyleFunction *)textTranslateAnchor; - __block std::vector> mbglStops; - [function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue * _Nonnull stopValue, BOOL * _Nonnull stop) { - id value = [(MGLStyleConstantValue *)stopValue rawValue]; - MGLTextTranslateAnchor textTranslateAnchorValue; - [value getValue:&textTranslateAnchorValue]; - auto str = mbgl::Enum::toString(textTranslateAnchorValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultTextTranslateAnchor().asConstant()); - auto mbglStopValue = mbgl::style::PropertyValue(mbglValue); - mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant()); - }]; - auto func = mbgl::style::Function({{mbglStops}}, function.base); - _rawLayer->setTextTranslateAnchor(func); - return; - } - id value = [(MGLStyleConstantValue *)textTranslateAnchor rawValue]; - MGLTextTranslateAnchor textTranslateAnchorValue; - [value getValue:&textTranslateAnchorValue]; - auto str = mbgl::Enum::toString(textTranslateAnchorValue); - auto mbglValue = mbgl::Enum::toEnum(str).value_or(_rawLayer->getDefaultTextTranslateAnchor().asConstant()); + auto mbglValue = MGLStyleValueTransformer().toEnumPropertyValue(textTranslateAnchor); _rawLayer->setTextTranslateAnchor(mbglValue); } - (MGLStyleValue *)textTranslateAnchor { auto propertyValue = _rawLayer->getTextTranslateAnchor() ?: _rawLayer->getDefaultTextTranslateAnchor(); - - return MGLStyleEnumerationValueTransformer().propertyValueMGLStyleValue(propertyValue); + return MGLStyleValueTransformer().toEnumStyleValue(propertyValue); } diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h index c3bba81e1ee..3fe0f4faaed 100644 --- a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h +++ b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h @@ -14,87 +14,137 @@ NS_ASSUME_NONNULL_BEGIN @interface NSValue (MGLStyleEnumAttributeAdditions) -#pragma mark Runtime Styling enumerations +#pragma mark Working with Style Layer Enumeration Attribute Values /** -Creates a new value object containing the given `MGLLineCap` structure. +Creates a new value object containing the given `MGLLineCap` enumeration. @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLLineCap:(MGLLineCap)type; ++ (instancetype)valueWithMGLLineCap:(MGLLineCap)lineCap; /** -Creates a new value object containing the given `MGLLineJoin` structure. +The `MGLLineCap` enumeration representation of the value. +*/ +@property (readonly) MGLLineCap lineCap; + +/** +Creates a new value object containing the given `MGLLineJoin` enumeration. @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLLineJoin:(MGLLineJoin)type; ++ (instancetype)valueWithMGLLineJoin:(MGLLineJoin)lineJoin; /** -Creates a new value object containing the given `MGLSymbolPlacement` structure. +The `MGLLineJoin` enumeration representation of the value. +*/ +@property (readonly) MGLLineJoin lineJoin; + +/** +Creates a new value object containing the given `MGLSymbolPlacement` enumeration. @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLSymbolPlacement:(MGLSymbolPlacement)type; ++ (instancetype)valueWithMGLSymbolPlacement:(MGLSymbolPlacement)symbolPlacement; /** -Creates a new value object containing the given `MGLIconRotationAlignment` structure. +The `MGLSymbolPlacement` enumeration representation of the value. +*/ +@property (readonly) MGLSymbolPlacement symbolPlacement; + +/** +Creates a new value object containing the given `MGLIconRotationAlignment` enumeration. @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLIconRotationAlignment:(MGLIconRotationAlignment)type; ++ (instancetype)valueWithMGLIconRotationAlignment:(MGLIconRotationAlignment)iconRotationAlignment; + +/** +The `MGLIconRotationAlignment` enumeration representation of the value. +*/ +@property (readonly) MGLIconRotationAlignment iconRotationAlignment; /** -Creates a new value object containing the given `MGLIconTextFit` structure. +Creates a new value object containing the given `MGLIconTextFit` enumeration. @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLIconTextFit:(MGLIconTextFit)type; ++ (instancetype)valueWithMGLIconTextFit:(MGLIconTextFit)iconTextFit; + +/** +The `MGLIconTextFit` enumeration representation of the value. +*/ +@property (readonly) MGLIconTextFit iconTextFit; /** -Creates a new value object containing the given `MGLTextPitchAlignment` structure. +Creates a new value object containing the given `MGLTextPitchAlignment` enumeration. @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLTextPitchAlignment:(MGLTextPitchAlignment)type; ++ (instancetype)valueWithMGLTextPitchAlignment:(MGLTextPitchAlignment)textPitchAlignment; /** -Creates a new value object containing the given `MGLTextRotationAlignment` structure. +The `MGLTextPitchAlignment` enumeration representation of the value. +*/ +@property (readonly) MGLTextPitchAlignment textPitchAlignment; + +/** +Creates a new value object containing the given `MGLTextRotationAlignment` enumeration. @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLTextRotationAlignment:(MGLTextRotationAlignment)type; ++ (instancetype)valueWithMGLTextRotationAlignment:(MGLTextRotationAlignment)textRotationAlignment; /** -Creates a new value object containing the given `MGLTextJustify` structure. +The `MGLTextRotationAlignment` enumeration representation of the value. +*/ +@property (readonly) MGLTextRotationAlignment textRotationAlignment; + +/** +Creates a new value object containing the given `MGLTextJustify` enumeration. @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLTextJustify:(MGLTextJustify)type; ++ (instancetype)valueWithMGLTextJustify:(MGLTextJustify)textJustify; + +/** +The `MGLTextJustify` enumeration representation of the value. +*/ +@property (readonly) MGLTextJustify textJustify; /** -Creates a new value object containing the given `MGLTextAnchor` structure. +Creates a new value object containing the given `MGLTextAnchor` enumeration. @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLTextAnchor:(MGLTextAnchor)type; ++ (instancetype)valueWithMGLTextAnchor:(MGLTextAnchor)textAnchor; /** -Creates a new value object containing the given `MGLTextTransform` structure. +The `MGLTextAnchor` enumeration representation of the value. +*/ +@property (readonly) MGLTextAnchor textAnchor; + +/** +Creates a new value object containing the given `MGLTextTransform` enumeration. @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLTextTransform:(MGLTextTransform)type; ++ (instancetype)valueWithMGLTextTransform:(MGLTextTransform)textTransform; + +/** +The `MGLTextTransform` enumeration representation of the value. +*/ +@property (readonly) MGLTextTransform textTransform; /** Creates a new value object containing the given `MGLFillTranslateAnchor` structure. @@ -102,7 +152,12 @@ Creates a new value object containing the given `MGLFillTranslateAnchor` structu @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLFillTranslateAnchor:(MGLFillTranslateAnchor)type; ++ (instancetype)valueWithMGLFillTranslateAnchor:(MGLFillTranslateAnchor)fillTranslateAnchor; + +/** +The `MGLFillTranslateAnchor` enumeration representation of the value. +*/ +@property (readonly) MGLFillTranslateAnchor fillTranslateAnchor; /** Creates a new value object containing the given `MGLLineTranslateAnchor` structure. @@ -110,7 +165,12 @@ Creates a new value object containing the given `MGLLineTranslateAnchor` structu @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLLineTranslateAnchor:(MGLLineTranslateAnchor)type; ++ (instancetype)valueWithMGLLineTranslateAnchor:(MGLLineTranslateAnchor)lineTranslateAnchor; + +/** +The `MGLLineTranslateAnchor` enumeration representation of the value. +*/ +@property (readonly) MGLLineTranslateAnchor lineTranslateAnchor; /** Creates a new value object containing the given `MGLIconTranslateAnchor` structure. @@ -118,7 +178,12 @@ Creates a new value object containing the given `MGLIconTranslateAnchor` structu @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLIconTranslateAnchor:(MGLIconTranslateAnchor)type; ++ (instancetype)valueWithMGLIconTranslateAnchor:(MGLIconTranslateAnchor)iconTranslateAnchor; + +/** +The `MGLIconTranslateAnchor` enumeration representation of the value. +*/ +@property (readonly) MGLIconTranslateAnchor iconTranslateAnchor; /** Creates a new value object containing the given `MGLTextTranslateAnchor` structure. @@ -126,7 +191,12 @@ Creates a new value object containing the given `MGLTextTranslateAnchor` structu @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLTextTranslateAnchor:(MGLTextTranslateAnchor)type; ++ (instancetype)valueWithMGLTextTranslateAnchor:(MGLTextTranslateAnchor)textTranslateAnchor; + +/** +The `MGLTextTranslateAnchor` enumeration representation of the value. +*/ +@property (readonly) MGLTextTranslateAnchor textTranslateAnchor; /** Creates a new value object containing the given `MGLCircleTranslateAnchor` structure. @@ -134,7 +204,12 @@ Creates a new value object containing the given `MGLCircleTranslateAnchor` struc @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLCircleTranslateAnchor:(MGLCircleTranslateAnchor)type; ++ (instancetype)valueWithMGLCircleTranslateAnchor:(MGLCircleTranslateAnchor)circleTranslateAnchor; + +/** +The `MGLCircleTranslateAnchor` enumeration representation of the value. +*/ +@property (readonly) MGLCircleTranslateAnchor circleTranslateAnchor; /** Creates a new value object containing the given `MGLCirclePitchScale` structure. @@ -142,9 +217,13 @@ Creates a new value object containing the given `MGLCirclePitchScale` structure. @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGLCirclePitchScale:(MGLCirclePitchScale)type; ++ (instancetype)valueWithMGLCirclePitchScale:(MGLCirclePitchScale)circlePitchScale; - -NS_ASSUME_NONNULL_END +/** +The `MGLCirclePitchScale` enumeration representation of the value. +*/ +@property (readonly) MGLCirclePitchScale circlePitchScale; @end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs index 2aa6508cccd..a737812a891 100644 --- a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs +++ b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs @@ -18,18 +18,23 @@ NS_ASSUME_NONNULL_BEGIN @interface NSValue (MGLStyleEnumAttributeAdditions) -#pragma mark Runtime Styling enumerations +#pragma mark Working with Style Layer Enumeration Attribute Values <% if (layoutProperties.length) { -%> <% for (const property of layoutProperties) { -%> <% if (property.type == "enum") { -%> /** -Creates a new value object containing the given `MGL<%- camelize(property.name) %>` structure. +Creates a new value object containing the given `MGL<%- camelize(property.name) %>` enumeration. @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)type; ++ (instancetype)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %>; + +/** +The `MGL<%- camelize(property.name) %>` enumeration representation of the value. +*/ +@property (readonly) MGL<%- camelize(property.name) %> <%- objCName(property) %>; <% } -%> <% } -%> @@ -43,12 +48,16 @@ Creates a new value object containing the given `MGL<%- camelize(property.name) @param type The value for the new object. @return A new value object that contains the style enumeration type. */ -+ (instancetype)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)type; ++ (instancetype)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %>; + +/** +The `MGL<%- camelize(property.name) %>` enumeration representation of the value. +*/ +@property (readonly) MGL<%- camelize(property.name) %> <%- objCName(property) %>; <% } -%> <% } -%> <% } -%> +@end NS_ASSUME_NONNULL_END - -@end diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm index 2a9019af6af..dedff5cf375 100644 --- a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm +++ b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm @@ -5,68 +5,164 @@ @implementation NSValue (MGLStyleEnumAttributeAdditions) -+ (NSValue *)valueWithMGLLineCap:(MGLLineCap)type { - return [NSValue value:&type withObjCType:@encode(MGLLineCap)]; ++ (NSValue *)valueWithMGLLineCap:(MGLLineCap)lineCap { + return [NSValue value:&lineCap withObjCType:@encode(MGLLineCap)]; } -+ (NSValue *)valueWithMGLLineJoin:(MGLLineJoin)type { - return [NSValue value:&type withObjCType:@encode(MGLLineJoin)]; +- (MGLLineCap)lineCap { + MGLLineCap value; + [self getValue:&value]; + return value; } -+ (NSValue *)valueWithMGLSymbolPlacement:(MGLSymbolPlacement)type { - return [NSValue value:&type withObjCType:@encode(MGLSymbolPlacement)]; ++ (NSValue *)valueWithMGLLineJoin:(MGLLineJoin)lineJoin { + return [NSValue value:&lineJoin withObjCType:@encode(MGLLineJoin)]; } -+ (NSValue *)valueWithMGLIconRotationAlignment:(MGLIconRotationAlignment)type { - return [NSValue value:&type withObjCType:@encode(MGLIconRotationAlignment)]; +- (MGLLineJoin)lineJoin { + MGLLineJoin value; + [self getValue:&value]; + return value; } -+ (NSValue *)valueWithMGLIconTextFit:(MGLIconTextFit)type { - return [NSValue value:&type withObjCType:@encode(MGLIconTextFit)]; ++ (NSValue *)valueWithMGLSymbolPlacement:(MGLSymbolPlacement)symbolPlacement { + return [NSValue value:&symbolPlacement withObjCType:@encode(MGLSymbolPlacement)]; } -+ (NSValue *)valueWithMGLTextPitchAlignment:(MGLTextPitchAlignment)type { - return [NSValue value:&type withObjCType:@encode(MGLTextPitchAlignment)]; +- (MGLSymbolPlacement)symbolPlacement { + MGLSymbolPlacement value; + [self getValue:&value]; + return value; } -+ (NSValue *)valueWithMGLTextRotationAlignment:(MGLTextRotationAlignment)type { - return [NSValue value:&type withObjCType:@encode(MGLTextRotationAlignment)]; ++ (NSValue *)valueWithMGLIconRotationAlignment:(MGLIconRotationAlignment)iconRotationAlignment { + return [NSValue value:&iconRotationAlignment withObjCType:@encode(MGLIconRotationAlignment)]; } -+ (NSValue *)valueWithMGLTextJustify:(MGLTextJustify)type { - return [NSValue value:&type withObjCType:@encode(MGLTextJustify)]; +- (MGLIconRotationAlignment)iconRotationAlignment { + MGLIconRotationAlignment value; + [self getValue:&value]; + return value; } -+ (NSValue *)valueWithMGLTextAnchor:(MGLTextAnchor)type { - return [NSValue value:&type withObjCType:@encode(MGLTextAnchor)]; ++ (NSValue *)valueWithMGLIconTextFit:(MGLIconTextFit)iconTextFit { + return [NSValue value:&iconTextFit withObjCType:@encode(MGLIconTextFit)]; } -+ (NSValue *)valueWithMGLTextTransform:(MGLTextTransform)type { - return [NSValue value:&type withObjCType:@encode(MGLTextTransform)]; +- (MGLIconTextFit)iconTextFit { + MGLIconTextFit value; + [self getValue:&value]; + return value; } -+ (NSValue *)valueWithMGLFillTranslateAnchor:(MGLFillTranslateAnchor)type { -return [NSValue value:&type withObjCType:@encode(MGLFillTranslateAnchor)]; ++ (NSValue *)valueWithMGLTextPitchAlignment:(MGLTextPitchAlignment)textPitchAlignment { + return [NSValue value:&textPitchAlignment withObjCType:@encode(MGLTextPitchAlignment)]; } -+ (NSValue *)valueWithMGLLineTranslateAnchor:(MGLLineTranslateAnchor)type { -return [NSValue value:&type withObjCType:@encode(MGLLineTranslateAnchor)]; +- (MGLTextPitchAlignment)textPitchAlignment { + MGLTextPitchAlignment value; + [self getValue:&value]; + return value; } -+ (NSValue *)valueWithMGLIconTranslateAnchor:(MGLIconTranslateAnchor)type { -return [NSValue value:&type withObjCType:@encode(MGLIconTranslateAnchor)]; ++ (NSValue *)valueWithMGLTextRotationAlignment:(MGLTextRotationAlignment)textRotationAlignment { + return [NSValue value:&textRotationAlignment withObjCType:@encode(MGLTextRotationAlignment)]; } -+ (NSValue *)valueWithMGLTextTranslateAnchor:(MGLTextTranslateAnchor)type { -return [NSValue value:&type withObjCType:@encode(MGLTextTranslateAnchor)]; +- (MGLTextRotationAlignment)textRotationAlignment { + MGLTextRotationAlignment value; + [self getValue:&value]; + return value; } -+ (NSValue *)valueWithMGLCircleTranslateAnchor:(MGLCircleTranslateAnchor)type { -return [NSValue value:&type withObjCType:@encode(MGLCircleTranslateAnchor)]; ++ (NSValue *)valueWithMGLTextJustify:(MGLTextJustify)textJustify { + return [NSValue value:&textJustify withObjCType:@encode(MGLTextJustify)]; } -+ (NSValue *)valueWithMGLCirclePitchScale:(MGLCirclePitchScale)type { -return [NSValue value:&type withObjCType:@encode(MGLCirclePitchScale)]; +- (MGLTextJustify)textJustify { + MGLTextJustify value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLTextAnchor:(MGLTextAnchor)textAnchor { + return [NSValue value:&textAnchor withObjCType:@encode(MGLTextAnchor)]; +} + +- (MGLTextAnchor)textAnchor { + MGLTextAnchor value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLTextTransform:(MGLTextTransform)textTransform { + return [NSValue value:&textTransform withObjCType:@encode(MGLTextTransform)]; +} + +- (MGLTextTransform)textTransform { + MGLTextTransform value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLFillTranslateAnchor:(MGLFillTranslateAnchor)fillTranslateAnchor { +return [NSValue value:&fillTranslateAnchor withObjCType:@encode(MGLFillTranslateAnchor)]; +} + +- (MGLFillTranslateAnchor)fillTranslateAnchor { + MGLFillTranslateAnchor value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLLineTranslateAnchor:(MGLLineTranslateAnchor)lineTranslateAnchor { +return [NSValue value:&lineTranslateAnchor withObjCType:@encode(MGLLineTranslateAnchor)]; +} + +- (MGLLineTranslateAnchor)lineTranslateAnchor { + MGLLineTranslateAnchor value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLIconTranslateAnchor:(MGLIconTranslateAnchor)iconTranslateAnchor { +return [NSValue value:&iconTranslateAnchor withObjCType:@encode(MGLIconTranslateAnchor)]; +} + +- (MGLIconTranslateAnchor)iconTranslateAnchor { + MGLIconTranslateAnchor value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLTextTranslateAnchor:(MGLTextTranslateAnchor)textTranslateAnchor { +return [NSValue value:&textTranslateAnchor withObjCType:@encode(MGLTextTranslateAnchor)]; +} + +- (MGLTextTranslateAnchor)textTranslateAnchor { + MGLTextTranslateAnchor value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLCircleTranslateAnchor:(MGLCircleTranslateAnchor)circleTranslateAnchor { +return [NSValue value:&circleTranslateAnchor withObjCType:@encode(MGLCircleTranslateAnchor)]; +} + +- (MGLCircleTranslateAnchor)circleTranslateAnchor { + MGLCircleTranslateAnchor value; + [self getValue:&value]; + return value; +} + ++ (NSValue *)valueWithMGLCirclePitchScale:(MGLCirclePitchScale)circlePitchScale { +return [NSValue value:&circlePitchScale withObjCType:@encode(MGLCirclePitchScale)]; +} + +- (MGLCirclePitchScale)circlePitchScale { + MGLCirclePitchScale value; + [self getValue:&value]; + return value; } diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs index 084536d5391..d445fa0a555 100644 --- a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs +++ b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs @@ -13,8 +13,14 @@ const paintProperties = locals.paintProperties; <% if (layoutProperties.length) { -%> <% for (const property of layoutProperties) { -%> <% if (property.type == "enum") { -%> -+ (NSValue *)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)type { - return [NSValue value:&type withObjCType:@encode(MGL<%- camelize(property.name) %>)]; ++ (NSValue *)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %> { + return [NSValue value:&<%- objCName(property) %> withObjCType:@encode(MGL<%- camelize(property.name) %>)]; +} + +- (MGL<%- camelize(property.name) %>)<%- objCName(property) %> { + MGL<%- camelize(property.name) %> value; + [self getValue:&value]; + return value; } <% } -%> @@ -23,8 +29,14 @@ const paintProperties = locals.paintProperties; <% if (paintProperties.length) { -%> <% for (const property of paintProperties) { -%> <% if (property.type == "enum") { -%> -+ (NSValue *)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)type { -return [NSValue value:&type withObjCType:@encode(MGL<%- camelize(property.name) %>)]; ++ (NSValue *)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %> { +return [NSValue value:&<%- objCName(property) %> withObjCType:@encode(MGL<%- camelize(property.name) %>)]; +} + +- (MGL<%- camelize(property.name) %>)<%- objCName(property) %> { + MGL<%- camelize(property.name) %> value; + [self getValue:&value]; + return value; } <% } -%> diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 0588dbb90f5..91e934ed1fe 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -5,7 +5,6 @@ #import "MBXOfflinePacksTableViewController.h" #import "MBXAnnotationView.h" #import "MBXUserLocationAnnotationView.h" -#import "NSValue+MGLStyleEnumAttributeAdditions.h" #import "MGLFillStyleLayer.h" @@ -72,6 +71,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) { MBXSettingsRuntimeStylingVectorSource, MBXSettingsRuntimeStylingRasterSource, MBXSettingsRuntimeStylingCountryLabels, + MBXSettingsRuntimeStylingRouteLine, }; typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) { @@ -333,6 +333,7 @@ - (void)dismissSettings:(__unused id)sender @"Style Vector Source", @"Style Raster Source", [NSString stringWithFormat:@"Label Countries in %@", (_usingLocaleBasedCountryLabels ? @"Local Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])], + @"Add Route Line", ]]; break; case MBXSettingsMiscellaneous: @@ -491,6 +492,9 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath case MBXSettingsRuntimeStylingCountryLabels: [self styleCountryLabelsLanguage]; break; + case MBXSettingsRuntimeStylingRouteLine: + [self styleRouteLine]; + break; default: NSAssert(NO, @"All runtime styling setting rows should be implemented"); break; @@ -831,47 +835,6 @@ - (void)styleFilteredFill - (void)styleFilteredLines { - -#warning remove this test stub - - NSURL *customStyleURL = [[NSURL alloc] initWithString:@"mapbox://styles/boundsj/cipk5wcrv0052cvnfzx8lnbf3"]; - [self.mapView setStyleURL:customStyleURL]; - - - // fetch the line layer after a second to give it time to load - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - - MGLLineStyleLayer *randomLineLayer = (MGLLineStyleLayer *)[self.mapView.style layerWithIdentifier:@"random-line"]; - - randomLineLayer.lineJoin = [MGLStyleValue valueWithRawValue:[NSValue valueWithMGLLineJoin:MGLLineJoinMiter]]; - - MGLStyleConstantValue *lineJoin = (MGLStyleConstantValue *)randomLineLayer.lineJoin; - NSValue *join = (NSValue *)lineJoin.rawValue; - MGLLineJoin finalJoin; - [join getValue:&finalJoin]; - NSLog(@"================> join %ld", finalJoin); - - randomLineLayer.lineCap = [MBXViewController testEnumFunction:MGLLineCapRound type:@encode(MGLLineCap)]; - MGLStyleFunction *lineCapFunc = (MGLStyleFunction *)randomLineLayer.lineCap; - MGLStyleConstantValue *firstStop = (MGLStyleConstantValue *)lineCapFunc.stops[@18]; - NSValue *cap = (NSValue *)firstStop.rawValue; - MGLLineCap finalCap; - [cap getValue:&finalCap]; - NSLog(@"================> cap %ld", finalCap); - - randomLineLayer.lineTranslateAnchor = [MBXViewController testEnumFunction:MGLLineTranslateAnchorViewport type:@encode(MGLLineTranslateAnchor)]; - MGLStyleFunction *lineTransFunc = (MGLStyleFunction *)randomLineLayer.lineTranslateAnchor; - MGLStyleConstantValue *lineTransFuncFirstStop = (MGLStyleConstantValue *)lineTransFunc.stops[@18]; - NSValue *lineTransValue = (NSValue *)lineTransFuncFirstStop.rawValue; - MGLLineCap finalLineTrans; - [lineTransValue getValue:&finalLineTrans]; - NSLog(@"================> cap %ld", finalLineTrans); - }); - return; - - -#warning reenable this test - // set style and focus on lower 48 [self.mapView setStyleURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"line_filter_style" ofType:@"json"]]]; [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(40, -97) zoomLevel:5 animated:NO]; @@ -1135,6 +1098,44 @@ -(void)styleCountryLabelsLanguage [self styleLabelLanguageForLayersNamed:labelLayers]; } +- (void)styleRouteLine +{ + CLLocationCoordinate2D coords[] = { + { 43.84455590478528, 10.504238605499268 }, + { 43.84385562343126, 10.504125952720642 }, + { 43.84388657526694, 10.503299832344055 }, + { 43.84332557075269, 10.503235459327698 }, + { 43.843441641085036, 10.502264499664307 }, + { 43.84396395478592, 10.50242006778717 }, + { 43.84406067904351, 10.501744151115416 }, + { 43.84422317544319, 10.501792430877686 } + }; + NSInteger count = sizeof(coords) / sizeof(coords[0]); + + [self.mapView setCenterCoordinate:coords[0] zoomLevel:16 animated:YES]; + + MGLPolylineFeature *routeLine = [MGLPolylineFeature polylineWithCoordinates:coords count:count]; + + MGLGeoJSONSource *routeSource = [[MGLGeoJSONSource alloc] initWithIdentifier:@"style-route-source" features:@[routeLine] options:nil]; + [self.mapView.style addSource:routeSource]; + + MGLLineStyleLayer *baseRouteLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"style-base-route-layer" source:routeSource]; + baseRouteLayer.lineColor = [MGLStyleConstantValue valueWithRawValue:[UIColor orangeColor]]; + baseRouteLayer.lineWidth = [MGLStyleConstantValue valueWithRawValue:@20]; + baseRouteLayer.lineOpacity = [MGLStyleConstantValue valueWithRawValue:@0.5]; + baseRouteLayer.lineCap = [MGLStyleConstantValue valueWithRawValue:[NSValue valueWithMGLLineCap:MGLLineCapRound]]; + baseRouteLayer.lineJoin = [MGLStyleConstantValue valueWithRawValue:[NSValue valueWithMGLLineJoin:MGLLineJoinRound]]; + [self.mapView.style addLayer:baseRouteLayer]; + + MGLLineStyleLayer *routeLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"style-base-route-layer" source:routeSource]; + routeLayer.lineColor = [MGLStyleConstantValue valueWithRawValue:[UIColor whiteColor]]; + routeLayer.lineWidth = [MGLStyleConstantValue valueWithRawValue:@15]; + routeLayer.lineOpacity = [MGLStyleConstantValue valueWithRawValue:@0.8]; + routeLayer.lineCap = [MGLStyleConstantValue valueWithRawValue:[NSValue valueWithMGLLineCap:MGLLineCapRound]]; + routeLayer.lineJoin = [MGLStyleConstantValue valueWithRawValue:[NSValue valueWithMGLLineJoin:MGLLineJoinRound]]; + [self.mapView.style addLayer:routeLayer]; +} + - (void)styleLabelLanguageForLayersNamed:(NSArray *)layers { _usingLocaleBasedCountryLabels = !_usingLocaleBasedCountryLabels; diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index bfe3569da77..2149df9db77 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -127,8 +127,8 @@ 4018B1C91CDC288A00F666AF /* MGLAnnotationView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4018B1C31CDC277F00F666AF /* MGLAnnotationView_Private.h */; }; 4018B1CA1CDC288E00F666AF /* MGLAnnotationView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4018B1C51CDC277F00F666AF /* MGLAnnotationView.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4018B1CB1CDC288E00F666AF /* MGLAnnotationView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4018B1C51CDC277F00F666AF /* MGLAnnotationView.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 4032C5BF1DE1FC780062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4032C5B81DE1EE7D0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h */; }; - 4032C5C01DE1FC780062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4032C5B81DE1EE7D0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h */; }; + 4032C5BF1DE1FC780062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4032C5B81DE1EE7D0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4032C5C01DE1FC780062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4032C5B81DE1EE7D0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4032C5C11DE1FC7E0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4032C5BD1DE1FC690062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm */; }; 4032C5C21DE1FC7E0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4032C5BD1DE1FC690062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm */; }; 404326891D5B9B27007111BD /* MGLAnnotationContainerView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 404326881D5B9B1A007111BD /* MGLAnnotationContainerView_Private.h */; }; diff --git a/platform/ios/src/Mapbox.h b/platform/ios/src/Mapbox.h index c2fda1be1f3..7664695315a 100644 --- a/platform/ios/src/Mapbox.h +++ b/platform/ios/src/Mapbox.h @@ -51,5 +51,6 @@ FOUNDATION_EXPORT const unsigned char MapboxVersionString[]; #import "MGLUserLocation.h" #import "MGLUserLocationAnnotationView.h" #import "NSValue+MGLAdditions.h" +#import "NSValue+MGLStyleEnumAttributeAdditions.h" #import "MGLStyleValue.h" #import "MGLTileSet.h" diff --git a/platform/macos/macos.xcodeproj/project.pbxproj b/platform/macos/macos.xcodeproj/project.pbxproj index 4df0ef3cd57..3ab9d4d9c0a 100644 --- a/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/macos/macos.xcodeproj/project.pbxproj @@ -40,7 +40,7 @@ 35C5D84A1D6DD66D00E95907 /* NSCompoundPredicate+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 35C5D8461D6DD66D00E95907 /* NSCompoundPredicate+MGLAdditions.mm */; }; 35D65C5A1D65AD5500722C23 /* NSDate+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 35D65C581D65AD5500722C23 /* NSDate+MGLAdditions.h */; }; 35D65C5B1D65AD5500722C23 /* NSDate+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 35D65C591D65AD5500722C23 /* NSDate+MGLAdditions.mm */; }; - 4032C5C51DE1FE930062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4032C5B91DE1EEBA0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h */; }; + 4032C5C51DE1FE930062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4032C5B91DE1EEBA0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4032C5C61DE1FE9B0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4032C5C31DE1FE810062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.mm */; }; 4049C2A51DB6CE7F00B3F799 /* MGLPointCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 4049C2A11DB6CE7800B3F799 /* MGLPointCollection.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4049C2AD1DB8020600B3F799 /* MGLPointCollection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4049C2A71DB6D09B00B3F799 /* MGLPointCollection.mm */; }; diff --git a/platform/macos/src/Mapbox.h b/platform/macos/src/Mapbox.h index cfddfe6e89b..73b8624be04 100644 --- a/platform/macos/src/Mapbox.h +++ b/platform/macos/src/Mapbox.h @@ -46,4 +46,5 @@ FOUNDATION_EXPORT const unsigned char MapboxVersionString[]; #import "MGLTilePyramidOfflineRegion.h" #import "MGLTypes.h" #import "NSValue+MGLAdditions.h" +#import "NSValue+MGLStyleEnumAttributeAdditions.h" #import "MGLStyleValue.h"