summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/docs/guides/For Style Authors.md.ejs2
-rw-r--r--platform/darwin/scripts/generate-style-code.js39
-rw-r--r--platform/darwin/scripts/style-spec-overrides-v8.json6
-rw-r--r--platform/darwin/src/MGLForegroundStyleLayer.h7
-rw-r--r--platform/darwin/src/MGLGeometry.h4
-rw-r--r--platform/darwin/src/MGLLight.h120
-rw-r--r--platform/darwin/src/MGLLight.h.ejs100
-rw-r--r--platform/darwin/src/MGLLight.mm41
-rw-r--r--platform/darwin/src/MGLLight.mm.ejs114
-rw-r--r--platform/darwin/src/MGLMultiPoint.h5
-rw-r--r--platform/darwin/src/MGLOfflinePack.h2
-rw-r--r--platform/darwin/src/MGLShape.h10
-rw-r--r--platform/darwin/src/MGLSource.h8
-rw-r--r--platform/darwin/src/MGLStyleLayer.h8
-rw-r--r--platform/darwin/src/MGLStyleValue.h9
-rw-r--r--platform/darwin/src/MGLTileSource.h6
-rw-r--r--platform/darwin/src/MGLTypes.h2
-rw-r--r--platform/darwin/src/MGLVectorStyleLayer.h9
-rw-r--r--platform/darwin/test/MGLLightTest.mm177
-rw-r--r--platform/darwin/test/MGLLightTest.mm.ejs92
20 files changed, 550 insertions, 211 deletions
diff --git a/platform/darwin/docs/guides/For Style Authors.md.ejs b/platform/darwin/docs/guides/For Style Authors.md.ejs
index 153639371c..06a8907704 100644
--- a/platform/darwin/docs/guides/For Style Authors.md.ejs
+++ b/platform/darwin/docs/guides/For Style Authors.md.ejs
@@ -121,6 +121,8 @@ for ink economy before printing the map view.
<% if (iOS) { -%>
For more information about user interface design, consult Apple’s
[_iOS Human Interface Guidelines_](https://developer.apple.com/ios/human-interface-guidelines/).
+To learn more about designing maps for mobile devices, see [Nathaniel Slaughter's blog post](https://www.mapbox.com/blog/designing-maps-for-mobile-devices/) on
+the subject.
<% } else { -%>
For more information about user interface design, consult Apple’s
[_macOS Human Interface Guidelines_](https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/OSXHIGuidelines/).
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js
index 7efc8d441c..5a4936c0ee 100644
--- a/platform/darwin/scripts/generate-style-code.js
+++ b/platform/darwin/scripts/generate-style-code.js
@@ -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':
@@ -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.
@@ -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.';
}
}
@@ -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)}\``;
@@ -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('`, `') + '`';
}
@@ -418,6 +428,7 @@ global.propertyType = function (property) {
return 'NSArray<NSString *> *';
case 'padding':
return 'NSValue *';
+ case 'position':
case 'offset':
case 'translate':
return 'NSValue *';
@@ -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];
@@ -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';
}
@@ -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}`);
}
@@ -519,6 +537,17 @@ 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});
@@ -526,6 +555,14 @@ const forStyleAuthorsMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guid
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') {
diff --git a/platform/darwin/scripts/style-spec-overrides-v8.json b/platform/darwin/scripts/style-spec-overrides-v8.json
index a594ef2957..67a6641fe7 100644
--- a/platform/darwin/scripts/style-spec-overrides-v8.json
+++ b/platform/darwin/scripts/style-spec-overrides-v8.json
@@ -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": {
diff --git a/platform/darwin/src/MGLForegroundStyleLayer.h b/platform/darwin/src/MGLForegroundStyleLayer.h
index 16a973630e..bcd323fb99 100644
--- a/platform/darwin/src/MGLForegroundStyleLayer.h
+++ b/platform/darwin/src/MGLForegroundStyleLayer.h
@@ -11,9 +11,10 @@ NS_ASSUME_NONNULL_BEGIN
`MGLForegroundStyleLayer` is an abstract superclass for style layers whose
content is defined by an `MGLSource` object.
- Do not create instances of this class directly, and do not create your own
- subclasses of this class. Instead, create instances of `MGLRasterStyleLayer`
- and the concrete subclasses of `MGLVectorStyleLayer`.
+ Create instances of `MGLRasterStyleLayer` and the concrete subclasses of
+ `MGLVectorStyleLayer` in order to use `MGLForegroundStyleLayer`'s methods.
+ Do not create instances of `MGLForegroundStyleLayer` directly, and do not
+ create your own subclasses of this class.
*/
MGL_EXPORT
@interface MGLForegroundStyleLayer : MGLStyleLayer
diff --git a/platform/darwin/src/MGLGeometry.h b/platform/darwin/src/MGLGeometry.h
index 3a3e59fb3e..7c68033abf 100644
--- a/platform/darwin/src/MGLGeometry.h
+++ b/platform/darwin/src/MGLGeometry.h
@@ -7,7 +7,7 @@
NS_ASSUME_NONNULL_BEGIN
/** Defines the area spanned by an `MGLCoordinateBounds`. */
-typedef struct MGLCoordinateSpan {
+typedef struct __attribute__((objc_boxable)) MGLCoordinateSpan {
/** Latitudes spanned by an `MGLCoordinateBounds`. */
CLLocationDegrees latitudeDelta;
/** Longitudes spanned by an `MGLCoordinateBounds`. */
@@ -38,7 +38,7 @@ NS_INLINE BOOL MGLCoordinateSpanEqualToCoordinateSpan(MGLCoordinateSpan span1, M
extern MGL_EXPORT const MGLCoordinateSpan MGLCoordinateSpanZero;
/** A rectangular area as measured on a two-dimensional map projection. */
-typedef struct MGLCoordinateBounds {
+typedef struct __attribute__((objc_boxable)) MGLCoordinateBounds {
/** Coordinate at the southwest corner. */
CLLocationCoordinate2D sw;
/** Coordinate at the northeast corner. */
diff --git a/platform/darwin/src/MGLLight.h b/platform/darwin/src/MGLLight.h
index ef9811bd33..55b789f043 100644
--- a/platform/darwin/src/MGLLight.h
+++ b/platform/darwin/src/MGLLight.h
@@ -1,3 +1,6 @@
+// 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"
@@ -5,13 +8,19 @@
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,
};
/**
@@ -20,7 +29,7 @@ typedef NS_ENUM(NSUInteger, MGLLightAnchor) {
*/
typedef struct MGLSphericalPosition {
/** Distance from the center of the base of an object to its light. */
- CLLocationDistance radial;
+ CGFloat radial;
/** Position of the light relative to 0° (0° when `MGLLight.anchor` is set to viewport corresponds
to the top of the viewport, or 0° when `MGLLight.anchor` is set to map corresponds to due north,
and degrees proceed clockwise). */
@@ -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;
@@ -54,8 +63,17 @@ 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.
@@ -63,14 +81,25 @@ MGL_EXPORT
@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.
@@ -78,48 +107,87 @@ MGL_EXPORT
@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
diff --git a/platform/darwin/src/MGLLight.h.ejs b/platform/darwin/src/MGLLight.h.ejs
new file mode 100644
index 0000000000..26ecefc3af
--- /dev/null
+++ b/platform/darwin/src/MGLLight.h.ejs
@@ -0,0 +1,100 @@
+<%
+ const properties = locals.properties;
+ const type = locals.type;
+ const doc = locals.doc;
+-%>
+// 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
+
+<% for (const property of properties) { -%>
+<% if (property.type == "enum") { -%>
+/**
+<%- propertyDoc(property.name, property, type, 'enum').wrap(80, 1) %>
+ */
+typedef NS_ENUM(NSUInteger, MGLLight<%- camelize(property.name) %>) {
+<% for (const value in property.values) { -%>
+ /**
+<%- propertyDoc(property.name, property.values[value], type, 'enum').wrap(80, 4+1) %>
+ */
+ MGLLightAnchor<%- camelize(value) %>,
+<% } -%>
+};
+<% } -%>
+<% } -%>
+
+/**
+ A structure containing information about the position of the light source
+ relative to lit geometries.
+ */
+typedef struct MGLSphericalPosition {
+ /** Distance from the center of the base of an object to its light. */
+ CGFloat radial;
+ /** Position of the light relative to 0° (0° when `MGLLight.anchor` is set to viewport corresponds
+ to the top of the viewport, or 0° when `MGLLight.anchor` is set to map corresponds to due north,
+ and degrees proceed clockwise). */
+ CLLocationDirection azimuthal;
+ /** Indicates the height of the light (from 0°, directly above, to 180°, directly below). */
+ CLLocationDirection polar;
+} MGLSphericalPosition;
+
+/**
+ Creates a new `MGLSphericalPosition` from the given radial, azimuthal, polar.
+
+ @param radial The radial coordinate.
+ @param azimuthal The azimuthal angle.
+ @param polar The polar angle.
+
+ @return Returns a `MGLSphericalPosition` struct containing the position attributes.
+ */
+NS_INLINE MGLSphericalPosition MGLSphericalPositionMake(CGFloat radial, CLLocationDirection azimuthal, CLLocationDirection polar) {
+ MGLSphericalPosition position;
+ position.radial = radial;
+ position.azimuthal = azimuthal;
+ position.polar = polar;
+
+ return position;
+}
+
+/**
+ <%- doc %>
+ */
+MGL_EXPORT
+@interface MGLLight : NSObject
+<% if (properties.length) { -%>
+
+<% for (const property of properties) { -%>
+/**
+<%- propertyDoc(property.name, property, type, 'light').wrap(80, 1) %>
+
+ This property corresponds to the <a
+ href="https://www.mapbox.com/mapbox-gl-js/style-spec/#light-<%- originalPropertyName(property) %>"><code><%- originalPropertyName(property) %></code></a>
+ light property in the Mapbox Style Specification.
+ */
+@property (nonatomic<% if (property.getter) { %>, getter=<%- objCGetter(property) -%><% } %>) MGLStyleValue<<%- propertyType(property, true) %>> *<%- camelizeWithLeadingLowercase(property.name) %>;
+
+<% if (property.transition) { -%>
+/**
+ The transition affecting any changes to this layer’s `<%- camelizeWithLeadingLowercase(property.name) %>` property.
+
+ This property corresponds to the `<%- originalPropertyName(property) %>-transition` property in the style JSON file format.
+*/
+@property (nonatomic) MGLTransition <%- camelizeWithLeadingLowercase(property.name) %>Transition;
+
+<% } -%>
+<% if (property.original) { -%>
+@property (nonatomic<% if (!property.required) { %>, null_resettable<% } %>) MGLStyleValue<<%- propertyType(property, true) %>> *<%- camelizeWithLeadingLowercase(originalPropertyName(property)) %> __attribute__((unavailable("Use <%- camelizeWithLeadingLowercase(property.name) %> instead.")));
+
+<% } -%>
+<% } -%>
+<% } -%>
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/darwin/src/MGLLight.mm b/platform/darwin/src/MGLLight.mm
index 262fad3b07..c83ef127a6 100644
--- a/platform/darwin/src/MGLLight.mm
+++ b/platform/darwin/src/MGLLight.mm
@@ -1,3 +1,7 @@
+// This file is generated.
+// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
+// test
+
#import "MGLLight.h"
#import "MGLTypes.h"
@@ -9,7 +13,7 @@
#import <mbgl/style/types.hpp>
namespace mbgl {
-
+
MBGL_DEFINE_ENUM(MGLLightAnchor, {
{ MGLLightAnchorMap, "map" },
{ MGLLightAnchorViewport, "viewport" },
@@ -47,11 +51,9 @@ NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition
} else {
anchorStyleValue = MGLStyleValueTransformer<mbgl::style::LightAnchorType, NSValue *, mbgl::style::LightAnchorType, MGLLightAnchor>().toEnumStyleValue(anchor);
}
-
+
_anchor = anchorStyleValue;
-
- _anchorTransition = MGLTransitionFromOptions(mbglLight->getAnchorTransition());
-
+
auto positionValue = mbglLight->getPosition();
if (positionValue.isUndefined()) {
_position = MGLStyleValueTransformer<mbgl::style::Position, NSValue *>().toStyleValue(mbglLight->getDefaultPosition());
@@ -59,8 +61,8 @@ NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition
_position = MGLStyleValueTransformer<mbgl::style::Position, NSValue *>().toStyleValue(positionValue);
}
- _positionTransiton = MGLTransitionFromOptions(mbglLight->getPositionTransition());
-
+ _positionTransition = MGLTransitionFromOptions(mbglLight->getPositionTransition());
+
auto colorValue = mbglLight->getColor();
if (colorValue.isUndefined()) {
_color = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(mbglLight->getDefaultColor());
@@ -68,8 +70,8 @@ NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition
_color = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(colorValue);
}
- _colorTransiton = MGLTransitionFromOptions(mbglLight->getColorTransition());
-
+ _colorTransition = MGLTransitionFromOptions(mbglLight->getColorTransition());
+
auto intensityValue = mbglLight->getIntensity();
if (intensityValue.isUndefined()) {
_intensity = MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(mbglLight->getDefaultIntensity());
@@ -78,6 +80,7 @@ NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition
}
_intensityTransition = MGLTransitionFromOptions(mbglLight->getIntensityTransition());
+
}
return self;
@@ -86,26 +89,24 @@ NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition
- (mbgl::style::Light)mbglLight
{
mbgl::style::Light mbglLight;
-
auto anchor = MGLStyleValueTransformer<mbgl::style::LightAnchorType, NSValue *, mbgl::style::LightAnchorType, MGLLightAnchor>().toEnumPropertyValue(self.anchor);
mbglLight.setAnchor(anchor);
-
- mbglLight.setAnchorTransition(MGLOptionsFromTransition(self.anchorTransition));
-
+
auto position = MGLStyleValueTransformer<mbgl::style::Position, NSValue *>().toInterpolatablePropertyValue(self.position);
mbglLight.setPosition(position);
-
- mbglLight.setPositionTransition(MGLOptionsFromTransition(self.positionTransiton));
-
+
+ mbglLight.setPositionTransition(MGLOptionsFromTransition(self.positionTransition));
+
auto color = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toInterpolatablePropertyValue(self.color);
mbglLight.setColor(color);
-
- mbglLight.setColorTransition(MGLOptionsFromTransition(self.colorTransiton));
-
+
+ mbglLight.setColorTransition(MGLOptionsFromTransition(self.colorTransition));
+
auto intensity = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(self.intensity);
mbglLight.setIntensity(intensity);
-
+
mbglLight.setIntensityTransition(MGLOptionsFromTransition(self.intensityTransition));
+
return mbglLight;
}
diff --git a/platform/darwin/src/MGLLight.mm.ejs b/platform/darwin/src/MGLLight.mm.ejs
new file mode 100644
index 0000000000..0d0da124c8
--- /dev/null
+++ b/platform/darwin/src/MGLLight.mm.ejs
@@ -0,0 +1,114 @@
+<%
+ const properties = locals.properties;
+-%>
+// This file is generated.
+// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
+// test
+
+#import "MGLLight.h"
+
+#import "MGLTypes.h"
+#import "NSDate+MGLAdditions.h"
+#import "MGLStyleValue_Private.h"
+#import "NSValue+MGLAdditions.h"
+
+#import <mbgl/style/light.hpp>
+#import <mbgl/style/types.hpp>
+
+namespace mbgl {
+
+ MBGL_DEFINE_ENUM(MGLLightAnchor, {
+<% for (const property of properties) { -%>
+<% if (property.type == "enum") { -%>
+<% for (const value in property.values) { -%>
+ { MGLLightAnchor<%- camelize(value) %>, "<%- value %>" },
+<% } -%>
+<% } -%>
+<% } -%>
+ });
+
+}
+
+NS_INLINE MGLTransition MGLTransitionFromOptions(const mbgl::style::TransitionOptions& options) {
+ MGLTransition transition;
+ transition.duration = MGLTimeIntervalFromDuration(options.duration.value_or(mbgl::Duration::zero()));
+ transition.delay = MGLTimeIntervalFromDuration(options.delay.value_or(mbgl::Duration::zero()));
+
+ return transition;
+}
+
+NS_INLINE mbgl::style::TransitionOptions MGLOptionsFromTransition(MGLTransition transition) {
+ mbgl::style::TransitionOptions options { { MGLDurationFromTimeInterval(transition.duration) }, { MGLDurationFromTimeInterval(transition.delay) } };
+ return options;
+}
+
+@interface MGLLight()
+
+@end
+
+@implementation MGLLight
+
+- (instancetype)initWithMBGLLight:(const mbgl::style::Light *)mbglLight
+{
+ if (self = [super init]) {
+<% if (properties.length) { -%>
+<% for (const property of properties) { -%>
+<% if (property.type == "enum") { -%>
+ auto <%- camelizeWithLeadingLowercase(property.name) -%> = mbglLight->get<%- camelize(property.name) -%>();
+ MGLStyleValue<NSValue *> *<%- camelizeWithLeadingLowercase(property.name) -%>StyleValue;
+ if (<%- camelizeWithLeadingLowercase(property.name) -%>.isUndefined()) {
+ mbgl::style::PropertyValue<mbgl::style::Light<%- camelize(property.name) -%>Type> default<%- camelize(property.name) -%> = mbglLight->getDefault<%- camelize(property.name) -%>();
+ <%- camelizeWithLeadingLowercase(property.name) -%>StyleValue = MGLStyleValueTransformer<mbgl::style::LightAnchorType, NSValue *, mbgl::style::Light<%- camelize(property.name) -%>Type, MGLLight<%- camelize(property.name) -%>>().toEnumStyleValue(default<%- camelize(property.name) -%>);
+ } else {
+ <%- camelizeWithLeadingLowercase(property.name) -%>StyleValue = MGLStyleValueTransformer<mbgl::style::Light<%- camelize(property.name) -%>Type, NSValue *, mbgl::style::Light<%- camelize(property.name) -%>Type, MGLLight<%- camelize(property.name) -%>>().toEnumStyleValue(<%- camelizeWithLeadingLowercase(property.name) -%>);
+ }
+
+ _<%- camelizeWithLeadingLowercase(property.name) -%> = <%- camelizeWithLeadingLowercase(property.name) -%>StyleValue;
+
+<% if (property.transition) { -%>
+ _<%- camelizeWithLeadingLowercase(property.name) -%>Transition = MGLTransitionFromOptions(mbglLight->get<%- camelize(property.name) -%>Transition());
+
+<% } -%>
+<% } else {-%>
+ auto <%- camelizeWithLeadingLowercase(property.name) -%>Value = mbglLight->get<%- camelize(property.name) -%>();
+ if (<%- camelizeWithLeadingLowercase(property.name) -%>Value.isUndefined()) {
+ _<%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(mbglLight->getDefault<%- camelize(property.name) -%>());
+ } else {
+ _<%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toStyleValue(<%- camelizeWithLeadingLowercase(property.name) -%>Value);
+ }
+<% if (property.transition) { -%>
+ _<%- camelizeWithLeadingLowercase(property.name) -%>Transition = MGLTransitionFromOptions(mbglLight->get<%- camelize(property.name) -%>Transition());
+<% } -%>
+<% } -%>
+<% } -%>
+<% } -%>
+ }
+
+ return self;
+}
+
+- (mbgl::style::Light)mbglLight
+{
+ mbgl::style::Light mbglLight;
+<% if (properties.length) { -%>
+<% for (const property of properties) { -%>
+<% if (property.type == "enum") { -%>
+ auto <%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<mbgl::style::Light<%- camelize(property.name) -%>Type, NSValue *, mbgl::style::Light<%- camelize(property.name) -%>Type, MGLLight<%- camelize(property.name) -%>>().toEnumPropertyValue(self.<%- camelizeWithLeadingLowercase(property.name) -%>);
+ mbglLight.set<%- camelize(property.name) -%>(<%- camelizeWithLeadingLowercase(property.name) -%>);
+
+<% } else {-%>
+ auto <%- camelizeWithLeadingLowercase(property.name) -%> = MGLStyleValueTransformer<<%- valueTransformerArguments(property).join(', ') %>>().toInterpolatablePropertyValue(self.<%- camelizeWithLeadingLowercase(property.name) -%>);
+ mbglLight.set<%- camelize(property.name) -%>(<%- camelizeWithLeadingLowercase(property.name) -%>);
+
+<% } -%>
+<% if (property.transition) { -%>
+ mbglLight.set<%- camelize(property.name) -%>Transition(MGLOptionsFromTransition(self.<%- camelizeWithLeadingLowercase(property.name) -%>Transition));
+
+<% } -%>
+<% } -%>
+<% } -%>
+
+ return mbglLight;
+}
+
+@end
diff --git a/platform/darwin/src/MGLMultiPoint.h b/platform/darwin/src/MGLMultiPoint.h
index 429bbdb22d..ee9eb530a4 100644
--- a/platform/darwin/src/MGLMultiPoint.h
+++ b/platform/darwin/src/MGLMultiPoint.h
@@ -10,8 +10,9 @@ NS_ASSUME_NONNULL_BEGIN
The `MGLMultiPoint` class is an abstract superclass used to define shapes
composed of multiple vertices.
- You do not create instances of this class directly. Instead, you create
- instances of the `MGLPolyline` or `MGLPolygon` classes. However, you can use
+ Create instances of `MGLPolyline` or `MGLPolygon` in order to use
+ properties of `MGLMultiPoint`. Do not create instances of `MGLMultiPoint`
+ directly and do not create your own subclasses of this class. You can use
the method and properties of this class to access information about the
vertices of the line or polygon.
diff --git a/platform/darwin/src/MGLOfflinePack.h b/platform/darwin/src/MGLOfflinePack.h
index 0b2db35b1a..dfc47bf1c8 100644
--- a/platform/darwin/src/MGLOfflinePack.h
+++ b/platform/darwin/src/MGLOfflinePack.h
@@ -54,7 +54,7 @@ typedef NS_ENUM (NSInteger, MGLOfflinePackState) {
A structure containing information about an offline pack’s current download
progress.
*/
-typedef struct MGLOfflinePackProgress {
+typedef struct __attribute__((objc_boxable)) MGLOfflinePackProgress {
/**
The number of resources, including tiles, that have been completely
downloaded and are ready to use offline.
diff --git a/platform/darwin/src/MGLShape.h b/platform/darwin/src/MGLShape.h
index bd8b6152d2..e965710552 100644
--- a/platform/darwin/src/MGLShape.h
+++ b/platform/darwin/src/MGLShape.h
@@ -10,11 +10,11 @@ NS_ASSUME_NONNULL_BEGIN
constitute the content of a map – not only the overlays atop the map, but also
the content that forms the base map.
- You do not create instances of this class directly or create subclasses of this
- class. Instead, you create instances of `MGLPointAnnotation`,
- `MGLPointCollection`, `MGLPolyline`, `MGLMultiPolyline`, `MGLPolygon`,
- `MGLMultiPolygon`, or `MGLShapeCollection`. The shape classes correspond to the
- <a href="https://tools.ietf.org/html/rfc7946#section-3.1">Geometry</a> object
+ Create instances of `MGLPointAnnotation`, `MGLPointCollection`, `MGLPolyline`,
+ `MGLMultiPolyline`, `MGLPolygon`, `MGLMultiPolygon`, or `MGLShapeCollection` in
+ order to use `MGLShape`'s methods. Do not create instances of `MGLShape` directly,
+ and do not create your own subclasses of this class. The shape classes correspond
+ to the <a href="https://tools.ietf.org/html/rfc7946#section-3.1">Geometry</a> object
types in the GeoJSON standard, but some have nonstandard names for backwards
compatibility.
diff --git a/platform/darwin/src/MGLSource.h b/platform/darwin/src/MGLSource.h
index f990aedd67..8d8c936833 100644
--- a/platform/darwin/src/MGLSource.h
+++ b/platform/darwin/src/MGLSource.h
@@ -16,10 +16,10 @@ NS_ASSUME_NONNULL_BEGIN
add and remove sources dynamically using methods such as
`-[MGLStyle addSource:]` and `-[MGLStyle sourceWithIdentifier:]`.
- Do not create instances of this class directly, and do not create your own
- subclasses of this class. Instead, create instances of `MGLShapeSource`,
- `MGLImageSource` and the concrete subclasses of `MGLTileSource`,
- `MGLVectorSource` and `MGLRasterSource`.
+ Create instances of `MGLShapeSource`, `MGLImageSource` and the concrete subclasses of
+ `MGLTileSource` (`MGLVectorSource` and `MGLRasterSource`) in order to use
+ `MGLSource`'s properties and methods. Do not create instances of `MGLSource`
+ directly, and do not create your own subclasses of this class.
*/
MGL_EXPORT
@interface MGLSource : NSObject
diff --git a/platform/darwin/src/MGLStyleLayer.h b/platform/darwin/src/MGLStyleLayer.h
index 7d181667d6..b610a27607 100644
--- a/platform/darwin/src/MGLStyleLayer.h
+++ b/platform/darwin/src/MGLStyleLayer.h
@@ -14,10 +14,10 @@ NS_ASSUME_NONNULL_BEGIN
`MGLStyleLayer` object, which you can use to refine the map’s appearance. You
can also add and remove style layers dynamically.
- Do not create instances of this class directly, and do not create your own
- subclasses of this class. Instead, create instances of
- `MGLBackgroundStyleLayer` and the concrete subclasses of
- `MGLForegroundStyleLayer`.
+ Create instances of `MGLBackgroundStyleLayer` and the concrete subclasses of
+ `MGLForegroundStyleLayer` in order to use `MGLStyleLayer`'s properties and methods.
+ You do not create instances of `MGLStyleLayer` directly, and do not
+ create your own subclasses of this class.
Do not add `MGLStyleLayer` objects to the `style` property of a `MGLMapView` before
`-mapView:didFinishLoadingStyle:` is called.
diff --git a/platform/darwin/src/MGLStyleValue.h b/platform/darwin/src/MGLStyleValue.h
index 2bb3aca4f4..9c9b1dc4d1 100644
--- a/platform/darwin/src/MGLStyleValue.h
+++ b/platform/darwin/src/MGLStyleValue.h
@@ -239,11 +239,10 @@ MGL_EXPORT
defined by an `MGLCameraStyleFunction`, `MGLSourceStyleFunction`, or
`MGLCompositeStyleFunction` object.
- Do not create instances of this class directly, and do not create your own
- subclasses of this class. Instead, use one of the class factory methods in
- `MGLStyleValue` to create instances of the following concrete subclasses:
- `MGLCameraStyleFunction`, `MGLSourceStyleFunction`, and
- `MGLCompositeStyleFunction`.
+ Create instances of `MGLCameraStyleFunction`, `MGLSourceStyleFunction`, and
+ `MGLCompositeStyleFunction` in order to use `MGLStyleFunction`'s methods. Do
+ not create instances of `MGLStyleFunction` directly, and do not create your
+ own subclasses of this class.
The `MGLStyleFunction` class takes a generic parameter `T` that indicates the
Foundation class being wrapped by this class.
diff --git a/platform/darwin/src/MGLTileSource.h b/platform/darwin/src/MGLTileSource.h
index 538b94037e..caeafcd2f6 100644
--- a/platform/darwin/src/MGLTileSource.h
+++ b/platform/darwin/src/MGLTileSource.h
@@ -140,9 +140,9 @@ typedef NS_ENUM(NSUInteger, MGLTileCoordinateSystem) {
Mapbox-hosted tile set, view it in
<a href="https://www.mapbox.com/studio/tilesets/">Mapbox Studio’s Tilesets editor</a>.
- Do not create instances of this class directly, and do not create your own
- subclasses of this class. Instead, create instances of `MGLRasterSource` and
- `MGLVectorSource`.
+ Create instances of `MGLRasterSource` and `MGLVectorSource` in order to use
+ `MGLTileSource`'s properties and methods. Do not create instances of `MGLTileSource`
+ directly, and do not create your own subclasses of this class.
*/
MGL_EXPORT
@interface MGLTileSource : MGLSource
diff --git a/platform/darwin/src/MGLTypes.h b/platform/darwin/src/MGLTypes.h
index 16f510b5a6..b3227e1cdf 100644
--- a/platform/darwin/src/MGLTypes.h
+++ b/platform/darwin/src/MGLTypes.h
@@ -78,7 +78,7 @@ typedef NS_OPTIONS(NSUInteger, MGLMapDebugMaskOptions) {
/**
A structure containing information about a transition.
*/
-typedef struct MGLTransition {
+typedef struct __attribute__((objc_boxable)) MGLTransition {
/**
The amount of time the animation should take, not including the delay.
*/
diff --git a/platform/darwin/src/MGLVectorStyleLayer.h b/platform/darwin/src/MGLVectorStyleLayer.h
index c6193e6046..6603570e25 100644
--- a/platform/darwin/src/MGLVectorStyleLayer.h
+++ b/platform/darwin/src/MGLVectorStyleLayer.h
@@ -9,10 +9,11 @@ NS_ASSUME_NONNULL_BEGIN
`MGLVectorStyleLayer` is an abstract superclass for style layers whose content
is defined by an `MGLShapeSource` or `MGLVectorSource` object.
- Do not create instances of this class directly, and do not create your own
- subclasses of this class. Instead, create instances of the following concrete
- subclasses: `MGLCircleStyleLayer`, `MGLFillStyleLayer`, `MGLLineStyleLayer`,
- and `MGLSymbolStyleLayer`.
+ Create instances of `MGLCircleStyleLayer`, `MGLFillStyleLayer`,
+ `MGLFillExtrusionStyleLayer`, `MGLLineStyleLayer`, and `MGLSymbolStyleLayer` in
+ order to use `MGLVectorStyleLayer`'s properties and methods. Do not create
+ instances of `MGLVectorStyleLayer` directly, and do not create your own
+ subclasses of this class.
*/
MGL_EXPORT
@interface MGLVectorStyleLayer : MGLForegroundStyleLayer
diff --git a/platform/darwin/test/MGLLightTest.mm b/platform/darwin/test/MGLLightTest.mm
index 2c3d1c7bd1..de64d57851 100644
--- a/platform/darwin/test/MGLLightTest.mm
+++ b/platform/darwin/test/MGLLightTest.mm
@@ -1,3 +1,5 @@
+// This file is generated.
+// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
#import <XCTest/XCTest.h>
#import <Mapbox/Mapbox.h>
@@ -16,197 +18,112 @@
@implementation MGLLightTest
- (void)testProperties {
-
+
MGLTransition defaultTransition = MGLTransitionMake(0, 0);
MGLTransition transition = MGLTransitionMake(6, 3);
mbgl::style::TransitionOptions transitionOptions { { MGLDurationFromTimeInterval(6) }, { MGLDurationFromTimeInterval(3) } };
-
+
// anchor
{
mbgl::style::Light light;
MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light];
-
- NSAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue.");
+ auto lightFromMGLlight = [mglLight mbglLight];
+
+ XCTAssertEqual(light.getDefaultAnchor(), lightFromMGLlight.getAnchor());
+ XCTAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue.");
NSValue *anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue;
XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorViewport);
- XCTAssertEqual(mglLight.anchorTransition.delay, defaultTransition.delay);
- XCTAssertEqual(mglLight.anchorTransition.duration, defaultTransition.duration);
-
- auto lightFromMGLlight = [mglLight mbglLight];
-
- XCTAssertEqual(light.getDefaultAnchor(), lightFromMGLlight.getAnchor().asConstant());
- auto anchorTransition = lightFromMGLlight.getAnchorTransition();
- XCTAssert(anchorTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == defaultTransition.delay);
- XCTAssert(anchorTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == defaultTransition.duration);
-
- MGLStyleValue<NSValue *> *anchorStyleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLLightAnchor:MGLLightAnchorMap]];
- mglLight.anchor = anchorStyleValue;
- mglLight.anchorTransition = transition;
- NSAssert([mglLight.anchor isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.anchor isn’t a MGLConstantStyleValue.");
- anchorValue = ((MGLConstantStyleValue *)mglLight.anchor).rawValue;
-
- XCTAssertEqual(anchorValue.MGLLightAnchorValue, MGLLightAnchorMap);
- XCTAssertEqual(mglLight.anchorTransition.delay, transition.delay);
- XCTAssertEqual(mglLight.anchorTransition.duration, transition.duration);
-
- mbgl::style::PropertyValue<mbgl::style::LightAnchorType> anchorProperty = { mbgl::style::LightAnchorType::Map };
- light.setAnchor(anchorProperty);
- light.setAnchorTransition(transitionOptions);
-
+
+ mbgl::style::PropertyValue<mbgl::style::LightAnchorType> propertyValue = { mbgl::style::LightAnchorType::Viewport };
+ light.setAnchor(propertyValue);
+ mglLight = [[MGLLight alloc] initWithMBGLLight:&light];
lightFromMGLlight = [mglLight mbglLight];
-
- XCTAssertEqual(light.getAnchor().asConstant(), lightFromMGLlight.getAnchor().asConstant());
- anchorTransition = lightFromMGLlight.getAnchorTransition();
- XCTAssert(anchorTransition.delay && MGLTimeIntervalFromDuration(*anchorTransition.delay) == transition.delay);
- XCTAssert(anchorTransition.duration && MGLTimeIntervalFromDuration(*anchorTransition.duration) == transition.duration);
-
+
+ XCTAssertEqual(light.getAnchor(), lightFromMGLlight.getAnchor());
}
-
+
// position
{
mbgl::style::Light light;
MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light];
- NSAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue.");
- NSValue *positionValue = ((MGLConstantStyleValue *)mglLight.position).rawValue;
- auto positionArray = light.getDefaultPosition().getSpherical();
- MGLSphericalPosition defaultPosition = MGLSphericalPositionMake(positionArray[0], positionArray[1], positionArray[2]);
-
- XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial);
- XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal);
- XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar);
- XCTAssertEqual(mglLight.positionTransiton.delay, defaultTransition.delay);
- XCTAssertEqual(mglLight.positionTransiton.duration, defaultTransition.duration);
-
auto lightFromMGLlight = [mglLight mbglLight];
-
- XCTAssertEqual(positionArray, lightFromMGLlight.getPosition().asConstant().getSpherical());
+
+ XCTAssertEqual(light.getDefaultPosition(), lightFromMGLlight.getPosition());
auto positionTransition = lightFromMGLlight.getPositionTransition();
XCTAssert(positionTransition.delay && MGLTimeIntervalFromDuration(*positionTransition.delay) == defaultTransition.delay);
XCTAssert(positionTransition.duration && MGLTimeIntervalFromDuration(*positionTransition.duration) == defaultTransition.duration);
-
- defaultPosition = MGLSphericalPositionMake(6, 180, 90);
- MGLStyleValue<NSValue *> *positionStyleValue = [MGLStyleValue<NSValue *> valueWithRawValue:[NSValue valueWithMGLSphericalPosition:defaultPosition]];
- mglLight.position = positionStyleValue;
- mglLight.positionTransiton = transition;
-
- NSAssert([mglLight.position isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.position isn’t a MGLConstantStyleValue.");
- positionValue = ((MGLConstantStyleValue *)mglLight.position).rawValue;
-
- XCTAssert(defaultPosition.radial == positionValue.MGLSphericalPositionValue.radial);
- XCTAssert(defaultPosition.azimuthal == positionValue.MGLSphericalPositionValue.azimuthal);
- XCTAssert(defaultPosition.polar == positionValue.MGLSphericalPositionValue.polar);
- XCTAssertEqual(mglLight.positionTransiton.delay, transition.delay);
- XCTAssertEqual(mglLight.positionTransiton.duration, transition.duration);
-
- lightFromMGLlight = [mglLight mbglLight];
-
- positionArray = { { 6, 180, 90 } };
+
+ std::array<float, 3> positionArray = { { 6, 180, 90 } };
mbgl::style::Position position = { positionArray };
- mbgl::style::PropertyValue<mbgl::style::Position> positionProperty = { position };
- light.setPosition(positionProperty);
+ mbgl::style::PropertyValue<mbgl::style::Position> propertyValue = { position };
+ light.setPosition(propertyValue);
light.setPositionTransition(transitionOptions);
- XCTAssertEqual(positionArray, lightFromMGLlight.getPosition().asConstant().getSpherical());
+ mglLight = [[MGLLight alloc] initWithMBGLLight:&light];
+ lightFromMGLlight = [mglLight mbglLight];
+
+ XCTAssertEqual(light.getPosition(), lightFromMGLlight.getPosition());
positionTransition = lightFromMGLlight.getPositionTransition();
XCTAssert(positionTransition.delay && MGLTimeIntervalFromDuration(*positionTransition.delay) == transition.delay);
XCTAssert(positionTransition.duration && MGLTimeIntervalFromDuration(*positionTransition.duration) == transition.duration);
}
-
+
// color
{
mbgl::style::Light light;
MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light];
- NSAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue.");
- MGLColor *colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue;
- auto color = light.getDefaultColor();
- const CGFloat *colorComponents = CGColorGetComponents(colorValue.CGColor);
-
- XCTAssert(color.r == colorComponents[0] && color.g == colorComponents[1] && color.b == colorComponents[2] &&
- color.a == colorComponents[3]);
- XCTAssertEqual(mglLight.colorTransiton.delay, defaultTransition.delay);
- XCTAssertEqual(mglLight.colorTransiton.duration, defaultTransition.duration);
-
auto lightFromMGLlight = [mglLight mbglLight];
-
- XCTAssertEqual(color, lightFromMGLlight.getColor().asConstant());
+
+ XCTAssertEqual(light.getDefaultColor(), lightFromMGLlight.getColor());
auto colorTransition = lightFromMGLlight.getColorTransition();
XCTAssert(colorTransition.delay && MGLTimeIntervalFromDuration(*colorTransition.delay) == defaultTransition.delay);
XCTAssert(colorTransition.duration && MGLTimeIntervalFromDuration(*colorTransition.duration) == defaultTransition.duration);
-
- MGLStyleValue<MGLColor *> *colorStyleValue = [MGLStyleValue<MGLColor *> valueWithRawValue:[MGLColor blackColor]];
- mglLight.color = colorStyleValue;
- mglLight.colorTransiton = transition;
-
- NSAssert([mglLight.color isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.color isn’t a MGLConstantStyleValue.");
- colorValue = ((MGLConstantStyleValue *)mglLight.color).rawValue;
-
- XCTAssertEqual([MGLColor blackColor], colorValue);
- XCTAssertEqual(mglLight.colorTransiton.delay, transition.delay);
- XCTAssertEqual(mglLight.colorTransiton.duration, transition.duration);
-
- mbgl::style::PropertyValue<mbgl::Color> colorProperty = { { 0, 0, 0, 1 } };
- light.setColor(colorProperty);
+
+ mbgl::style::PropertyValue<mbgl::Color> propertyValue = { { 1, 0, 0, 1 } };
+ light.setColor(propertyValue);
light.setColorTransition(transitionOptions);
-
+
+ mglLight = [[MGLLight alloc] initWithMBGLLight:&light];
lightFromMGLlight = [mglLight mbglLight];
-
- colorComponents = CGColorGetComponents(colorValue.CGColor);
- color = lightFromMGLlight.getColor().asConstant();
- XCTAssertEqual(light.getColor().asConstant(),lightFromMGLlight.getColor().asConstant());
+
+ XCTAssertEqual(light.getColor(), lightFromMGLlight.getColor());
colorTransition = lightFromMGLlight.getColorTransition();
XCTAssert(colorTransition.delay && MGLTimeIntervalFromDuration(*colorTransition.delay) == transition.delay);
XCTAssert(colorTransition.duration && MGLTimeIntervalFromDuration(*colorTransition.duration) == transition.duration);
+
}
-
+
// intensity
{
mbgl::style::Light light;
MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light];
- NSAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue.");
- NSNumber *intensityNumber = ((MGLConstantStyleValue *)mglLight.intensity).rawValue;
- auto intensity = light.getDefaultIntensity();
-
- XCTAssert(intensityNumber.floatValue == intensity);
- XCTAssertEqual(mglLight.intensityTransition.delay, defaultTransition.delay);
- XCTAssertEqual(mglLight.intensityTransition.duration, defaultTransition.duration);
-
auto lightFromMGLlight = [mglLight mbglLight];
-
- XCTAssertEqual(intensity, lightFromMGLlight.getIntensity().asConstant());
+
+ XCTAssertEqual(light.getDefaultIntensity(), lightFromMGLlight.getIntensity());
auto intensityTransition = lightFromMGLlight.getIntensityTransition();
XCTAssert(intensityTransition.delay && MGLTimeIntervalFromDuration(*intensityTransition.delay) == defaultTransition.delay);
XCTAssert(intensityTransition.duration && MGLTimeIntervalFromDuration(*intensityTransition.duration) == defaultTransition.duration);
-
- NSNumber *intensityValue = @0.4;
- MGLStyleValue<NSNumber *> *intensityStyleValue = [MGLStyleValue<NSNumber *> valueWithRawValue:intensityValue];
- mglLight.intensity = intensityStyleValue;
- mglLight.intensityTransition = transition;
-
- NSAssert([mglLight.intensity isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.intensity isn’t a MGLConstantStyleValue.");
- intensityNumber = ((MGLConstantStyleValue *)mglLight.intensity).rawValue;
- XCTAssert(intensityNumber.floatValue == intensityValue.floatValue);
- XCTAssertEqual(mglLight.intensityTransition.delay, transition.delay);
- XCTAssertEqual(mglLight.intensityTransition.duration, transition.duration);
-
- mbgl::style::PropertyValue<float> intensityProperty = { 0.4 };
- light.setIntensity(intensityProperty);
+
+ mbgl::style::PropertyValue<float> propertyValue = { 0xff };
+ light.setIntensity(propertyValue);
light.setIntensityTransition(transitionOptions);
+ mglLight = [[MGLLight alloc] initWithMBGLLight:&light];
lightFromMGLlight = [mglLight mbglLight];
-
- XCTAssertEqual(light.getIntensity().asConstant(), lightFromMGLlight.getIntensity().asConstant());
+
+ XCTAssertEqual(light.getIntensity(), lightFromMGLlight.getIntensity());
intensityTransition = lightFromMGLlight.getIntensityTransition();
XCTAssert(intensityTransition.delay && MGLTimeIntervalFromDuration(*intensityTransition.delay) == transition.delay);
XCTAssert(intensityTransition.duration && MGLTimeIntervalFromDuration(*intensityTransition.duration) == transition.duration);
-
+
}
}
- (void)testValueAdditions {
MGLSphericalPosition position = MGLSphericalPositionMake(1.15, 210, 30);
-
+
XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.radial, position.radial);
XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.azimuthal, position.azimuthal);
XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.polar, position.polar);
diff --git a/platform/darwin/test/MGLLightTest.mm.ejs b/platform/darwin/test/MGLLightTest.mm.ejs
new file mode 100644
index 0000000000..5b1f27d8d1
--- /dev/null
+++ b/platform/darwin/test/MGLLightTest.mm.ejs
@@ -0,0 +1,92 @@
+<%
+ const type = locals.type;
+ const properties = locals.properties;
+-%>
+// This file is generated.
+// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`.
+#import <XCTest/XCTest.h>
+#import <Mapbox/Mapbox.h>
+
+#import "MGLLight_Private.h"
+
+#import "../../darwin/src/NSDate+MGLAdditions.h"
+
+#import <mbgl/style/light.hpp>
+#import <mbgl/style/types.hpp>
+#include <mbgl/style/transition_options.hpp>
+
+@interface MGLLightTest : XCTestCase
+
+@end
+
+@implementation MGLLightTest
+
+- (void)testProperties {
+
+ MGLTransition defaultTransition = MGLTransitionMake(0, 0);
+ MGLTransition transition = MGLTransitionMake(6, 3);
+ mbgl::style::TransitionOptions transitionOptions { { MGLDurationFromTimeInterval(6) }, { MGLDurationFromTimeInterval(3) } };
+
+<% for (const property of properties) { -%>
+ // <%- property.name %>
+ {
+ mbgl::style::Light light;
+ MGLLight *mglLight = [[MGLLight alloc] initWithMBGLLight:&light];
+ auto lightFromMGLlight = [mglLight mbglLight];
+
+ XCTAssertEqual(light.getDefault<%- camelize(property.name) -%>(), lightFromMGLlight.get<%- camelize(property.name) -%>());
+<% if (property.transition) { -%>
+ auto <%- camelizeWithLeadingLowercase(property.name) -%>Transition = lightFromMGLlight.get<%- camelize(property.name) -%>Transition();
+ XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay && MGLTimeIntervalFromDuration(*<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay) == defaultTransition.delay);
+ XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration && MGLTimeIntervalFromDuration(*<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration) == defaultTransition.duration);
+
+<% } -%>
+<% if (property.type == "enum" && property.default) { -%>
+ XCTAssert([mglLight.<%- camelizeWithLeadingLowercase(property.name) -%> isKindOfClass:[MGLConstantStyleValue class]], @"mglLight.<%- camelizeWithLeadingLowercase(property.name) -%> isn’t a MGLConstantStyleValue.");
+ NSValue *<%- camelizeWithLeadingLowercase(property.name) -%>Value = ((MGLConstantStyleValue *)mglLight.<%- camelizeWithLeadingLowercase(property.name) -%>).rawValue;
+ XCTAssertEqual(<%- camelizeWithLeadingLowercase(property.name) -%>Value.MGLLight<%- camelize(property.name) -%>Value, MGLLight<%- camelize(property.name) -%><%- camelize(property.default) -%>);
+
+<% } -%>
+<% if (property.type == "array") { -%>
+ std::array<float, 3> positionArray = { { 6, 180, 90 } };
+ mbgl::style::Position position = { positionArray };
+ mbgl::style::PropertyValue<mbgl::style::Position> propertyValue = { position };
+<% } else { -%>
+ mbgl::style::PropertyValue<<%- mbglType(property) %>> propertyValue = { <%- mbglTestValue(property, type) %> };
+<% } -%>
+ light.set<%- camelize(property.name) -%>(propertyValue);
+<% if (property.transition) { -%>
+ light.set<%- camelize(property.name) -%>Transition(transitionOptions);
+
+<% } -%>
+ mglLight = [[MGLLight alloc] initWithMBGLLight:&light];
+ lightFromMGLlight = [mglLight mbglLight];
+
+ XCTAssertEqual(light.get<%- camelize(property.name) -%>(), lightFromMGLlight.get<%- camelize(property.name) -%>());
+<% if (property.transition) { -%>
+ <%- camelizeWithLeadingLowercase(property.name) -%>Transition = lightFromMGLlight.get<%- camelize(property.name) -%>Transition();
+ XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay && MGLTimeIntervalFromDuration(*<%- camelizeWithLeadingLowercase(property.name) -%>Transition.delay) == transition.delay);
+ XCTAssert(<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration && MGLTimeIntervalFromDuration(*<%- camelizeWithLeadingLowercase(property.name) -%>Transition.duration) == transition.duration);
+
+<% } -%>
+ }
+
+<% } -%>
+}
+
+- (void)testValueAdditions {
+ MGLSphericalPosition position = MGLSphericalPositionMake(1.15, 210, 30);
+
+ XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.radial, position.radial);
+ XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.azimuthal, position.azimuthal);
+ XCTAssertEqual([NSValue valueWithMGLSphericalPosition:position].MGLSphericalPositionValue.polar, position.polar);
+<% for (const property of properties) { -%>
+<% if (property.type == "enum") { -%>
+<% for (const value in property.values) { -%>
+ XCTAssertEqual([NSValue valueWithMGLLight<%- camelize(property.name) %>:MGLLight<%- camelize(property.name) %><%- camelize(value) %>].MGLLight<%- camelize(property.name) %>Value, MGLLight<%- camelize(property.name) %><%- camelize(value) %>);
+<% } -%>
+<% } -%>
+<% } -%>
+}
+
+@end