summaryrefslogtreecommitdiff
path: root/platform/darwin/src
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src')
-rw-r--r--platform/darwin/src/MGLLight.h118
-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
4 files changed, 328 insertions, 45 deletions
diff --git a/platform/darwin/src/MGLLight.h b/platform/darwin/src/MGLLight.h
index 6dd24712e2..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,
};
/**
@@ -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