Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release-ios-v3.6.0-android-v5.1.0' into merge_mapbox_v5_1
Browse files Browse the repository at this point in the history
* release-ios-v3.6.0-android-v5.1.0:
  [ios, macos] Updated changelogs
  [ios] Update pods spec for iOS v3.6.0-beta.3
  MGLLight autogenerate scripts (mapbox#9260)
  • Loading branch information
Tran Thuong Tien committed Jun 19, 2017
2 parents 1787307 + 8699bcd commit eef6f5b
Show file tree
Hide file tree
Showing 13 changed files with 526 additions and 177 deletions.
2 changes: 1 addition & 1 deletion include/mbgl/style/position.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace style {
class Position {
public:
Position() = default;
Position(std::array<float, 3>& position_)
Position(const std::array<float, 3>& position_)
: radial(position_[0]), azimuthal(position_[1]), polar(position_[2]) {
calculateCartesian();
};
Expand Down
39 changes: 38 additions & 1 deletion platform/darwin/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ global.mbglTestValue = function (property, layerType) {
type = 'Alignment';
}
let value = camelize(_.last(_.keys(property.values)));
if (property['light-property']) {
return `mbgl::style::Light${type}Type::${value}`;
}
return `mbgl::style::${type}Type::${value}`;
}
case 'color':
Expand Down Expand Up @@ -225,6 +228,9 @@ global.propertyDoc = function (propertyName, property, layerType, kind) {
let doc = property.doc.replace(/`([^`]+?)` is set to `([^`]+?)`/g, function (m, peerPropertyName, propertyValue, offset, str) {
let otherProperty = camelizeWithLeadingLowercase(peerPropertyName);
let otherValue = objCType(layerType, peerPropertyName) + camelize(propertyValue);
if (property.type == 'array' && kind == 'light') {
otherValue = propertyValue;
}
return '`' + `${otherProperty}` + '` is set to `' + `${otherValue}` + '`';
});
// Match references to our own property values.
Expand Down Expand Up @@ -256,7 +262,7 @@ global.propertyDoc = function (propertyName, property, layerType, kind) {
if (kind !== 'enum') {
if ('default' in property) {
doc += `\n\nThe default value of this property is ${propertyDefault(property, layerType)}.`;
if (!property.required) {
if (!property.required && kind != 'light') {
doc += ' Set this property to `nil` to reset it to the default value.';
}
}
Expand Down Expand Up @@ -348,6 +354,8 @@ global.describeValue = function (value, property, layerType) {
let objCType = global.objCType(layerType, property.name);
return `${conjunction}\`${objCType}${camelize(possibleValue)}\``;
}).join(separator);
} else if (property['light-property']) {
displayValue = `\`${prefix}Light${camelize(property.name)}${camelize(value)}\``;
} else {
let objCType = global.objCType(layerType, property.name);
displayValue = `\`${objCType}${camelize(value)}\``;
Expand Down Expand Up @@ -382,6 +390,8 @@ global.describeValue = function (value, property, layerType) {
case 'offset':
case 'translate':
return 'an `NSValue` object containing a `CGVector` struct set to' + ` ${value[0]}${units} rightward and ${value[1]}${units} downward`;
case 'position':
return 'an `MGLSphericalPosition` struct set to' + ` ${value[0]} radial, ${value[1]} azimuthal and ${value[2]} polar`;
default:
return 'the array `' + value.join('`, `') + '`';
}
Expand Down Expand Up @@ -418,6 +428,7 @@ global.propertyType = function (property) {
return 'NSArray<NSString *> *';
case 'padding':
return 'NSValue *';
case 'position':
case 'offset':
case 'translate':
return 'NSValue *';
Expand Down Expand Up @@ -457,6 +468,8 @@ global.valueTransformerArguments = function (property) {
return ['std::vector<std::string>', objCType, 'std::string'];
case 'padding':
return ['std::array<float, 4>', objCType];
case 'position':
return ['mbgl::style::Position', objCType];
case 'offset':
case 'translate':
return ['std::array<float, 2>', objCType];
Expand All @@ -478,6 +491,9 @@ global.mbglType = function(property) {
return 'std::string';
case 'enum': {
let type = camelize(originalPropertyName(property));
if (property['light-property']) {
return `mbgl::style::Light${type}Type`;
}
if (/-translate-anchor$/.test(originalPropertyName(property))) {
type = 'TranslateAnchor';
}
Expand All @@ -499,6 +515,8 @@ global.mbglType = function(property) {
case 'offset':
case 'translate':
return 'std::array<float, 2>';
case 'position':
return 'mbgl::style::Position';
default:
throw new Error(`unknown array type for ${property.name}`);
}
Expand All @@ -519,13 +537,32 @@ global.setSourceLayer = function() {
return `_layer->setSourceLayer(sourceLayer.UTF8String);`
};

const lightProperties = Object.keys(spec['light']).reduce((memo, name) => {
var property = spec['light'][name];
property.name = name;
property['light-property'] = true;
memo.push(property);
return memo;
}, []);

const lightDoc = spec['light-cocoa-doc'];
const lightType = 'light';

const layerH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.h.ejs', 'utf8'), { strict: true });
const layerM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.mm.ejs', 'utf8'), { strict: true});
const testLayers = ejs.compile(fs.readFileSync('platform/darwin/test/MGLStyleLayerTests.mm.ejs', 'utf8'), { strict: true});
const forStyleAuthorsMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/For Style Authors.md.ejs', 'utf8'), { strict: true });
const ddsGuideMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Using Style Functions at Runtime.md.ejs', 'utf8'), { strict: true });
const templatesMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/Tile URL Templates.md.ejs', 'utf8'), { strict: true });

const lightH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.h.ejs', 'utf8'), {strict: true});
const lightM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLLight.mm.ejs', 'utf8'), {strict: true});
const testLight = ejs.compile(fs.readFileSync('platform/darwin/test/MGLLightTest.mm.ejs', 'utf8'), { strict: true});
fs.writeFileSync(`platform/darwin/src/MGLLight.h`, duplicatePlatformDecls(lightH({ properties: lightProperties, doc: lightDoc, type: lightType })));
fs.writeFileSync(`platform/darwin/src/MGLLight.mm`, lightM({ properties: lightProperties, doc: lightDoc, type: lightType }));
fs.writeFileSync(`platform/darwin/test/MGLLightTest.mm`, testLight({ properties: lightProperties, doc: lightDoc, type: lightType }));


const layers = _(spec.layer.type.values).map((value, layerType) => {
const layoutProperties = Object.keys(spec[`layout_${layerType}`]).reduce((memo, name) => {
if (name !== 'visibility') {
Expand Down
6 changes: 6 additions & 0 deletions platform/darwin/scripts/style-spec-overrides-v8.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"light-cocoa-doc": "An `MGLLight` object represents the light source for extruded geometries in `MGLStyle`.",
"light": {
"position": {
"doc": "Position of the `MGLLight` source relative to lit (extruded) geometries, in a `MGLSphericalPosition` struct [radial coordinate, azimuthal angle, polar angle] where radial indicates the distance from the center of the base of an object to its light, azimuthal indicates the position of the light relative to 0° (0° when `MGLLight.anchor` is set to `MGLLightAnchorViewport` corresponds to the top of the viewport, or 0° when `MGLLight.anchor` is set to `MGLLightAnchorMap` corresponds to due north, and degrees proceed clockwise), and polar indicates the height of the light (from 0°, directly above, to 180°, directly below)."
}
},
"layer": {
"type": {
"values": {
Expand Down
118 changes: 93 additions & 25 deletions platform/darwin/src/MGLLight.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
// This file is generated.
// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.

#import <CoreLocation/CoreLocation.h>

#import "MGLFoundation.h"
#import "MGLStyleValue.h"

NS_ASSUME_NONNULL_BEGIN


/** Options to specify extruded geometries are lit relative to the map or viewport. */
/**
Whether extruded geometries are lit relative to the map or viewport.
*/
typedef NS_ENUM(NSUInteger, MGLLightAnchor) {
/** The position of the light source is aligned to the rotation of the map. */
/**
The position of the light source is aligned to the rotation of the map.
*/
MGLLightAnchorMap,
/** The position of the light source is aligned to the rotation of the viewport. */
MGLLightAnchorViewport
/**
The position of the light source is aligned to the rotation of the
viewport.
*/
MGLLightAnchorViewport,
};

/**
Expand All @@ -38,7 +47,7 @@ typedef struct MGLSphericalPosition {
@return Returns a `MGLSphericalPosition` struct containing the position attributes.
*/
NS_INLINE MGLSphericalPosition MGLSphericalPositionMake(CLLocationDistance radial, CLLocationDirection azimuthal, CLLocationDirection polar) {
NS_INLINE MGLSphericalPosition MGLSphericalPositionMake(CGFloat radial, CLLocationDirection azimuthal, CLLocationDirection polar) {
MGLSphericalPosition position;
position.radial = radial;
position.azimuthal = azimuthal;
Expand All @@ -54,72 +63,131 @@ MGL_EXPORT
@interface MGLLight : NSObject

/**
`anchor` Whether extruded geometries are lit relative to the map or viewport.
Whether extruded geometries are lit relative to the map or viewport.
The default value of this property is an `MGLStyleValue` object containing an
`NSValue` object containing `MGLLightAnchorViewport`.
You can set this property to an instance of:
* `MGLConstantStyleValue`
* `MGLCameraStyleFunction` with an interpolation mode of
`MGLInterpolationModeInterval`
This property corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-anchor"><code>anchor</code></a>
light property in the Mapbox Style Specification.
*/
@property (nonatomic) MGLStyleValue<NSValue *> *anchor;

/**
Values describing animated transitions to `anchor` property.
*/
@property (nonatomic) MGLTransition anchorTransition;


/**
Position of the light source relative to lit (extruded) geometries.
Position of the `MGLLight` source relative to lit (extruded) geometries, in a
`MGLSphericalPosition` struct [radial coordinate, azimuthal angle, polar angle]
where radial indicates the distance from the center of the base of an object to
its light, azimuthal indicates the position of the light relative to 0° (0°
when `MGLLight.anchor` is set to `MGLLightAnchorViewport` corresponds to the
top of the viewport, or 0° when `MGLLight.anchor` is set to `MGLLightAnchorMap`
corresponds to due north, and degrees proceed clockwise), and polar indicates
the height of the light (from 0°, directly above, to 180°, directly below).
The default value of this property is an `MGLStyleValue` object containing an
`MGLSphericalPosition` struct set to 1.15 radial, 210 azimuthal and 30 polar.
You can set this property to an instance of:
* `MGLConstantStyleValue`
* `MGLCameraStyleFunction` with an interpolation mode of:
* `MGLInterpolationModeExponential`
* `MGLInterpolationModeInterval`
This property corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-position"><code>position</code></a>
light property in the Mapbox Style Specification.
*/
@property (nonatomic) MGLStyleValue<NSValue *> *position;

/**
Values describing animated transitions to `position` property.
*/
@property (nonatomic) MGLTransition positionTransiton;
The transition affecting any changes to this layer’s `position` property.
This property corresponds to the `position-transition` property in the style JSON file format.
*/
@property (nonatomic) MGLTransition positionTransition;

#if TARGET_OS_IPHONE
/**
Color tint for lighting extruded geometries.
The default value of this property is an `MGLStyleValue` object containing
`UIColor.whiteColor`.
You can set this property to an instance of:
* `MGLConstantStyleValue`
* `MGLCameraStyleFunction` with an interpolation mode of:
* `MGLInterpolationModeExponential`
* `MGLInterpolationModeInterval`
This property corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-color"><code>color</code></a>
light property in the Mapbox Style Specification.
*/
@property (nonatomic) MGLStyleValue<UIColor *> *color;
#else

/**
Color tint for lighting extruded geometries.
The default value of this property is an `MGLStyleValue` object containing
`NSColor.whiteColor`.
You can set this property to an instance of:
* `MGLConstantStyleValue`
* `MGLCameraStyleFunction` with an interpolation mode of:
* `MGLInterpolationModeExponential`
* `MGLInterpolationModeInterval`
This property corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-color"><code>color</code></a>
light property in the Mapbox Style Specification.
*/
@property (nonatomic) MGLStyleValue<NSColor *> *color;
#endif

/**
Values describing animated transitions to `color` property.
*/
@property (nonatomic) MGLTransition colorTransiton;
The transition affecting any changes to this layer’s `color` property.
This property corresponds to the `color-transition` property in the style JSON file format.
*/
@property (nonatomic) MGLTransition colorTransition;

/**
Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as more extreme contrast.
Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as
more extreme contrast.
The default value of this property is an `MGLStyleValue` object containing an
`NSNumber` object containing the float `0.5`.
You can set this property to an instance of:
* `MGLConstantStyleValue`
* `MGLCameraStyleFunction` with an interpolation mode of:
* `MGLInterpolationModeExponential`
* `MGLInterpolationModeInterval`
This property corresponds to the <a
href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-intensity"><code>intensity</code></a>
light property in the Mapbox Style Specification.
*/
@property(nonatomic) MGLStyleValue<NSNumber *> *intensity;
@property (nonatomic) MGLStyleValue<NSNumber *> *intensity;

/**
Values describing animated transitions to `intensity` property.
*/
The transition affecting any changes to this layer’s `intensity` property.
This property corresponds to the `intensity-transition` property in the style JSON file format.
*/
@property (nonatomic) MGLTransition intensityTransition;


@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit eef6f5b

Please sign in to comment.