summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMolly Lloyd <mollymerp@users.noreply.github.com>2018-06-21 14:37:17 -0700
committerGitHub <noreply@github.com>2018-06-21 14:37:17 -0700
commite1af62e87dfd77d1c38802f082c4981dab1beeab (patch)
tree8371dccdcf8545fd50b2edddbdd3a622bb00b27a
parenteb70b8984901d8113f3a29d26cc355d5b3ed46fd (diff)
downloadqtlocation-mapboxgl-e1af62e87dfd77d1c38802f082c4981dab1beeab.tar.gz
[core] add raster-resampling property (#12176)upstream/rclee
* update style-code for raster-resampling * implement user-defined raster-resampling * invert filter condition * raster-resampling -> raster-resampling-mode for darwin language conventions
-rw-r--r--include/mbgl/style/layers/raster_layer.hpp6
-rw-r--r--include/mbgl/style/types.hpp5
m---------mapbox-gl-js0
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java21
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java20
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java13
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java14
-rw-r--r--platform/android/src/style/conversion/types.hpp7
-rw-r--r--platform/android/src/style/conversion/types_string_values.hpp14
-rw-r--r--platform/android/src/style/layers/raster_layer.cpp7
-rw-r--r--platform/android/src/style/layers/raster_layer.hpp2
-rw-r--r--platform/darwin/scripts/style-spec-cocoa-conventions-v8.json3
-rw-r--r--platform/darwin/src/MGLRasterStyleLayer.h78
-rw-r--r--platform/darwin/src/MGLRasterStyleLayer.mm47
-rw-r--r--platform/darwin/test/MGLRasterStyleLayerTests.mm49
-rw-r--r--platform/ios/docs/guides/For Style Authors.md1
-rw-r--r--platform/macos/docs/guides/For Style Authors.md1
-rw-r--r--platform/node/test/ignores.json4
-rw-r--r--src/mbgl/renderer/layers/render_raster_layer.cpp10
-rw-r--r--src/mbgl/style/conversion/make_property_setters.hpp2
-rw-r--r--src/mbgl/style/expression/value.cpp4
-rw-r--r--src/mbgl/style/layers/raster_layer.cpp27
-rw-r--r--src/mbgl/style/layers/raster_layer_properties.hpp5
-rw-r--r--src/mbgl/style/types.cpp5
24 files changed, 340 insertions, 5 deletions
diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp
index 8111364709..8e7849c27d 100644
--- a/include/mbgl/style/layers/raster_layer.hpp
+++ b/include/mbgl/style/layers/raster_layer.hpp
@@ -67,6 +67,12 @@ public:
void setRasterContrastTransition(const TransitionOptions&);
TransitionOptions getRasterContrastTransition() const;
+ static PropertyValue<RasterResamplingType> getDefaultRasterResampling();
+ PropertyValue<RasterResamplingType> getRasterResampling() const;
+ void setRasterResampling(PropertyValue<RasterResamplingType>);
+ void setRasterResamplingTransition(const TransitionOptions&);
+ TransitionOptions getRasterResamplingTransition() const;
+
static PropertyValue<float> getDefaultRasterFadeDuration();
PropertyValue<float> getRasterFadeDuration() const;
void setRasterFadeDuration(PropertyValue<float>);
diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp
index 693972a72f..44c11186b8 100644
--- a/include/mbgl/style/types.hpp
+++ b/include/mbgl/style/types.hpp
@@ -38,6 +38,11 @@ enum class LineJoinType : uint8_t {
FlipBevel
};
+enum class RasterResamplingType : bool {
+ Linear,
+ Nearest
+};
+
enum class HillshadeIlluminationAnchorType : bool {
Map,
Viewport
diff --git a/mapbox-gl-js b/mapbox-gl-js
-Subproject 45b0be007cd5df6837e5381e067b9c2a42b7850
+Subproject f546de26b9b531a84fe621a5f51f4c0f791e57f
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java
index e52474c35b..c264d773c5 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java
@@ -570,6 +570,27 @@ public final class Property {
@Retention(RetentionPolicy.SOURCE)
public @interface FILL_EXTRUSION_TRANSLATE_ANCHOR {}
+ // RASTER_RESAMPLING: The resampling/interpolation method to use for overscaling, also known as texture magnification filter
+
+ /**
+ * (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
+ */
+ public static final String RASTER_RESAMPLING_LINEAR = "linear";
+ /**
+ * Nearest neighbor filtering interpolates pixel values using the nearest original source pixel creating a sharp but pixelated look when overscaled
+ */
+ public static final String RASTER_RESAMPLING_NEAREST = "nearest";
+
+ /**
+ * The resampling/interpolation method to use for overscaling, also known as texture magnification filter
+ */
+ @StringDef({
+ RASTER_RESAMPLING_LINEAR,
+ RASTER_RESAMPLING_NEAREST,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface RASTER_RESAMPLING {}
+
// HILLSHADE_ILLUMINATION_ANCHOR: Direction of light source when map is rotated.
/**
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
index 57638920be..5338fb84f6 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
@@ -1336,6 +1336,26 @@ public class PropertyFactory {
}
/**
+ * The resampling/interpolation method to use for overscaling, also known as texture magnification filter
+ *
+ * @param value a String value
+ * @return property wrapper around String
+ */
+ public static PropertyValue<String> rasterResampling(@Property.RASTER_RESAMPLING String value) {
+ return new PaintPropertyValue<>("raster-resampling", value);
+ }
+
+ /**
+ * The resampling/interpolation method to use for overscaling, also known as texture magnification filter
+ *
+ * @param expression an expression statement
+ * @return property wrapper around an expression statement
+ */
+ public static PropertyValue<Expression> rasterResampling(Expression expression) {
+ return new PaintPropertyValue<>("raster-resampling", expression);
+ }
+
+ /**
* Fade duration when a new tile is added.
*
* @param value a Float value
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java
index 218ed36744..1214f7b11c 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java
@@ -264,6 +264,17 @@ public class RasterLayer extends Layer {
}
/**
+ * Get the RasterResampling property
+ *
+ * @return property wrapper value around String
+ */
+ @SuppressWarnings("unchecked")
+ public PropertyValue<String> getRasterResampling() {
+ checkThread();
+ return (PropertyValue<String>) new PropertyValue("raster-resampling", nativeGetRasterResampling());
+ }
+
+ /**
* Get the RasterFadeDuration property
*
* @return property wrapper value around Float
@@ -310,6 +321,8 @@ public class RasterLayer extends Layer {
private native void nativeSetRasterContrastTransition(long duration, long delay);
+ private native Object nativeGetRasterResampling();
+
private native Object nativeGetRasterFadeDuration();
@Override
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java
index 6e5afdb479..8440fad20a 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/RasterLayerTest.java
@@ -242,6 +242,20 @@ public class RasterLayerTest extends BaseActivityTest {
}
@Test
+ public void testRasterResamplingAsConstant() {
+ validateTestSetup();
+ setupLayer();
+ Timber.i("raster-resampling");
+ invoke(mapboxMap, (uiController, mapboxMap) -> {
+ assertNotNull(layer);
+
+ // Set and Get
+ layer.setProperties(rasterResampling(RASTER_RESAMPLING_LINEAR));
+ assertEquals((String) layer.getRasterResampling().getValue(), (String) RASTER_RESAMPLING_LINEAR);
+ });
+ }
+
+ @Test
public void testRasterFadeDurationAsConstant() {
validateTestSetup();
setupLayer();
diff --git a/platform/android/src/style/conversion/types.hpp b/platform/android/src/style/conversion/types.hpp
index 8a75b870b3..e87782fad0 100644
--- a/platform/android/src/style/conversion/types.hpp
+++ b/platform/android/src/style/conversion/types.hpp
@@ -93,6 +93,13 @@ struct Converter<jni::jobject*, mbgl::style::CirclePitchScaleType> {
};
template <>
+struct Converter<jni::jobject*, mbgl::style::RasterResamplingType> {
+ Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::RasterResamplingType& value) const {
+ return convert<jni::jobject*, std::string>(env, toString(value));
+ }
+};
+
+template <>
struct Converter<jni::jobject*, mbgl::style::HillshadeIlluminationAnchorType> {
Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::HillshadeIlluminationAnchorType& value) const {
return convert<jni::jobject*, std::string>(env, toString(value));
diff --git a/platform/android/src/style/conversion/types_string_values.hpp b/platform/android/src/style/conversion/types_string_values.hpp
index 7e4fd4a7f7..ff79fa4f1c 100644
--- a/platform/android/src/style/conversion/types_string_values.hpp
+++ b/platform/android/src/style/conversion/types_string_values.hpp
@@ -206,6 +206,20 @@ namespace conversion {
}
}
+ // raster-resampling
+ inline std::string toString(mbgl::style::RasterResamplingType value) {
+ switch (value) {
+ case mbgl::style::RasterResamplingType::Linear:
+ return "linear";
+ break;
+ case mbgl::style::RasterResamplingType::Nearest:
+ return "nearest";
+ break;
+ default:
+ throw std::runtime_error("Not implemented");
+ }
+ }
+
// hillshade-illumination-anchor
inline std::string toString(mbgl::style::HillshadeIlluminationAnchorType value) {
switch (value) {
diff --git a/platform/android/src/style/layers/raster_layer.cpp b/platform/android/src/style/layers/raster_layer.cpp
index 6d36298bb1..53086951e4 100644
--- a/platform/android/src/style/layers/raster_layer.cpp
+++ b/platform/android/src/style/layers/raster_layer.cpp
@@ -149,6 +149,12 @@ namespace android {
layer.as<mbgl::style::RasterLayer>()->RasterLayer::setRasterContrastTransition(options);
}
+ jni::Object<jni::ObjectTag> RasterLayer::getRasterResampling(jni::JNIEnv& env) {
+ using namespace mbgl::android::conversion;
+ Result<jni::jobject*> converted = convert<jni::jobject*>(env, layer.as<mbgl::style::RasterLayer>()->RasterLayer::getRasterResampling());
+ return jni::Object<jni::ObjectTag>(*converted);
+ }
+
jni::Object<jni::ObjectTag> RasterLayer::getRasterFadeDuration(jni::JNIEnv& env) {
using namespace mbgl::android::conversion;
Result<jni::jobject*> converted = convert<jni::jobject*>(env, layer.as<mbgl::style::RasterLayer>()->RasterLayer::getRasterFadeDuration());
@@ -193,6 +199,7 @@ namespace android {
METHOD(&RasterLayer::getRasterContrastTransition, "nativeGetRasterContrastTransition"),
METHOD(&RasterLayer::setRasterContrastTransition, "nativeSetRasterContrastTransition"),
METHOD(&RasterLayer::getRasterContrast, "nativeGetRasterContrast"),
+ METHOD(&RasterLayer::getRasterResampling, "nativeGetRasterResampling"),
METHOD(&RasterLayer::getRasterFadeDuration, "nativeGetRasterFadeDuration"));
}
diff --git a/platform/android/src/style/layers/raster_layer.hpp b/platform/android/src/style/layers/raster_layer.hpp
index ed6fc3e1b2..d1c1b45234 100644
--- a/platform/android/src/style/layers/raster_layer.hpp
+++ b/platform/android/src/style/layers/raster_layer.hpp
@@ -53,6 +53,8 @@ public:
void setRasterContrastTransition(jni::JNIEnv&, jlong duration, jlong delay);
jni::Object<TransitionOptions> getRasterContrastTransition(jni::JNIEnv&);
+ jni::Object<jni::ObjectTag> getRasterResampling(jni::JNIEnv&);
+
jni::Object<jni::ObjectTag> getRasterFadeDuration(jni::JNIEnv&);
jni::jobject* createJavaPeer(jni::JNIEnv&);
diff --git a/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json b/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json
index 830b6d69f9..dfc7d76a3c 100644
--- a/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json
+++ b/platform/darwin/scripts/style-spec-cocoa-conventions-v8.json
@@ -37,7 +37,8 @@
"paint_raster": {
"raster-brightness-min": "minimum-raster-brightness",
"raster-brightness-max": "maximum-raster-brightness",
- "raster-hue-rotate": "raster-hue-rotation"
+ "raster-hue-rotate": "raster-hue-rotation",
+ "raster-resampling": "raster-resampling-mode"
},
"paint_line": {
"line-dasharray": "line-dash-pattern",
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
diff --git a/platform/darwin/test/MGLRasterStyleLayerTests.mm b/platform/darwin/test/MGLRasterStyleLayerTests.mm
index cf5175812e..cc5c1b6984 100644
--- a/platform/darwin/test/MGLRasterStyleLayerTests.mm
+++ b/platform/darwin/test/MGLRasterStyleLayerTests.mm
@@ -306,6 +306,49 @@
XCTAssertEqual(rasterOpacityTransition.duration, transitionTest.duration);
}
+ // raster-resampling
+ {
+ XCTAssertTrue(rawLayer->getRasterResampling().isUndefined(),
+ @"raster-resampling should be unset initially.");
+ NSExpression *defaultExpression = layer.rasterResamplingMode;
+
+ NSExpression *constantExpression = [NSExpression expressionWithFormat:@"'nearest'"];
+ layer.rasterResamplingMode = constantExpression;
+ mbgl::style::PropertyValue<mbgl::style::RasterResamplingType> propertyValue = { mbgl::style::RasterResamplingType::Nearest };
+ XCTAssertEqual(rawLayer->getRasterResampling(), propertyValue,
+ @"Setting rasterResamplingMode to a constant value expression should update raster-resampling.");
+ XCTAssertEqualObjects(layer.rasterResamplingMode, constantExpression,
+ @"rasterResamplingMode should round-trip constant value expressions.");
+
+ constantExpression = [NSExpression expressionWithFormat:@"'nearest'"];
+ NSExpression *functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, %@, %@)", constantExpression, @{@18: constantExpression}];
+ layer.rasterResamplingMode = functionExpression;
+
+ mbgl::style::IntervalStops<mbgl::style::RasterResamplingType> intervalStops = {{
+ { -INFINITY, mbgl::style::RasterResamplingType::Nearest },
+ { 18, mbgl::style::RasterResamplingType::Nearest },
+ }};
+ propertyValue = mbgl::style::CameraFunction<mbgl::style::RasterResamplingType> { intervalStops };
+
+ XCTAssertEqual(rawLayer->getRasterResampling(), propertyValue,
+ @"Setting rasterResamplingMode to a camera expression should update raster-resampling.");
+ XCTAssertEqualObjects(layer.rasterResamplingMode, functionExpression,
+ @"rasterResamplingMode should round-trip camera expressions.");
+
+
+ layer.rasterResamplingMode = nil;
+ XCTAssertTrue(rawLayer->getRasterResampling().isUndefined(),
+ @"Unsetting rasterResamplingMode should return raster-resampling to the default value.");
+ XCTAssertEqualObjects(layer.rasterResamplingMode, defaultExpression,
+ @"rasterResamplingMode should return the default value after being unset.");
+
+ functionExpression = [NSExpression expressionForKeyPath:@"bogus"];
+ XCTAssertThrowsSpecificNamed(layer.rasterResamplingMode = functionExpression, NSException, NSInvalidArgumentException, @"MGLRasterLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes.");
+ functionExpression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:(bogus, %@, %@)", constantExpression, @{@18: constantExpression}];
+ functionExpression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", @{@10: functionExpression}];
+ XCTAssertThrowsSpecificNamed(layer.rasterResamplingMode = functionExpression, NSException, NSInvalidArgumentException, @"MGLRasterLayer should raise an exception if a camera-data expression is applied to a property that does not support key paths to feature attributes.");
+ }
+
// raster-saturation
{
XCTAssertTrue(rawLayer->getRasterSaturation().isUndefined(),
@@ -366,7 +409,13 @@
[self testPropertyName:@"raster-fade-duration" isBoolean:NO];
[self testPropertyName:@"raster-hue-rotation" isBoolean:NO];
[self testPropertyName:@"raster-opacity" isBoolean:NO];
+ [self testPropertyName:@"raster-resampling-mode" isBoolean:NO];
[self testPropertyName:@"raster-saturation" isBoolean:NO];
}
+- (void)testValueAdditions {
+ XCTAssertEqual([NSValue valueWithMGLRasterResamplingMode:MGLRasterResamplingModeLinear].MGLRasterResamplingModeValue, MGLRasterResamplingModeLinear);
+ XCTAssertEqual([NSValue valueWithMGLRasterResamplingMode:MGLRasterResamplingModeNearest].MGLRasterResamplingModeValue, MGLRasterResamplingModeNearest);
+}
+
@end
diff --git a/platform/ios/docs/guides/For Style Authors.md b/platform/ios/docs/guides/For Style Authors.md
index d4fb17eb6a..e3e2eca603 100644
--- a/platform/ios/docs/guides/For Style Authors.md
+++ b/platform/ios/docs/guides/For Style Authors.md
@@ -243,6 +243,7 @@ In style JSON | In Objective-C | In Swift
`raster-brightness-max` | `MGLRasterStyleLayer.maximumRasterBrightness` | `MGLRasterStyleLayer.maximumRasterBrightness`
`raster-brightness-min` | `MGLRasterStyleLayer.minimumRasterBrightness` | `MGLRasterStyleLayer.minimumRasterBrightness`
`raster-hue-rotate` | `MGLRasterStyleLayer.rasterHueRotation` | `MGLRasterStyleLayer.rasterHueRotation`
+`raster-resampling` | `MGLRasterStyleLayer.rasterResamplingMode` | `MGLRasterStyleLayer.rasterResamplingMode`
### Symbol style layers
diff --git a/platform/macos/docs/guides/For Style Authors.md b/platform/macos/docs/guides/For Style Authors.md
index 08385a66d9..e2d63a6506 100644
--- a/platform/macos/docs/guides/For Style Authors.md
+++ b/platform/macos/docs/guides/For Style Authors.md
@@ -230,6 +230,7 @@ In style JSON | In Objective-C | In Swift
`raster-brightness-max` | `MGLRasterStyleLayer.maximumRasterBrightness` | `MGLRasterStyleLayer.maximumRasterBrightness`
`raster-brightness-min` | `MGLRasterStyleLayer.minimumRasterBrightness` | `MGLRasterStyleLayer.minimumRasterBrightness`
`raster-hue-rotate` | `MGLRasterStyleLayer.rasterHueRotation` | `MGLRasterStyleLayer.rasterHueRotation`
+`raster-resampling` | `MGLRasterStyleLayer.rasterResamplingMode` | `MGLRasterStyleLayer.rasterResamplingMode`
### Symbol style layers
diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json
index 05a0497242..44ab90d5a0 100644
--- a/platform/node/test/ignores.json
+++ b/platform/node/test/ignores.json
@@ -30,6 +30,8 @@
"query-tests/feature-state/default": "skip - port https://github.com/mapbox/mapbox-gl-js/pull/6263 - needs issue",
"query-tests/regressions/mapbox-gl-js#6555": "skip - no querySourceFeatures in mbgl-node; needs issue",
"render-tests/background-color/transition": "https://github.com/mapbox/mapbox-gl-native/issues/10619",
+ "render-tests/collator/resolved-locale": "Some test platforms don't resolve 'en' locale",
+ "render-tests/collator/default": "Some test platforms don't resolve 'en' locale",
"render-tests/debug/collision": "https://github.com/mapbox/mapbox-gl-native/issues/3841",
"render-tests/debug/collision-lines": "https://github.com/mapbox/mapbox-gl-native/issues/10412",
"render-tests/debug/collision-lines-overscaled": "https://github.com/mapbox/mapbox-gl-native/issues/10412",
@@ -47,6 +49,7 @@
"render-tests/geojson/inline-linestring-fill": "current behavior is arbitrary",
"render-tests/geojson/inline-polygon-symbol": "behavior needs reconciliation with gl-js",
"render-tests/icon-rotate/with-offset": "https://github.com/mapbox/mapbox-gl-native/issues/11872",
+ "render-tests/icon-no-cross-source-collision/default": "skip - gl-js only",
"render-tests/line-gradient/gradient": "https://github.com/mapbox/mapbox-gl-native/issues/11718",
"render-tests/line-gradient/translucent": "https://github.com/mapbox/mapbox-gl-native/issues/11718",
"render-tests/mixed-zoom/z10-z11": "https://github.com/mapbox/mapbox-gl-native/issues/10397",
@@ -71,6 +74,7 @@
"render-tests/runtime-styling/set-style-paint-property-fill-flat-to-extrude": "https://github.com/mapbox/mapbox-gl-native/issues/6745",
"render-tests/symbol-placement/line-overscaled": "https://github.com/mapbox/mapbox-gl-js/issues/5654",
"render-tests/symbol-visibility/visible": "https://github.com/mapbox/mapbox-gl-native/issues/10409",
+ "render-tests/text-no-cross-source-collision/default": "skip - gl-js only",
"render-tests/text-pitch-alignment/auto-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732",
"render-tests/text-pitch-alignment/map-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732",
"render-tests/text-pitch-alignment/viewport-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732",
diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp
index f202ed4ebb..f31f53481f 100644
--- a/src/mbgl/renderer/layers/render_raster_layer.cpp
+++ b/src/mbgl/renderer/layers/render_raster_layer.cpp
@@ -123,13 +123,15 @@ void RenderRasterLayer::render(PaintParameters& parameters, RenderSource* source
);
};
+ const gl::TextureFilter filter = evaluated.get<RasterResampling>() == RasterResamplingType::Nearest ? gl::TextureFilter::Nearest : gl::TextureFilter::Linear;
+
if (RenderImageSource* imageSource = source->as<RenderImageSource>()) {
if (imageSource->isEnabled() && imageSource->isLoaded() && !imageSource->bucket->needsUpload()) {
RasterBucket& bucket = *imageSource->bucket;
assert(bucket.texture);
- parameters.context.bindTexture(*bucket.texture, 0, gl::TextureFilter::Linear);
- parameters.context.bindTexture(*bucket.texture, 1, gl::TextureFilter::Linear);
+ parameters.context.bindTexture(*bucket.texture, 0, filter);
+ parameters.context.bindTexture(*bucket.texture, 1, filter);
for (auto matrix_ : imageSource->matrices) {
draw(matrix_,
@@ -147,8 +149,8 @@ void RenderRasterLayer::render(PaintParameters& parameters, RenderSource* source
continue;
assert(bucket.texture);
- parameters.context.bindTexture(*bucket.texture, 0, gl::TextureFilter::Linear);
- parameters.context.bindTexture(*bucket.texture, 1, gl::TextureFilter::Linear);
+ parameters.context.bindTexture(*bucket.texture, 0, filter);
+ parameters.context.bindTexture(*bucket.texture, 1, filter);
if (bucket.vertexBuffer && bucket.indexBuffer && !bucket.segments.empty()) {
// Draw only the parts of the tile that aren't drawn by another tile in the layer.
diff --git a/src/mbgl/style/conversion/make_property_setters.hpp b/src/mbgl/style/conversion/make_property_setters.hpp
index 25c8fdb1ca..40461fc1e7 100644
--- a/src/mbgl/style/conversion/make_property_setters.hpp
+++ b/src/mbgl/style/conversion/make_property_setters.hpp
@@ -206,6 +206,8 @@ inline auto makePaintPropertySetters() {
result["raster-saturation-transition"] = &setTransition<RasterLayer, &RasterLayer::setRasterSaturationTransition>;
result["raster-contrast"] = &setProperty<RasterLayer, PropertyValue<float>, &RasterLayer::setRasterContrast>;
result["raster-contrast-transition"] = &setTransition<RasterLayer, &RasterLayer::setRasterContrastTransition>;
+ result["raster-resampling"] = &setProperty<RasterLayer, PropertyValue<RasterResamplingType>, &RasterLayer::setRasterResampling>;
+ result["raster-resampling-transition"] = &setTransition<RasterLayer, &RasterLayer::setRasterResamplingTransition>;
result["raster-fade-duration"] = &setProperty<RasterLayer, PropertyValue<float>, &RasterLayer::setRasterFadeDuration>;
result["raster-fade-duration-transition"] = &setTransition<RasterLayer, &RasterLayer::setRasterFadeDurationTransition>;
diff --git a/src/mbgl/style/expression/value.cpp b/src/mbgl/style/expression/value.cpp
index 1b3257c755..7c329e8f1f 100644
--- a/src/mbgl/style/expression/value.cpp
+++ b/src/mbgl/style/expression/value.cpp
@@ -337,6 +337,10 @@ template type::Type valueTypeToExpressionType<TranslateAnchorType>();
template optional<TranslateAnchorType> fromExpressionValue<TranslateAnchorType>(const Value&);
template Value toExpressionValue(const TranslateAnchorType&);
+template type::Type valueTypeToExpressionType<RasterResamplingType>();
+template optional<RasterResamplingType> fromExpressionValue<RasterResamplingType>(const Value&);
+template Value toExpressionValue(const RasterResamplingType&);
+
template type::Type valueTypeToExpressionType<HillshadeIlluminationAnchorType>();
template optional<HillshadeIlluminationAnchorType> fromExpressionValue<HillshadeIlluminationAnchorType>(const Value&);
template Value toExpressionValue(const HillshadeIlluminationAnchorType&);
diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp
index 36b2e3e027..e5b03df0f6 100644
--- a/src/mbgl/style/layers/raster_layer.cpp
+++ b/src/mbgl/style/layers/raster_layer.cpp
@@ -236,6 +236,33 @@ TransitionOptions RasterLayer::getRasterContrastTransition() const {
return impl().paint.template get<RasterContrast>().options;
}
+PropertyValue<RasterResamplingType> RasterLayer::getDefaultRasterResampling() {
+ return { RasterResamplingType::Linear };
+}
+
+PropertyValue<RasterResamplingType> RasterLayer::getRasterResampling() const {
+ return impl().paint.template get<RasterResampling>().value;
+}
+
+void RasterLayer::setRasterResampling(PropertyValue<RasterResamplingType> value) {
+ if (value == getRasterResampling())
+ return;
+ auto impl_ = mutableImpl();
+ impl_->paint.template get<RasterResampling>().value = value;
+ baseImpl = std::move(impl_);
+ observer->onLayerChanged(*this);
+}
+
+void RasterLayer::setRasterResamplingTransition(const TransitionOptions& options) {
+ auto impl_ = mutableImpl();
+ impl_->paint.template get<RasterResampling>().options = options;
+ baseImpl = std::move(impl_);
+}
+
+TransitionOptions RasterLayer::getRasterResamplingTransition() const {
+ return impl().paint.template get<RasterResampling>().options;
+}
+
PropertyValue<float> RasterLayer::getDefaultRasterFadeDuration() {
return { 300 };
}
diff --git a/src/mbgl/style/layers/raster_layer_properties.hpp b/src/mbgl/style/layers/raster_layer_properties.hpp
index 12df09f32c..08818c9fb3 100644
--- a/src/mbgl/style/layers/raster_layer_properties.hpp
+++ b/src/mbgl/style/layers/raster_layer_properties.hpp
@@ -36,6 +36,10 @@ struct RasterContrast : PaintProperty<float> {
static float defaultValue() { return 0; }
};
+struct RasterResampling : PaintProperty<RasterResamplingType> {
+ static RasterResamplingType defaultValue() { return RasterResamplingType::Linear; }
+};
+
struct RasterFadeDuration : PaintProperty<float> {
static float defaultValue() { return 300; }
};
@@ -47,6 +51,7 @@ class RasterPaintProperties : public Properties<
RasterBrightnessMax,
RasterSaturation,
RasterContrast,
+ RasterResampling,
RasterFadeDuration
> {};
diff --git a/src/mbgl/style/types.cpp b/src/mbgl/style/types.cpp
index bdfa20a047..bcaa9e87c7 100644
--- a/src/mbgl/style/types.cpp
+++ b/src/mbgl/style/types.cpp
@@ -25,6 +25,11 @@ MBGL_DEFINE_ENUM(TranslateAnchorType, {
{ TranslateAnchorType::Viewport, "viewport" },
});
+MBGL_DEFINE_ENUM(RasterResamplingType, {
+ { RasterResamplingType::Linear, "linear" },
+ { RasterResamplingType::Nearest, "nearest" },
+});
+
MBGL_DEFINE_ENUM(HillshadeIlluminationAnchorType, {
{ HillshadeIlluminationAnchorType::Map, "map" },
{ HillshadeIlluminationAnchorType::Viewport, "viewport" },