diff options
Diffstat (limited to 'platform/darwin/src')
-rw-r--r-- | platform/darwin/src/MGLHillshadeStyleLayer.h | 276 | ||||
-rw-r--r-- | platform/darwin/src/MGLHillshadeStyleLayer.mm | 286 |
2 files changed, 562 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLHillshadeStyleLayer.h b/platform/darwin/src/MGLHillshadeStyleLayer.h new file mode 100644 index 0000000000..0fe49d510d --- /dev/null +++ b/platform/darwin/src/MGLHillshadeStyleLayer.h @@ -0,0 +1,276 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. + +#import "MGLFoundation.h" +#import "MGLStyleValue.h" +#import "MGLVectorStyleLayer.h" + +NS_ASSUME_NONNULL_BEGIN + +/** + Direction of light source when map is rotated. + + Values of this type are used in the `MGLHillshadeStyleLayer.hillshadeIlluminationAnchor` + property. + */ +typedef NS_ENUM(NSUInteger, MGLHillshadeIlluminationAnchor) { + /** + The hillshade illumination is relative to the north direction. + */ + MGLHillshadeIlluminationAnchorMap, + /** + The hillshade illumination is relative to the top of the viewport. + */ + MGLHillshadeIlluminationAnchorViewport, +}; + +/** + Client-side hillshading visualization based on DEM data. Currently, the + implementation only supports Mapbox Terrain RGB tiles + + You can access an existing hillshade style layer using the + `-[MGLStyle layerWithIdentifier:]` method if you know its identifier; + otherwise, find it using the `MGLStyle.layers` property. You can also create a + new hillshade style layer and add it to the style using a method such as + `-[MGLStyle addLayer:]`. + + ### Example + + ```swift + ``` + */ +MGL_EXPORT +@interface MGLHillshadeStyleLayer : MGLVectorStyleLayer + +/** + Returns a hillshade style layer initialized with an identifier and source. + + After initializing and configuring the style layer, add it to a map view’s + style using the `-[MGLStyle addLayer:]` or + `-[MGLStyle insertLayer:belowLayer:]` method. + + @param identifier A string that uniquely identifies the source in the style to + which it is added. + @param source The source from which to obtain the data to style. If the source + has not yet been added to the current style, the behavior is undefined. + @return An initialized foreground style layer. + */ +- (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source; + +#pragma mark - Accessing the Paint Attributes + +#if TARGET_OS_IPHONE +/** + The shading color used to accentuate rugged terrain like sharp cliffs and + gorges. + + The default value of this property is an `MGLStyleValue` object containing + `UIColor.blackColor`. Set this property to `nil` to reset it to the default + value. + + You can set this property to an instance of: + + * `MGLConstantStyleValue` + * `MGLCameraStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + */ +@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *hillshadeAccentColor; +#else +/** + The shading color used to accentuate rugged terrain like sharp cliffs and + gorges. + + The default value of this property is an `MGLStyleValue` object containing + `NSColor.blackColor`. Set this property to `nil` to reset it to the default + value. + + You can set this property to an instance of: + + * `MGLConstantStyleValue` + * `MGLCameraStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + */ +@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *hillshadeAccentColor; +#endif + +/** + The transition affecting any changes to this layer’s `hillshadeAccentColor` property. + + This property corresponds to the `hillshade-accent-color-transition` property in the style JSON file format. +*/ +@property (nonatomic) MGLTransition hillshadeAccentColorTransition; + +/** + Intensity of the hillshade + + The default value of this property is an `MGLStyleValue` object containing an + `NSNumber` object containing the float `0.5`. Set this property to `nil` to + reset it to the default value. + + You can set this property to an instance of: + + * `MGLConstantStyleValue` + * `MGLCameraStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + */ +@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *hillshadeExaggeration; + +/** + The transition affecting any changes to this layer’s `hillshadeExaggeration` property. + + This property corresponds to the `hillshade-exaggeration-transition` property in the style JSON file format. +*/ +@property (nonatomic) MGLTransition hillshadeExaggerationTransition; + +#if TARGET_OS_IPHONE +/** + The shading color of areas that faces towards the light source. + + The default value of this property is an `MGLStyleValue` object containing + `UIColor.whiteColor`. Set this property to `nil` to reset it to the default + value. + + You can set this property to an instance of: + + * `MGLConstantStyleValue` + * `MGLCameraStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + */ +@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *hillshadeHighlightColor; +#else +/** + The shading color of areas that faces towards the light source. + + The default value of this property is an `MGLStyleValue` object containing + `NSColor.whiteColor`. Set this property to `nil` to reset it to the default + value. + + You can set this property to an instance of: + + * `MGLConstantStyleValue` + * `MGLCameraStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + */ +@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *hillshadeHighlightColor; +#endif + +/** + The transition affecting any changes to this layer’s `hillshadeHighlightColor` property. + + This property corresponds to the `hillshade-highlight-color-transition` property in the style JSON file format. +*/ +@property (nonatomic) MGLTransition hillshadeHighlightColorTransition; + +/** + Direction of light source when map is rotated. + + The default value of this property is an `MGLStyleValue` object containing an + `NSValue` object containing `MGLHillshadeIlluminationAnchorViewport`. Set this + property to `nil` to reset it to the default value. + + You can set this property to an instance of: + + * `MGLConstantStyleValue` + * `MGLCameraStyleFunction` with an interpolation mode of + `MGLInterpolationModeInterval` + */ +@property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *hillshadeIlluminationAnchor; + +/** + The direction of the light source used to generate the hillshading with 0 as + the top of the viewport if `hillshadeIlluminationAnchor` is set to + `MGLHillshadeIlluminationAnchorViewport` and due north if + `hillshadeIlluminationAnchor` is set to `MGLHillshadeIlluminationAnchorMap`. + + The default value of this property is an `MGLStyleValue` object containing an + `NSNumber` object containing the float `335`. Set this property to `nil` to + reset it to the default value. + + You can set this property to an instance of: + + * `MGLConstantStyleValue` + * `MGLCameraStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + */ +@property (nonatomic, null_resettable) MGLStyleValue<NSNumber *> *hillshadeIlluminationDirection; + +/** + The transition affecting any changes to this layer’s `hillshadeIlluminationDirection` property. + + This property corresponds to the `hillshade-illumination-direction-transition` property in the style JSON file format. +*/ +@property (nonatomic) MGLTransition hillshadeIlluminationDirectionTransition; + +#if TARGET_OS_IPHONE +/** + The shading color of areas that face away from the light source. + + The default value of this property is an `MGLStyleValue` object containing + `UIColor.blackColor`. Set this property to `nil` to reset it to the default + value. + + You can set this property to an instance of: + + * `MGLConstantStyleValue` + * `MGLCameraStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + */ +@property (nonatomic, null_resettable) MGLStyleValue<UIColor *> *hillshadeShadowColor; +#else +/** + The shading color of areas that face away from the light source. + + The default value of this property is an `MGLStyleValue` object containing + `NSColor.blackColor`. Set this property to `nil` to reset it to the default + value. + + You can set this property to an instance of: + + * `MGLConstantStyleValue` + * `MGLCameraStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + */ +@property (nonatomic, null_resettable) MGLStyleValue<NSColor *> *hillshadeShadowColor; +#endif + +/** + The transition affecting any changes to this layer’s `hillshadeShadowColor` property. + + This property corresponds to the `hillshade-shadow-color-transition` property in the style JSON file format. +*/ +@property (nonatomic) MGLTransition hillshadeShadowColorTransition; + +@end + +/** + Methods for wrapping an enumeration value for a style layer attribute in an + `MGLHillshadeStyleLayer` object and unwrapping its raw value. + */ +@interface NSValue (MGLHillshadeStyleLayerAdditions) + +#pragma mark Working with Hillshade Style Layer Attribute Values + +/** + Creates a new value object containing the given `MGLHillshadeIlluminationAnchor` enumeration. + + @param hillshadeIlluminationAnchor The value for the new object. + @return A new value object that contains the enumeration value. + */ ++ (instancetype)valueWithMGLHillshadeIlluminationAnchor:(MGLHillshadeIlluminationAnchor)hillshadeIlluminationAnchor; + +/** + The `MGLHillshadeIlluminationAnchor` enumeration representation of the value. + */ +@property (readonly) MGLHillshadeIlluminationAnchor MGLHillshadeIlluminationAnchorValue; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLHillshadeStyleLayer.mm b/platform/darwin/src/MGLHillshadeStyleLayer.mm new file mode 100644 index 0000000000..3225feb587 --- /dev/null +++ b/platform/darwin/src/MGLHillshadeStyleLayer.mm @@ -0,0 +1,286 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. + +#import "MGLSource.h" +#import "NSPredicate+MGLAdditions.h" +#import "NSDate+MGLAdditions.h" +#import "MGLStyleLayer_Private.h" +#import "MGLStyleValue_Private.h" +#import "MGLHillshadeStyleLayer.h" + +#include <mbgl/style/transition_options.hpp> +#include <mbgl/style/layers/hillshade_layer.hpp> + +namespace mbgl { + + MBGL_DEFINE_ENUM(MGLHillshadeIlluminationAnchor, { + { MGLHillshadeIlluminationAnchorMap, "map" }, + { MGLHillshadeIlluminationAnchorViewport, "viewport" }, + }); + +} + +@interface MGLHillshadeStyleLayer () + +@property (nonatomic, readonly) mbgl::style::HillshadeLayer *rawLayer; + +@end + +@implementation MGLHillshadeStyleLayer + +- (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)source +{ + auto layer = std::make_unique<mbgl::style::HillshadeLayer>(identifier.UTF8String, source.identifier.UTF8String); + return self = [super initWithPendingLayer:std::move(layer)]; +} + +- (mbgl::style::HillshadeLayer *)rawLayer +{ + return (mbgl::style::HillshadeLayer *)super.rawLayer; +} + +- (NSString *)sourceIdentifier +{ + MGLAssertStyleLayerIsValid(); + + return @(self.rawLayer->getSourceID().c_str()); +} + +- (NSString *)sourceLayerIdentifier +{ + MGLAssertStyleLayerIsValid(); + + auto layerID = self.rawLayer->getSourceLayer(); + return layerID.empty() ? nil : @(layerID.c_str()); +} + +- (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier +{ + MGLAssertStyleLayerIsValid(); + + self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); +} + +- (void)setPredicate:(NSPredicate *)predicate +{ + MGLAssertStyleLayerIsValid(); + + self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter()); +} + +- (NSPredicate *)predicate +{ + MGLAssertStyleLayerIsValid(); + + return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; +} + +#pragma mark - Accessing the Paint Attributes + +- (void)setHillshadeAccentColor:(MGLStyleValue<MGLColor *> *)hillshadeAccentColor { + MGLAssertStyleLayerIsValid(); + + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toInterpolatablePropertyValue(hillshadeAccentColor); + self.rawLayer->setHillshadeAccentColor(mbglValue); +} + +- (MGLStyleValue<MGLColor *> *)hillshadeAccentColor { + MGLAssertStyleLayerIsValid(); + + auto propertyValue = self.rawLayer->getHillshadeAccentColor(); + if (propertyValue.isUndefined()) { + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(self.rawLayer->getDefaultHillshadeAccentColor()); + } + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); +} + +- (void)setHillshadeAccentColorTransition:(MGLTransition )transition { + MGLAssertStyleLayerIsValid(); + + mbgl::style::TransitionOptions options { { MGLDurationFromTimeInterval(transition.duration) }, { MGLDurationFromTimeInterval(transition.delay) } }; + self.rawLayer->setHillshadeAccentColorTransition(options); +} + +- (MGLTransition)hillshadeAccentColorTransition { + MGLAssertStyleLayerIsValid(); + + mbgl::style::TransitionOptions transitionOptions = self.rawLayer->getHillshadeAccentColorTransition(); + MGLTransition transition; + transition.duration = MGLTimeIntervalFromDuration(transitionOptions.duration.value_or(mbgl::Duration::zero())); + transition.delay = MGLTimeIntervalFromDuration(transitionOptions.delay.value_or(mbgl::Duration::zero())); + + return transition; +} + +- (void)setHillshadeExaggeration:(MGLStyleValue<NSNumber *> *)hillshadeExaggeration { + MGLAssertStyleLayerIsValid(); + + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(hillshadeExaggeration); + self.rawLayer->setHillshadeExaggeration(mbglValue); +} + +- (MGLStyleValue<NSNumber *> *)hillshadeExaggeration { + MGLAssertStyleLayerIsValid(); + + auto propertyValue = self.rawLayer->getHillshadeExaggeration(); + if (propertyValue.isUndefined()) { + return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultHillshadeExaggeration()); + } + return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); +} + +- (void)setHillshadeExaggerationTransition:(MGLTransition )transition { + MGLAssertStyleLayerIsValid(); + + mbgl::style::TransitionOptions options { { MGLDurationFromTimeInterval(transition.duration) }, { MGLDurationFromTimeInterval(transition.delay) } }; + self.rawLayer->setHillshadeExaggerationTransition(options); +} + +- (MGLTransition)hillshadeExaggerationTransition { + MGLAssertStyleLayerIsValid(); + + mbgl::style::TransitionOptions transitionOptions = self.rawLayer->getHillshadeExaggerationTransition(); + MGLTransition transition; + transition.duration = MGLTimeIntervalFromDuration(transitionOptions.duration.value_or(mbgl::Duration::zero())); + transition.delay = MGLTimeIntervalFromDuration(transitionOptions.delay.value_or(mbgl::Duration::zero())); + + return transition; +} + +- (void)setHillshadeHighlightColor:(MGLStyleValue<MGLColor *> *)hillshadeHighlightColor { + MGLAssertStyleLayerIsValid(); + + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toInterpolatablePropertyValue(hillshadeHighlightColor); + self.rawLayer->setHillshadeHighlightColor(mbglValue); +} + +- (MGLStyleValue<MGLColor *> *)hillshadeHighlightColor { + MGLAssertStyleLayerIsValid(); + + auto propertyValue = self.rawLayer->getHillshadeHighlightColor(); + if (propertyValue.isUndefined()) { + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(self.rawLayer->getDefaultHillshadeHighlightColor()); + } + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); +} + +- (void)setHillshadeHighlightColorTransition:(MGLTransition )transition { + MGLAssertStyleLayerIsValid(); + + mbgl::style::TransitionOptions options { { MGLDurationFromTimeInterval(transition.duration) }, { MGLDurationFromTimeInterval(transition.delay) } }; + self.rawLayer->setHillshadeHighlightColorTransition(options); +} + +- (MGLTransition)hillshadeHighlightColorTransition { + MGLAssertStyleLayerIsValid(); + + mbgl::style::TransitionOptions transitionOptions = self.rawLayer->getHillshadeHighlightColorTransition(); + MGLTransition transition; + transition.duration = MGLTimeIntervalFromDuration(transitionOptions.duration.value_or(mbgl::Duration::zero())); + transition.delay = MGLTimeIntervalFromDuration(transitionOptions.delay.value_or(mbgl::Duration::zero())); + + return transition; +} + +- (void)setHillshadeIlluminationAnchor:(MGLStyleValue<NSValue *> *)hillshadeIlluminationAnchor { + MGLAssertStyleLayerIsValid(); + + auto mbglValue = MGLStyleValueTransformer<mbgl::style::HillshadeIlluminationAnchorType, NSValue *, mbgl::style::HillshadeIlluminationAnchorType, MGLHillshadeIlluminationAnchor>().toEnumPropertyValue(hillshadeIlluminationAnchor); + self.rawLayer->setHillshadeIlluminationAnchor(mbglValue); +} + +- (MGLStyleValue<NSValue *> *)hillshadeIlluminationAnchor { + MGLAssertStyleLayerIsValid(); + + auto propertyValue = self.rawLayer->getHillshadeIlluminationAnchor(); + if (propertyValue.isUndefined()) { + return MGLStyleValueTransformer<mbgl::style::HillshadeIlluminationAnchorType, NSValue *, mbgl::style::HillshadeIlluminationAnchorType, MGLHillshadeIlluminationAnchor>().toEnumStyleValue(self.rawLayer->getDefaultHillshadeIlluminationAnchor()); + } + return MGLStyleValueTransformer<mbgl::style::HillshadeIlluminationAnchorType, NSValue *, mbgl::style::HillshadeIlluminationAnchorType, MGLHillshadeIlluminationAnchor>().toEnumStyleValue(propertyValue); +} + +- (void)setHillshadeIlluminationDirection:(MGLStyleValue<NSNumber *> *)hillshadeIlluminationDirection { + MGLAssertStyleLayerIsValid(); + + auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toInterpolatablePropertyValue(hillshadeIlluminationDirection); + self.rawLayer->setHillshadeIlluminationDirection(mbglValue); +} + +- (MGLStyleValue<NSNumber *> *)hillshadeIlluminationDirection { + MGLAssertStyleLayerIsValid(); + + auto propertyValue = self.rawLayer->getHillshadeIlluminationDirection(); + if (propertyValue.isUndefined()) { + return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(self.rawLayer->getDefaultHillshadeIlluminationDirection()); + } + return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); +} + +- (void)setHillshadeIlluminationDirectionTransition:(MGLTransition )transition { + MGLAssertStyleLayerIsValid(); + + mbgl::style::TransitionOptions options { { MGLDurationFromTimeInterval(transition.duration) }, { MGLDurationFromTimeInterval(transition.delay) } }; + self.rawLayer->setHillshadeIlluminationDirectionTransition(options); +} + +- (MGLTransition)hillshadeIlluminationDirectionTransition { + MGLAssertStyleLayerIsValid(); + + mbgl::style::TransitionOptions transitionOptions = self.rawLayer->getHillshadeIlluminationDirectionTransition(); + MGLTransition transition; + transition.duration = MGLTimeIntervalFromDuration(transitionOptions.duration.value_or(mbgl::Duration::zero())); + transition.delay = MGLTimeIntervalFromDuration(transitionOptions.delay.value_or(mbgl::Duration::zero())); + + return transition; +} + +- (void)setHillshadeShadowColor:(MGLStyleValue<MGLColor *> *)hillshadeShadowColor { + MGLAssertStyleLayerIsValid(); + + auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toInterpolatablePropertyValue(hillshadeShadowColor); + self.rawLayer->setHillshadeShadowColor(mbglValue); +} + +- (MGLStyleValue<MGLColor *> *)hillshadeShadowColor { + MGLAssertStyleLayerIsValid(); + + auto propertyValue = self.rawLayer->getHillshadeShadowColor(); + if (propertyValue.isUndefined()) { + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(self.rawLayer->getDefaultHillshadeShadowColor()); + } + return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); +} + +- (void)setHillshadeShadowColorTransition:(MGLTransition )transition { + MGLAssertStyleLayerIsValid(); + + mbgl::style::TransitionOptions options { { MGLDurationFromTimeInterval(transition.duration) }, { MGLDurationFromTimeInterval(transition.delay) } }; + self.rawLayer->setHillshadeShadowColorTransition(options); +} + +- (MGLTransition)hillshadeShadowColorTransition { + MGLAssertStyleLayerIsValid(); + + mbgl::style::TransitionOptions transitionOptions = self.rawLayer->getHillshadeShadowColorTransition(); + MGLTransition transition; + transition.duration = MGLTimeIntervalFromDuration(transitionOptions.duration.value_or(mbgl::Duration::zero())); + transition.delay = MGLTimeIntervalFromDuration(transitionOptions.delay.value_or(mbgl::Duration::zero())); + + return transition; +} + +@end + +@implementation NSValue (MGLHillshadeStyleLayerAdditions) + ++ (NSValue *)valueWithMGLHillshadeIlluminationAnchor:(MGLHillshadeIlluminationAnchor)hillshadeIlluminationAnchor { + return [NSValue value:&hillshadeIlluminationAnchor withObjCType:@encode(MGLHillshadeIlluminationAnchor)]; +} + +- (MGLHillshadeIlluminationAnchor)MGLHillshadeIlluminationAnchorValue { + MGLHillshadeIlluminationAnchor hillshadeIlluminationAnchor; + [self getValue:&hillshadeIlluminationAnchor]; + return hillshadeIlluminationAnchor; +} + +@end |