summaryrefslogtreecommitdiff
path: root/platform/darwin/src
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src')
-rw-r--r--platform/darwin/src/MGLRasterStyleLayer.h78
-rw-r--r--platform/darwin/src/MGLRasterStyleLayer.mm47
2 files changed, 125 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLRasterStyleLayer.h b/platform/darwin/src/MGLRasterStyleLayer.h
index ff055d24f6..a74d4f7f26 100644
--- a/platform/darwin/src/MGLRasterStyleLayer.h
+++ b/platform/darwin/src/MGLRasterStyleLayer.h
@@ -7,6 +7,27 @@
NS_ASSUME_NONNULL_BEGIN
/**
+ The resampling/interpolation method to use for overscaling, also known as
+ texture magnification filter
+
+ Values of this type are used in the `MGLRasterStyleLayer.rasterResamplingMode`
+ property.
+ */
+typedef NS_ENUM(NSUInteger, MGLRasterResamplingMode) {
+ /**
+ (Bi)linear filtering interpolates point values using the weighted average
+ of the four closest original source points creating a smooth but blurry
+ look when overscaled
+ */
+ MGLRasterResamplingModeLinear,
+ /**
+ Nearest neighbor filtering interpolates point values using the nearest
+ original source point creating a sharp but pointated look when overscaled
+ */
+ MGLRasterResamplingModeNearest,
+};
+
+/**
An `MGLRasterStyleLayer` is a style layer that renders georeferenced raster
imagery on the map, especially raster tiles.
@@ -233,6 +254,40 @@ MGL_EXPORT
@property (nonatomic) MGLTransition rasterOpacityTransition;
/**
+ The resampling/interpolation method to use for overscaling, also known as
+ texture magnification filter
+
+ The default value of this property is an expression that evaluates to `linear`.
+ Set this property to `nil` to reset it to the default value.
+
+ This attribute corresponds to the <a
+ href="https://www.mapbox.com/mapbox-gl-style-spec/#paint-raster-resampling"><code>raster-resampling</code></a>
+ layout property in the Mapbox Style Specification.
+
+ You can set this property to an expression containing any of the following:
+
+ * Constant `MGLRasterResamplingMode` values
+ * Any of the following constant string values:
+ * `linear`: (Bi)linear filtering interpolates pixel values using the weighted
+ average of the four closest original source pixels creating a smooth but blurry
+ look when overscaled
+ * `nearest`: Nearest neighbor filtering interpolates pixel values using the
+ nearest original source pixel creating a sharp but pixelated look when
+ overscaled
+ * Predefined functions, including mathematical and string operators
+ * Conditional expressions
+ * Variable assignments and references to assigned variables
+ * Step functions applied to the `$zoomLevel` variable
+
+ This property does not support applying interpolation functions to the
+ `$zoomLevel` variable or applying interpolation or step functions to feature
+ attributes.
+ */
+@property (nonatomic, null_resettable) NSExpression *rasterResamplingMode;
+
+@property (nonatomic, null_resettable) NSExpression *rasterResampling __attribute__((unavailable("Use rasterResamplingMode instead.")));
+
+/**
Increase or reduce the saturation of the image.
The default value of this property is an expression that evaluates to the float
@@ -260,4 +315,27 @@ MGL_EXPORT
@end
+/**
+ Methods for wrapping an enumeration value for a style layer attribute in an
+ `MGLRasterStyleLayer` object and unwrapping its raw value.
+ */
+@interface NSValue (MGLRasterStyleLayerAdditions)
+
+#pragma mark Working with Raster Style Layer Attribute Values
+
+/**
+ Creates a new value object containing the given `MGLRasterResamplingMode` enumeration.
+
+ @param rasterResamplingMode The value for the new object.
+ @return A new value object that contains the enumeration value.
+ */
++ (instancetype)valueWithMGLRasterResamplingMode:(MGLRasterResamplingMode)rasterResamplingMode;
+
+/**
+ The `MGLRasterResamplingMode` enumeration representation of the value.
+ */
+@property (readonly) MGLRasterResamplingMode MGLRasterResamplingModeValue;
+
+@end
+
NS_ASSUME_NONNULL_END
diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm
index 0e31512491..96ed5ab513 100644
--- a/platform/darwin/src/MGLRasterStyleLayer.mm
+++ b/platform/darwin/src/MGLRasterStyleLayer.mm
@@ -11,6 +11,15 @@
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/layers/raster_layer.hpp>
+namespace mbgl {
+
+ MBGL_DEFINE_ENUM(MGLRasterResamplingMode, {
+ { MGLRasterResamplingModeLinear, "linear" },
+ { MGLRasterResamplingModeNearest, "nearest" },
+ });
+
+}
+
@interface MGLRasterStyleLayer ()
@property (nonatomic, readonly) mbgl::style::RasterLayer *rawLayer;
@@ -252,6 +261,30 @@
return transition;
}
+- (void)setRasterResamplingMode:(NSExpression *)rasterResamplingMode {
+ MGLAssertStyleLayerIsValid();
+
+ auto mbglValue = MGLStyleValueTransformer<mbgl::style::RasterResamplingType, NSValue *, mbgl::style::RasterResamplingType, MGLRasterResamplingMode>().toPropertyValue<mbgl::style::PropertyValue<mbgl::style::RasterResamplingType>>(rasterResamplingMode);
+ self.rawLayer->setRasterResampling(mbglValue);
+}
+
+- (NSExpression *)rasterResamplingMode {
+ MGLAssertStyleLayerIsValid();
+
+ auto propertyValue = self.rawLayer->getRasterResampling();
+ if (propertyValue.isUndefined()) {
+ propertyValue = self.rawLayer->getDefaultRasterResampling();
+ }
+ return MGLStyleValueTransformer<mbgl::style::RasterResamplingType, NSValue *, mbgl::style::RasterResamplingType, MGLRasterResamplingMode>().toExpression(propertyValue);
+}
+
+- (void)setRasterResampling:(NSExpression *)rasterResampling {
+}
+
+- (NSExpression *)rasterResampling {
+ return self.rasterResamplingMode;
+}
+
- (void)setRasterSaturation:(NSExpression *)rasterSaturation {
MGLAssertStyleLayerIsValid();
@@ -288,3 +321,17 @@
}
@end
+
+@implementation NSValue (MGLRasterStyleLayerAdditions)
+
++ (NSValue *)valueWithMGLRasterResamplingMode:(MGLRasterResamplingMode)rasterResamplingMode {
+ return [NSValue value:&rasterResamplingMode withObjCType:@encode(MGLRasterResamplingMode)];
+}
+
+- (MGLRasterResamplingMode)MGLRasterResamplingModeValue {
+ MGLRasterResamplingMode rasterResamplingMode;
+ [self getValue:&rasterResamplingMode];
+ return rasterResamplingMode;
+}
+
+@end