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

Commit

Permalink
[ios, macos] rename style spec properties
Browse files Browse the repository at this point in the history
  • Loading branch information
frederoni committed Nov 21, 2016
1 parent 307f8e4 commit aae1e77
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 63 deletions.
18 changes: 16 additions & 2 deletions platform/darwin/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@ const fs = require('fs');
const ejs = require('ejs');
const _ = require('lodash');
const colorParser = require('csscolorparser');
const spec = _.merge(require('mapbox-gl-style-spec').latest, require('./style-spec-overrides-v8.json'));

const cocoaConventions = require('./style-spec-cocoa-conventions-v8.json');
let spec = _.merge(require('mapbox-gl-style-spec').latest, require('./style-spec-overrides-v8.json'));
const prefix = 'MGL';
const suffix = 'StyleLayer';

function renameProperties(obj, overrides, stack='') {
_.forOwn(overrides, function (value, key) {
const keyPath = stack + '.';
if (_.isObject(value)) {
renameProperties(obj, overrides[key], stack.length ? keyPath + key : key);
} else {
_.set(obj, keyPath + overrides[key], _.get(obj, keyPath + key));
_.unset(obj, keyPath + key);
}
});
}

renameProperties(spec, cocoaConventions);

global.camelize = function (str) {
return str.replace(/(?:^|-)(.)/g, function (_, x) {
return x.toUpperCase();
Expand Down
9 changes: 9 additions & 0 deletions platform/darwin/scripts/style-spec-cocoa-conventions-v8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"layout_symbol": {
"icon-image": "icon-image-name"
},
"paint_raster": {
"raster-brightness-min": "raster-brightness-minimum",
"raster-brightness-max": "raster-brightness-maximum"
}
}
28 changes: 14 additions & 14 deletions platform/darwin/src/MGLRasterStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *rasterHueRotate;

/**
Increase or reduce the brightness of the image. The value is the minimum brightness.
The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *rasterBrightnessMin;

/**
Increase or reduce the brightness of the image. The value is the maximum brightness.
The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *rasterBrightnessMax;

/**
Increase or reduce the saturation of the image.
Expand All @@ -69,6 +55,20 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *rasterFadeDuration;

/**
Increase or reduce the brightness of the image. The value is the minimum brightness.
The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `0`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *rasterBrightnessMinimum;

/**
Increase or reduce the brightness of the image. The value is the maximum brightness.
The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `1`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *rasterBrightnessMaximum;

@end

NS_ASSUME_NONNULL_END
40 changes: 20 additions & 20 deletions platform/darwin/src/MGLRasterStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,6 @@ - (void)setRasterHueRotate:(MGLStyleValue<NSNumber *> *)rasterHueRotate {
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
}

- (void)setRasterBrightnessMin:(MGLStyleValue<NSNumber *> *)rasterBrightnessMin {
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(rasterBrightnessMin);
self.rawLayer->setRasterBrightnessMin(mbglValue);
}

- (MGLStyleValue<NSNumber *> *)rasterBrightnessMin {
auto propertyValue = self.rawLayer->getRasterBrightnessMin() ?: self.rawLayer->getDefaultRasterBrightnessMin();
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
}

- (void)setRasterBrightnessMax:(MGLStyleValue<NSNumber *> *)rasterBrightnessMax {
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(rasterBrightnessMax);
self.rawLayer->setRasterBrightnessMax(mbglValue);
}

- (MGLStyleValue<NSNumber *> *)rasterBrightnessMax {
auto propertyValue = self.rawLayer->getRasterBrightnessMax() ?: self.rawLayer->getDefaultRasterBrightnessMax();
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
}

- (void)setRasterSaturation:(MGLStyleValue<NSNumber *> *)rasterSaturation {
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(rasterSaturation);
self.rawLayer->setRasterSaturation(mbglValue);
Expand Down Expand Up @@ -129,5 +109,25 @@ - (void)setRasterFadeDuration:(MGLStyleValue<NSNumber *> *)rasterFadeDuration {
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
}

- (void)setRasterBrightnessMinimum:(MGLStyleValue<NSNumber *> *)rasterBrightnessMinimum {
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(rasterBrightnessMinimum);
self.rawLayer->setRasterBrightnessMinimum(mbglValue);
}

- (MGLStyleValue<NSNumber *> *)rasterBrightnessMinimum {
auto propertyValue = self.rawLayer->getRasterBrightnessMinimum() ?: self.rawLayer->getDefaultRasterBrightnessMinimum();
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
}

- (void)setRasterBrightnessMaximum:(MGLStyleValue<NSNumber *> *)rasterBrightnessMaximum {
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(rasterBrightnessMaximum);
self.rawLayer->setRasterBrightnessMaximum(mbglValue);
}

- (MGLStyleValue<NSNumber *> *)rasterBrightnessMaximum {
auto propertyValue = self.rawLayer->getRasterBrightnessMaximum() ?: self.rawLayer->getDefaultRasterBrightnessMaximum();
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
}


@end
10 changes: 5 additions & 5 deletions platform/darwin/src/MGLSymbolStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,6 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) {
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *iconTextFitPadding;

/**
A string with {tokens} replaced, referencing the data property to pull from.
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *iconImage;

/**
Rotates the icon clockwise.
Expand Down Expand Up @@ -552,6 +547,11 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) {
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *textOptional;

/**
A string with {tokens} replaced, referencing the data property to pull from.
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *iconImageName;

#pragma mark - Accessing the Paint Attributes

/**
Expand Down
20 changes: 10 additions & 10 deletions platform/darwin/src/MGLSymbolStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,6 @@ - (void)setIconTextFitPadding:(MGLStyleValue<NSValue *> *)iconTextFitPadding {
return MGLStyleValueTransformer<std::array<float, 4>, NSValue *>().toStyleValue(propertyValue);
}

- (void)setIconImage:(MGLStyleValue<NSString *> *)iconImage {
auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(iconImage);
self.rawLayer->setIconImage(mbglValue);
}

- (MGLStyleValue<NSString *> *)iconImage {
auto propertyValue = self.rawLayer->getIconImage() ?: self.rawLayer->getDefaultIconImage();
return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue);
}

- (void)setIconRotate:(MGLStyleValue<NSNumber *> *)iconRotate {
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(iconRotate);
self.rawLayer->setIconRotate(mbglValue);
Expand Down Expand Up @@ -420,6 +410,16 @@ - (void)setTextOptional:(MGLStyleValue<NSNumber *> *)textOptional {
return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue);
}

- (void)setIconImageName:(MGLStyleValue<NSString *> *)iconImageName {
auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(iconImageName);
self.rawLayer->setIconImageName(mbglValue);
}

- (MGLStyleValue<NSString *> *)iconImageName {
auto propertyValue = self.rawLayer->getIconImageName() ?: self.rawLayer->getDefaultIconImageName();
return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue);
}

#pragma mark - Accessing the Paint Attributes

- (void)setIconOpacity:(MGLStyleValue<NSNumber *> *)iconOpacity {
Expand Down
16 changes: 8 additions & 8 deletions platform/darwin/test/MGLRasterStyleLayerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,37 @@ - (void)testRasterLayer {

layer.rasterOpacity = [MGLRuntimeStylingHelper testNumber];
layer.rasterHueRotate = [MGLRuntimeStylingHelper testNumber];
layer.rasterBrightnessMin = [MGLRuntimeStylingHelper testNumber];
layer.rasterBrightnessMax = [MGLRuntimeStylingHelper testNumber];
layer.rasterSaturation = [MGLRuntimeStylingHelper testNumber];
layer.rasterContrast = [MGLRuntimeStylingHelper testNumber];
layer.rasterFadeDuration = [MGLRuntimeStylingHelper testNumber];
layer.rasterBrightnessMinimum = [MGLRuntimeStylingHelper testNumber];
layer.rasterBrightnessMaximum = [MGLRuntimeStylingHelper testNumber];

MGLRasterStyleLayer *gLayer = (MGLRasterStyleLayer *)[self.mapView.style layerWithIdentifier:@"layerID"];
XCTAssertTrue([gLayer isKindOfClass:[MGLRasterStyleLayer class]]);
XCTAssertEqualObjects(gLayer.rasterOpacity, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.rasterHueRotate, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.rasterBrightnessMin, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.rasterBrightnessMax, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.rasterSaturation, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.rasterContrast, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.rasterFadeDuration, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.rasterBrightnessMinimum, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.rasterBrightnessMaximum, [MGLRuntimeStylingHelper testNumber]);

layer.rasterOpacity = [MGLRuntimeStylingHelper testNumberFunction];
layer.rasterHueRotate = [MGLRuntimeStylingHelper testNumberFunction];
layer.rasterBrightnessMin = [MGLRuntimeStylingHelper testNumberFunction];
layer.rasterBrightnessMax = [MGLRuntimeStylingHelper testNumberFunction];
layer.rasterSaturation = [MGLRuntimeStylingHelper testNumberFunction];
layer.rasterContrast = [MGLRuntimeStylingHelper testNumberFunction];
layer.rasterFadeDuration = [MGLRuntimeStylingHelper testNumberFunction];
layer.rasterBrightnessMinimum = [MGLRuntimeStylingHelper testNumberFunction];
layer.rasterBrightnessMaximum = [MGLRuntimeStylingHelper testNumberFunction];

XCTAssertEqualObjects(gLayer.rasterOpacity, [MGLRuntimeStylingHelper testNumberFunction]);
XCTAssertEqualObjects(gLayer.rasterHueRotate, [MGLRuntimeStylingHelper testNumberFunction]);
XCTAssertEqualObjects(gLayer.rasterBrightnessMin, [MGLRuntimeStylingHelper testNumberFunction]);
XCTAssertEqualObjects(gLayer.rasterBrightnessMax, [MGLRuntimeStylingHelper testNumberFunction]);
XCTAssertEqualObjects(gLayer.rasterSaturation, [MGLRuntimeStylingHelper testNumberFunction]);
XCTAssertEqualObjects(gLayer.rasterContrast, [MGLRuntimeStylingHelper testNumberFunction]);
XCTAssertEqualObjects(gLayer.rasterFadeDuration, [MGLRuntimeStylingHelper testNumberFunction]);
XCTAssertEqualObjects(gLayer.rasterBrightnessMinimum, [MGLRuntimeStylingHelper testNumberFunction]);
XCTAssertEqualObjects(gLayer.rasterBrightnessMaximum, [MGLRuntimeStylingHelper testNumberFunction]);
}

@end
8 changes: 4 additions & 4 deletions platform/darwin/test/MGLSymbolStyleLayerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ - (void)testSymbolLayer {
layer.iconSize = [MGLRuntimeStylingHelper testNumber];
layer.iconTextFit = [MGLRuntimeStylingHelper testEnum:MGLIconTextFitBoth type:@encode(MGLIconTextFit)];
layer.iconTextFitPadding = [MGLRuntimeStylingHelper testPadding];
layer.iconImage = [MGLRuntimeStylingHelper testString];
layer.iconRotate = [MGLRuntimeStylingHelper testNumber];
layer.iconPadding = [MGLRuntimeStylingHelper testNumber];
layer.iconKeepUpright = [MGLRuntimeStylingHelper testBool];
Expand All @@ -50,6 +49,7 @@ - (void)testSymbolLayer {
layer.textAllowOverlap = [MGLRuntimeStylingHelper testBool];
layer.textIgnorePlacement = [MGLRuntimeStylingHelper testBool];
layer.textOptional = [MGLRuntimeStylingHelper testBool];
layer.iconImageName = [MGLRuntimeStylingHelper testString];
layer.iconOpacity = [MGLRuntimeStylingHelper testNumber];
layer.iconColor = [MGLRuntimeStylingHelper testColor];
layer.iconHaloColor = [MGLRuntimeStylingHelper testColor];
Expand Down Expand Up @@ -80,7 +80,6 @@ - (void)testSymbolLayer {
XCTAssert([gLayer.iconTextFit isKindOfClass:[MGLStyleConstantValue class]]);
XCTAssertEqualObjects(gLayer.iconTextFit, [MGLRuntimeStylingHelper testEnum:MGLIconTextFitBoth type:@encode(MGLIconTextFit)]);
XCTAssertEqualObjects(gLayer.iconTextFitPadding, [MGLRuntimeStylingHelper testPadding]);
XCTAssertEqualObjects(gLayer.iconImage, [MGLRuntimeStylingHelper testString]);
XCTAssertEqualObjects(gLayer.iconRotate, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.iconPadding, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.iconKeepUpright, [MGLRuntimeStylingHelper testBool]);
Expand Down Expand Up @@ -109,6 +108,7 @@ - (void)testSymbolLayer {
XCTAssertEqualObjects(gLayer.textAllowOverlap, [MGLRuntimeStylingHelper testBool]);
XCTAssertEqualObjects(gLayer.textIgnorePlacement, [MGLRuntimeStylingHelper testBool]);
XCTAssertEqualObjects(gLayer.textOptional, [MGLRuntimeStylingHelper testBool]);
XCTAssertEqualObjects(gLayer.iconImageName, [MGLRuntimeStylingHelper testString]);
XCTAssertEqualObjects(gLayer.iconOpacity, [MGLRuntimeStylingHelper testNumber]);
XCTAssertEqualObjects(gLayer.iconColor, [MGLRuntimeStylingHelper testColor]);
XCTAssertEqualObjects(gLayer.iconHaloColor, [MGLRuntimeStylingHelper testColor]);
Expand Down Expand Up @@ -136,7 +136,6 @@ - (void)testSymbolLayer {
layer.iconSize = [MGLRuntimeStylingHelper testNumberFunction];
layer.iconTextFit = [MGLRuntimeStylingHelper testEnumFunction:MGLIconTextFitBoth type:@encode(MGLIconTextFit)];
layer.iconTextFitPadding = [MGLRuntimeStylingHelper testPaddingFunction];
layer.iconImage = [MGLRuntimeStylingHelper testStringFunction];
layer.iconRotate = [MGLRuntimeStylingHelper testNumberFunction];
layer.iconPadding = [MGLRuntimeStylingHelper testNumberFunction];
layer.iconKeepUpright = [MGLRuntimeStylingHelper testBoolFunction];
Expand All @@ -160,6 +159,7 @@ - (void)testSymbolLayer {
layer.textAllowOverlap = [MGLRuntimeStylingHelper testBoolFunction];
layer.textIgnorePlacement = [MGLRuntimeStylingHelper testBoolFunction];
layer.textOptional = [MGLRuntimeStylingHelper testBoolFunction];
layer.iconImageName = [MGLRuntimeStylingHelper testStringFunction];
layer.iconOpacity = [MGLRuntimeStylingHelper testNumberFunction];
layer.iconColor = [MGLRuntimeStylingHelper testColorFunction];
layer.iconHaloColor = [MGLRuntimeStylingHelper testColorFunction];
Expand All @@ -185,7 +185,6 @@ - (void)testSymbolLayer {
XCTAssertEqualObjects(gLayer.iconSize, [MGLRuntimeStylingHelper testNumberFunction]);
XCTAssertEqualObjects(gLayer.iconTextFit, [MGLRuntimeStylingHelper testEnumFunction:MGLIconTextFitBoth type:@encode(MGLIconTextFit)]);
XCTAssertEqualObjects(gLayer.iconTextFitPadding, [MGLRuntimeStylingHelper testPaddingFunction]);
XCTAssertEqualObjects(gLayer.iconImage, [MGLRuntimeStylingHelper testStringFunction]);
XCTAssertEqualObjects(gLayer.iconRotate, [MGLRuntimeStylingHelper testNumberFunction]);
XCTAssertEqualObjects(gLayer.iconPadding, [MGLRuntimeStylingHelper testNumberFunction]);
XCTAssertEqualObjects(gLayer.iconKeepUpright, [MGLRuntimeStylingHelper testBoolFunction]);
Expand All @@ -209,6 +208,7 @@ - (void)testSymbolLayer {
XCTAssertEqualObjects(gLayer.textAllowOverlap, [MGLRuntimeStylingHelper testBoolFunction]);
XCTAssertEqualObjects(gLayer.textIgnorePlacement, [MGLRuntimeStylingHelper testBoolFunction]);
XCTAssertEqualObjects(gLayer.textOptional, [MGLRuntimeStylingHelper testBoolFunction]);
XCTAssertEqualObjects(gLayer.iconImageName, [MGLRuntimeStylingHelper testStringFunction]);
XCTAssertEqualObjects(gLayer.iconOpacity, [MGLRuntimeStylingHelper testNumberFunction]);
XCTAssertEqualObjects(gLayer.iconColor, [MGLRuntimeStylingHelper testColorFunction]);
XCTAssertEqualObjects(gLayer.iconHaloColor, [MGLRuntimeStylingHelper testColorFunction]);
Expand Down

0 comments on commit aae1e77

Please sign in to comment.