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 30, 2016
1 parent 4096544 commit 0c518ad
Show file tree
Hide file tree
Showing 23 changed files with 929 additions and 907 deletions.
21 changes: 17 additions & 4 deletions platform/darwin/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ 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';

// Rename properties and keep `original` for use with setters and getters
_.forOwn(cocoaConventions, function (properties, kind) {
_.forOwn(properties, function (newName, oldName) {
spec[kind][newName] = spec[kind][oldName];
spec[kind][newName].original = oldName;
delete spec[kind][oldName];
})
});

global.camelize = function (str) {
return str.replace(/(?:^|-)(.)/g, function (_, x) {
return x.toUpperCase();
Expand Down Expand Up @@ -212,6 +221,10 @@ global.propertyDefault = function (property, layerType) {
return 'an `MGLStyleValue` object containing ' + describeValue(property.default, property, layerType);
};

global.originalPropertyName = function (property) {
return property.original || property.name;
}

global.propertyType = function (property) {
switch (property.type) {
case 'boolean':
Expand Down Expand Up @@ -321,8 +334,8 @@ const layers = Object.keys(spec.layer.type.values).map((type) => {

return {
type: type,
layoutProperties: layoutProperties,
paintProperties: paintProperties,
layoutProperties: _.sortBy(layoutProperties, ['name']),
paintProperties: _.sortBy(paintProperties, ['name']),
layoutPropertiesByName: spec[`layout_${type}`],
paintPropertiesByName: spec[`paint_${type}`],
};
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": "minimum-raster-brightness",
"raster-brightness-max": "maximum-raster-brightness"
}
}
10 changes: 5 additions & 5 deletions platform/darwin/src/MGLBackgroundStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *backgroundColor;
#endif

/**
Name of image in style images to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512).
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *backgroundPattern;

/**
The opacity at which the background will be drawn.
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 *> *backgroundOpacity;

/**
Name of image in style images to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512).
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *backgroundPattern;

@end

NS_ASSUME_NONNULL_END
20 changes: 10 additions & 10 deletions platform/darwin/src/MGLBackgroundStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ - (void)setBackgroundColor:(MGLStyleValue<MGLColor *> *)backgroundColor {
return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue);
}

- (void)setBackgroundPattern:(MGLStyleValue<NSString *> *)backgroundPattern {
auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(backgroundPattern);
_rawLayer->setBackgroundPattern(mbglValue);
}

- (MGLStyleValue<NSString *> *)backgroundPattern {
auto propertyValue = _rawLayer->getBackgroundPattern() ?: _rawLayer->getDefaultBackgroundPattern();
return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue);
}

- (void)setBackgroundOpacity:(MGLStyleValue<NSNumber *> *)backgroundOpacity {
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(backgroundOpacity);
_rawLayer->setBackgroundOpacity(mbglValue);
Expand All @@ -90,5 +80,15 @@ - (void)setBackgroundOpacity:(MGLStyleValue<NSNumber *> *)backgroundOpacity {
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
}

- (void)setBackgroundPattern:(MGLStyleValue<NSString *> *)backgroundPattern {
auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(backgroundPattern);
_rawLayer->setBackgroundPattern(mbglValue);
}

- (MGLStyleValue<NSString *> *)backgroundPattern {
auto propertyValue = _rawLayer->getBackgroundPattern() ?: _rawLayer->getDefaultBackgroundPattern();
return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue);
}


@end
64 changes: 32 additions & 32 deletions platform/darwin/src/MGLCircleStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@
NS_ASSUME_NONNULL_BEGIN

/**
Controls the translation reference point.
Controls the scaling behavior of the circle when the map is pitched.
Values of this type are used in the `circleTranslateAnchor` property of `MGLCircleStyleLayer`.
Values of this type are used in the `circlePitchScale` property of `MGLCircleStyleLayer`.
*/
typedef NS_ENUM(NSUInteger, MGLCircleTranslateAnchor) {
typedef NS_ENUM(NSUInteger, MGLCirclePitchScale) {
/**
The circle is translated relative to the map.
Circles are scaled according to their apparent distance to the camera.
*/
MGLCircleTranslateAnchorMap,
MGLCirclePitchScaleMap,
/**
The circle is translated relative to the viewport.
Circles are not scaled.
*/
MGLCircleTranslateAnchorViewport,
MGLCirclePitchScaleViewport,
};

/**
Controls the scaling behavior of the circle when the map is pitched.
Controls the translation reference point.
Values of this type are used in the `circlePitchScale` property of `MGLCircleStyleLayer`.
Values of this type are used in the `circleTranslateAnchor` property of `MGLCircleStyleLayer`.
*/
typedef NS_ENUM(NSUInteger, MGLCirclePitchScale) {
typedef NS_ENUM(NSUInteger, MGLCircleTranslateAnchor) {
/**
Circles are scaled according to their apparent distance to the camera.
The circle is translated relative to the map.
*/
MGLCirclePitchScaleMap,
MGLCircleTranslateAnchorMap,
/**
Circles are not scaled.
The circle is translated relative to the viewport.
*/
MGLCirclePitchScaleViewport,
MGLCircleTranslateAnchorViewport,
};

/**
Expand All @@ -49,13 +49,11 @@ typedef NS_ENUM(NSUInteger, MGLCirclePitchScale) {
#pragma mark - Accessing the Paint Attributes

/**
Circle radius.
This property is measured in points.
Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity.
The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `5`. Set this property to `nil` to reset it to the default value.
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 *> *circleRadius;
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleBlur;

#if TARGET_OS_IPHONE
/**
Expand All @@ -74,18 +72,27 @@ typedef NS_ENUM(NSUInteger, MGLCirclePitchScale) {
#endif

/**
Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity.
The opacity at which the circle will be drawn.
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.
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 *> *circleBlur;
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleOpacity;

/**
The opacity at which the circle will be drawn.
Controls the scaling behavior of the circle when the map is pitched.
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.
The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLCirclePitchScaleMap`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleOpacity;
@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *circlePitchScale;

/**
Circle radius.
This property is measured in points.
The default value of this property is an `MGLStyleValue` object containing an `NSNumber` object containing the float `5`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *circleRadius;

/**
The geometry's offset.
Expand All @@ -105,13 +112,6 @@ typedef NS_ENUM(NSUInteger, MGLCirclePitchScale) {
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *circleTranslateAnchor;

/**
Controls the scaling behavior of the circle when the map is pitched.
The default value of this property is an `MGLStyleValue` object containing an `NSValue` object containing `MGLCirclePitchScaleMap`. Set this property to `nil` to reset it to the default value.
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *circlePitchScale;

@end

NS_ASSUME_NONNULL_END
60 changes: 30 additions & 30 deletions platform/darwin/src/MGLCircleStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
#include <mbgl/style/layers/circle_layer.hpp>
namespace mbgl {

MBGL_DEFINE_ENUM(MGLCircleTranslateAnchor, {
{ MGLCircleTranslateAnchorMap, "map" },
{ MGLCircleTranslateAnchorViewport, "viewport" },
});

MBGL_DEFINE_ENUM(MGLCirclePitchScale, {
{ MGLCirclePitchScaleMap, "map" },
{ MGLCirclePitchScaleViewport, "viewport" },
});

MBGL_DEFINE_ENUM(MGLCircleTranslateAnchor, {
{ MGLCircleTranslateAnchorMap, "map" },
{ MGLCircleTranslateAnchorViewport, "viewport" },
});

}

@interface MGLCircleStyleLayer ()
Expand Down Expand Up @@ -92,13 +92,13 @@ - (void)removeFromMapView:(MGLMapView *)mapView

#pragma mark - Accessing the Paint Attributes

- (void)setCircleRadius:(MGLStyleValue<NSNumber *> *)circleRadius {
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(circleRadius);
_rawLayer->setCircleRadius(mbglValue);
- (void)setCircleBlur:(MGLStyleValue<NSNumber *> *)circleBlur {
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(circleBlur);
_rawLayer->setCircleBlur(mbglValue);
}

- (MGLStyleValue<NSNumber *> *)circleRadius {
auto propertyValue = _rawLayer->getCircleRadius() ?: _rawLayer->getDefaultCircleRadius();
- (MGLStyleValue<NSNumber *> *)circleBlur {
auto propertyValue = _rawLayer->getCircleBlur() ?: _rawLayer->getDefaultCircleBlur();
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
}

Expand All @@ -112,16 +112,6 @@ - (void)setCircleColor:(MGLStyleValue<MGLColor *> *)circleColor {
return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue);
}

- (void)setCircleBlur:(MGLStyleValue<NSNumber *> *)circleBlur {
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(circleBlur);
_rawLayer->setCircleBlur(mbglValue);
}

- (MGLStyleValue<NSNumber *> *)circleBlur {
auto propertyValue = _rawLayer->getCircleBlur() ?: _rawLayer->getDefaultCircleBlur();
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
}

- (void)setCircleOpacity:(MGLStyleValue<NSNumber *> *)circleOpacity {
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(circleOpacity);
_rawLayer->setCircleOpacity(mbglValue);
Expand All @@ -132,6 +122,26 @@ - (void)setCircleOpacity:(MGLStyleValue<NSNumber *> *)circleOpacity {
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
}

- (void)setCirclePitchScale:(MGLStyleValue<NSValue *> *)circlePitchScale {
auto mbglValue = MGLStyleValueTransformer<mbgl::style::CirclePitchScaleType, NSValue *, mbgl::style::CirclePitchScaleType, MGLCirclePitchScale>().toEnumPropertyValue(circlePitchScale);
_rawLayer->setCirclePitchScale(mbglValue);
}

- (MGLStyleValue<NSValue *> *)circlePitchScale {
auto propertyValue = _rawLayer->getCirclePitchScale() ?: _rawLayer->getDefaultCirclePitchScale();
return MGLStyleValueTransformer<mbgl::style::CirclePitchScaleType, NSValue *, mbgl::style::CirclePitchScaleType, MGLCirclePitchScale>().toEnumStyleValue(propertyValue);
}

- (void)setCircleRadius:(MGLStyleValue<NSNumber *> *)circleRadius {
auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(circleRadius);
_rawLayer->setCircleRadius(mbglValue);
}

- (MGLStyleValue<NSNumber *> *)circleRadius {
auto propertyValue = _rawLayer->getCircleRadius() ?: _rawLayer->getDefaultCircleRadius();
return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue);
}

- (void)setCircleTranslate:(MGLStyleValue<NSValue *> *)circleTranslate {
auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue(circleTranslate);
_rawLayer->setCircleTranslate(mbglValue);
Expand All @@ -152,15 +162,5 @@ - (void)setCircleTranslateAnchor:(MGLStyleValue<NSValue *> *)circleTranslateAnch
return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLCircleTranslateAnchor>().toEnumStyleValue(propertyValue);
}

- (void)setCirclePitchScale:(MGLStyleValue<NSValue *> *)circlePitchScale {
auto mbglValue = MGLStyleValueTransformer<mbgl::style::CirclePitchScaleType, NSValue *, mbgl::style::CirclePitchScaleType, MGLCirclePitchScale>().toEnumPropertyValue(circlePitchScale);
_rawLayer->setCirclePitchScale(mbglValue);
}

- (MGLStyleValue<NSValue *> *)circlePitchScale {
auto propertyValue = _rawLayer->getCirclePitchScale() ?: _rawLayer->getDefaultCirclePitchScale();
return MGLStyleValueTransformer<mbgl::style::CirclePitchScaleType, NSValue *, mbgl::style::CirclePitchScaleType, MGLCirclePitchScale>().toEnumStyleValue(propertyValue);
}


@end
24 changes: 12 additions & 12 deletions platform/darwin/src/MGLFillStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslateAnchor) {
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *fillAntialias;

/**
The opacity of the entire fill layer. In contrast to the `fillColor`, this value will also affect the 1pt stroke around the fill, if the stroke is used.
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 *> *fillOpacity;

#if TARGET_OS_IPHONE
/**
The color of the filled part of this layer.
Expand All @@ -66,13 +59,25 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslateAnchor) {
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *fillColor;
#endif

/**
The opacity of the entire fill layer. In contrast to the `fillColor`, this value will also affect the 1pt stroke around the fill, if the stroke is used.
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 *> *fillOpacity;

/**
The outline color of the fill. Matches the value of `fillColor` if unspecified.
This property is only applied to the style if `fillPattern` is set to `nil`, and `fillAntialias` is set to an `MGLStyleValue` object containing an `NSNumber` object containing `YES`. Otherwise, it is ignored.
*/
@property (nonatomic, null_resettable) MGLStyleValue<MGLColor *> *fillOutlineColor;

/**
Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512).
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *fillPattern;

/**
The geometry's offset.
Expand All @@ -91,11 +96,6 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslateAnchor) {
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *fillTranslateAnchor;

/**
Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512).
*/
@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *fillPattern;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 0c518ad

Please sign in to comment.