[core] add raster-resampling property (#12176)
* update style-code for raster-resampling * implement user-defined raster-resampling * invert filter condition * raster-resampling -> raster-resampling-mode for darwin language conventions
This commit is contained in:
@@ -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.
|
||||
|
||||
/**
|
||||
|
||||
@@ -1335,6 +1335,26 @@ public class PropertyFactory {
|
||||
return new PaintPropertyValue<>("raster-contrast", expression);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
||||
@@ -263,6 +263,17 @@ public class RasterLayer extends Layer {
|
||||
nativeSetRasterContrastTransition(options.getDuration(), options.getDelay());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@@ -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
|
||||
|
||||
@@ -241,6 +241,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();
|
||||
|
||||
@@ -92,6 +92,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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
|
||||
@@ -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&);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user