core: Update Hillshade Algorithms and add Color-Relief Layer support (#3965)

This commit is contained in:
Andrew Calcutt
2026-02-25 20:50:06 -05:00
committed by GitHub
parent 9682e09ae4
commit 369af13ead
187 changed files with 8804 additions and 2352 deletions

View File

@@ -0,0 +1,227 @@
// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`.
package org.maplibre.android.style.layers;
import androidx.annotation.ColorInt;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import static org.maplibre.android.utils.ColorUtils.rgbaToColor;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import org.maplibre.android.style.expressions.Expression;
import org.maplibre.android.style.layers.TransitionOptions;
/**
* Client-side elevation coloring based on DEM data. The implementation supports Mapbox Terrain RGB, Mapzen Terrarium tiles and custom encodings.
*
* @see <a href="https://maplibre.org/maplibre-style-spec/#layers-color-relief">The online documentation</a>
*/
@UiThread
public class ColorReliefLayer extends Layer {
/**
* Creates a ColorReliefLayer.
*
* @param nativePtr pointer used by core
*/
@Keep
ColorReliefLayer(long nativePtr) {
super(nativePtr);
}
/**
* Creates a ColorReliefLayer.
*
* @param layerId the id of the layer
* @param sourceId the id of the source
*/
public ColorReliefLayer(String layerId, String sourceId) {
super();
initialize(layerId, sourceId);
}
@Keep
protected native void initialize(String layerId, String sourceId);
/**
* Set the source layer.
*
* @param sourceLayer the source layer to set
*/
public void setSourceLayer(String sourceLayer) {
checkThread();
nativeSetSourceLayer(sourceLayer);
}
/**
* Set the source Layer.
*
* @param sourceLayer the source layer to set
* @return This
*/
@NonNull
public ColorReliefLayer withSourceLayer(String sourceLayer) {
setSourceLayer(sourceLayer);
return this;
}
/**
* Get the source id.
*
* @return id of the source
*/
@NonNull
public String getSourceId() {
checkThread();
return nativeGetSourceId();
}
/**
* Get the source layer.
*
* @return sourceLayer the source layer to get
*/
@NonNull
public String getSourceLayer() {
checkThread();
return nativeGetSourceLayer();
}
/**
* Set a single expression filter.
*
* @param filter the expression filter to set
*/
public void setFilter(@NonNull Expression filter) {
checkThread();
nativeSetFilter(filter.toArray());
}
/**
* Set a single expression filter.
*
* @param filter the expression filter to set
* @return This
*/
@NonNull
public ColorReliefLayer withFilter(@NonNull Expression filter) {
setFilter(filter);
return this;
}
/**
* Get a single expression filter.
*
* @return the expression filter to get
*/
@Nullable
public Expression getFilter() {
checkThread();
JsonElement jsonElement = nativeGetFilter();
if (jsonElement != null) {
return Expression.Converter.convert(jsonElement);
} else {
return null;
}
}
/**
* Set a property or properties.
*
* @param properties the var-args properties
* @return This
*/
@NonNull
public ColorReliefLayer withProperties(@NonNull PropertyValue<?>... properties) {
setProperties(properties);
return this;
}
// Property getters
/**
* Get the ColorReliefOpacity property
*
* @return property wrapper value around Float
*/
@NonNull
@SuppressWarnings("unchecked")
public PropertyValue<Float> getColorReliefOpacity() {
checkThread();
return (PropertyValue<Float>) new PropertyValue("color-relief-opacity", nativeGetColorReliefOpacity());
}
/**
* Get the ColorReliefOpacity property transition options
*
* @return transition options for Float
*/
@NonNull
public TransitionOptions getColorReliefOpacityTransition() {
checkThread();
return nativeGetColorReliefOpacityTransition();
}
/**
* Set the ColorReliefOpacity property transition options
*
* @param options transition options for Float
*/
public void setColorReliefOpacityTransition(@NonNull TransitionOptions options) {
checkThread();
nativeSetColorReliefOpacityTransition(options.getDuration(), options.getDelay());
}
/**
* Get the ColorReliefColor property
*
* @return property wrapper value around String
*/
@NonNull
@SuppressWarnings("unchecked")
public PropertyValue<String> getColorReliefColor() {
checkThread();
return (PropertyValue<String>) new PropertyValue("color-relief-color", nativeGetColorReliefColor());
}
/**
* Defines the color of each pixel based on its elevation. Should be an expression that uses `["elevation"]` as input.
*
* @return int representation of a rgba string color
* @throws RuntimeException thrown if property isn't a value
*/
@ColorInt
public int getColorReliefColorAsInt() {
checkThread();
PropertyValue<String> value = getColorReliefColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
} else {
throw new RuntimeException("color-relief-color was set as a Function");
}
}
@NonNull
@Keep
private native Object nativeGetColorReliefOpacity();
@NonNull
@Keep
private native TransitionOptions nativeGetColorReliefOpacityTransition();
@Keep
private native void nativeSetColorReliefOpacityTransition(long duration, long delay);
@NonNull
@Keep
private native Object nativeGetColorReliefColor();
@Override
@Keep
protected native void finalize() throws Throwable;
}

View File

@@ -97,13 +97,25 @@ public class HillshadeLayer extends Layer {
/**
* Get the HillshadeIlluminationDirection property
*
* @return property wrapper value around Float
* @return property wrapper value around Float[]
*/
@NonNull
@SuppressWarnings("unchecked")
public PropertyValue<Float> getHillshadeIlluminationDirection() {
public PropertyValue<Float[]> getHillshadeIlluminationDirection() {
checkThread();
return (PropertyValue<Float>) new PropertyValue("hillshade-illumination-direction", nativeGetHillshadeIlluminationDirection());
return (PropertyValue<Float[]>) new PropertyValue("hillshade-illumination-direction", nativeGetHillshadeIlluminationDirection());
}
/**
* Get the HillshadeIlluminationAltitude property
*
* @return property wrapper value around Float[]
*/
@NonNull
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getHillshadeIlluminationAltitude() {
checkThread();
return (PropertyValue<Float[]>) new PropertyValue("hillshade-illumination-altitude", nativeGetHillshadeIlluminationAltitude());
}
/**
@@ -154,36 +166,19 @@ public class HillshadeLayer extends Layer {
/**
* Get the HillshadeShadowColor property
*
* @return property wrapper value around String
* @return property wrapper value around String[]
*/
@NonNull
@SuppressWarnings("unchecked")
public PropertyValue<String> getHillshadeShadowColor() {
public PropertyValue<String[]> getHillshadeShadowColor() {
checkThread();
return (PropertyValue<String>) new PropertyValue("hillshade-shadow-color", nativeGetHillshadeShadowColor());
}
/**
* The shading color of areas that face away from the light source.
*
* @return int representation of a rgba string color
* @throws RuntimeException thrown if property isn't a value
*/
@ColorInt
public int getHillshadeShadowColorAsInt() {
checkThread();
PropertyValue<String> value = getHillshadeShadowColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
} else {
throw new RuntimeException("hillshade-shadow-color was set as a Function");
}
return (PropertyValue<String[]>) new PropertyValue("hillshade-shadow-color", nativeGetHillshadeShadowColor());
}
/**
* Get the HillshadeShadowColor property transition options
*
* @return transition options for String
* @return transition options for String[]
*/
@NonNull
public TransitionOptions getHillshadeShadowColorTransition() {
@@ -194,7 +189,7 @@ public class HillshadeLayer extends Layer {
/**
* Set the HillshadeShadowColor property transition options
*
* @param options transition options for String
* @param options transition options for String[]
*/
public void setHillshadeShadowColorTransition(@NonNull TransitionOptions options) {
checkThread();
@@ -204,36 +199,19 @@ public class HillshadeLayer extends Layer {
/**
* Get the HillshadeHighlightColor property
*
* @return property wrapper value around String
* @return property wrapper value around String[]
*/
@NonNull
@SuppressWarnings("unchecked")
public PropertyValue<String> getHillshadeHighlightColor() {
public PropertyValue<String[]> getHillshadeHighlightColor() {
checkThread();
return (PropertyValue<String>) new PropertyValue("hillshade-highlight-color", nativeGetHillshadeHighlightColor());
}
/**
* The shading color of areas that faces towards the light source.
*
* @return int representation of a rgba string color
* @throws RuntimeException thrown if property isn't a value
*/
@ColorInt
public int getHillshadeHighlightColorAsInt() {
checkThread();
PropertyValue<String> value = getHillshadeHighlightColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
} else {
throw new RuntimeException("hillshade-highlight-color was set as a Function");
}
return (PropertyValue<String[]>) new PropertyValue("hillshade-highlight-color", nativeGetHillshadeHighlightColor());
}
/**
* Get the HillshadeHighlightColor property transition options
*
* @return transition options for String
* @return transition options for String[]
*/
@NonNull
public TransitionOptions getHillshadeHighlightColorTransition() {
@@ -244,7 +222,7 @@ public class HillshadeLayer extends Layer {
/**
* Set the HillshadeHighlightColor property transition options
*
* @param options transition options for String
* @param options transition options for String[]
*/
public void setHillshadeHighlightColorTransition(@NonNull TransitionOptions options) {
checkThread();
@@ -301,10 +279,26 @@ public class HillshadeLayer extends Layer {
nativeSetHillshadeAccentColorTransition(options.getDuration(), options.getDelay());
}
/**
* Get the HillshadeMethod property
*
* @return property wrapper value around String
*/
@NonNull
@SuppressWarnings("unchecked")
public PropertyValue<String> getHillshadeMethod() {
checkThread();
return (PropertyValue<String>) new PropertyValue("hillshade-method", nativeGetHillshadeMethod());
}
@NonNull
@Keep
private native Object nativeGetHillshadeIlluminationDirection();
@NonNull
@Keep
private native Object nativeGetHillshadeIlluminationAltitude();
@NonNull
@Keep
private native Object nativeGetHillshadeIlluminationAnchor();
@@ -353,6 +347,10 @@ public class HillshadeLayer extends Layer {
@Keep
private native void nativeSetHillshadeAccentColorTransition(long duration, long delay);
@NonNull
@Keep
private native Object nativeGetHillshadeMethod();
@Override
@Keep
protected native void finalize() throws Throwable;

View File

@@ -648,6 +648,42 @@ public final class Property {
@Retention(RetentionPolicy.SOURCE)
public @interface HILLSHADE_ILLUMINATION_ANCHOR {}
// HILLSHADE_METHOD: The hillshade algorithm to use, one of `standard`, `basic`, `combined`, `igor`, or `multidirectional`. ![image](assets/hillshade_methods.png)
/**
* The legacy hillshade method.
*/
public static final String HILLSHADE_METHOD_STANDARD = "standard";
/**
* Basic hillshade. Uses a simple physics model where the reflected light intensity is proportional to the cosine of the angle between the incident light and the surface normal. Similar to GDAL's {@link GDALDEM} default algorithm.
*/
public static final String HILLSHADE_METHOD_BASIC = "basic";
/**
* Hillshade algorithm whose intensity scales with slope. Similar to GDAL's {@link GDALDEM} with -combined option.
*/
public static final String HILLSHADE_METHOD_COMBINED = "combined";
/**
* Hillshade algorithm which tries to minimize effects on other map features beneath. Similar to GDAL's {@link GDALDEM} with -igor option.
*/
public static final String HILLSHADE_METHOD_IGOR = "igor";
/**
* Hillshade with multiple illumination directions. Uses the basic hillshade model with multiple independent light sources.
*/
public static final String HILLSHADE_METHOD_MULTIDIRECTIONAL = "multidirectional";
/**
* The hillshade algorithm to use, one of `standard`, `basic`, `combined`, `igor`, or `multidirectional`. ![image](assets/hillshade_methods.png)
*/
@StringDef({
HILLSHADE_METHOD_STANDARD,
HILLSHADE_METHOD_BASIC,
HILLSHADE_METHOD_COMBINED,
HILLSHADE_METHOD_IGOR,
HILLSHADE_METHOD_MULTIDIRECTIONAL,
})
@Retention(RetentionPolicy.SOURCE)
public @interface HILLSHADE_METHOD {}
// ANCHOR: Whether extruded geometries are lit relative to the map or viewport.
/**

View File

@@ -507,6 +507,7 @@ public class PropertyFactory {
/**
* Distance of halo to the icon outline.
The unit is in density-independent pixels only for SDF sprites that were created with a blur radius of 8, multiplied by the display density. I.e., the radius needs to be 16 for `@2x` sprites, etc.
*
* @param value a Float value
@@ -518,6 +519,7 @@ The unit is in density-independent pixels only for SDF sprites that were created
/**
* Distance of halo to the icon outline.
The unit is in density-independent pixels only for SDF sprites that were created with a blur radius of 8, multiplied by the display density. I.e., the radius needs to be 16 for `@2x` sprites, etc.
*
* @param expression an expression statement
@@ -1428,17 +1430,17 @@ The unit is in density-independent pixels only for SDF sprites that were created
}
/**
* The direction of the light source used to generate the hillshading with 0 as the top of the viewport if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `viewport` and due north if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `map`.
* The direction of the light source(s) used to generate the hillshading with 0 as the top of the viewport if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `viewport` and due north if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `map`. Only when {@link Property.HILLSHADE_METHOD} is set to `multidirectional` can you specify multiple light sources.
*
* @param value a Float value
* @return property wrapper around Float
* @param value a Float[] value
* @return property wrapper around Float[]
*/
public static PropertyValue<Float> hillshadeIlluminationDirection(Float value) {
public static PropertyValue<Float[]> hillshadeIlluminationDirection(Float[] value) {
return new PaintPropertyValue<>("hillshade-illumination-direction", value);
}
/**
* The direction of the light source used to generate the hillshading with 0 as the top of the viewport if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `viewport` and due north if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `map`.
* The direction of the light source(s) used to generate the hillshading with 0 as the top of the viewport if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `viewport` and due north if {@link Property.HILLSHADE_ILLUMINATION_ANCHOR} is set to `map`. Only when {@link Property.HILLSHADE_METHOD} is set to `multidirectional` can you specify multiple light sources.
*
* @param expression an expression statement
* @return property wrapper around an expression statement
@@ -1447,6 +1449,26 @@ The unit is in density-independent pixels only for SDF sprites that were created
return new PaintPropertyValue<>("hillshade-illumination-direction", expression);
}
/**
* The altitude of the light source(s) used to generate the hillshading with 0 as sunset and 90 as noon. Only when {@link Property.HILLSHADE_METHOD} is set to `multidirectional` can you specify multiple light sources.
*
* @param value a Float[] value
* @return property wrapper around Float[]
*/
public static PropertyValue<Float[]> hillshadeIlluminationAltitude(Float[] value) {
return new PaintPropertyValue<>("hillshade-illumination-altitude", value);
}
/**
* The altitude of the light source(s) used to generate the hillshading with 0 as sunset and 90 as noon. Only when {@link Property.HILLSHADE_METHOD} is set to `multidirectional` can you specify multiple light sources.
*
* @param expression an expression statement
* @return property wrapper around an expression statement
*/
public static PropertyValue<Expression> hillshadeIlluminationAltitude(Expression expression) {
return new PaintPropertyValue<>("hillshade-illumination-altitude", expression);
}
/**
* Direction of light source when map is rotated.
*
@@ -1488,27 +1510,17 @@ The unit is in density-independent pixels only for SDF sprites that were created
}
/**
* The shading color of areas that face away from the light source.
* The shading color of areas that face away from the light source(s). Only when {@link Property.HILLSHADE_METHOD} is set to `multidirectional` can you specify multiple light sources.
*
* @param value a int color value
* @return property wrapper around String color
* @param value a String[] value
* @return property wrapper around String[]
*/
public static PropertyValue<String> hillshadeShadowColor(@ColorInt int value) {
return new PaintPropertyValue<>("hillshade-shadow-color", colorToRgbaString(value));
}
/**
* The shading color of areas that face away from the light source.
*
* @param value a String value
* @return property wrapper around String
*/
public static PropertyValue<String> hillshadeShadowColor(String value) {
public static PropertyValue<String[]> hillshadeShadowColor(String[] value) {
return new PaintPropertyValue<>("hillshade-shadow-color", value);
}
/**
* The shading color of areas that face away from the light source.
* The shading color of areas that face away from the light source(s). Only when {@link Property.HILLSHADE_METHOD} is set to `multidirectional` can you specify multiple light sources.
*
* @param expression an expression statement
* @return property wrapper around an expression statement
@@ -1518,27 +1530,17 @@ The unit is in density-independent pixels only for SDF sprites that were created
}
/**
* The shading color of areas that faces towards the light source.
* The shading color of areas that faces towards the light source(s). Only when {@link Property.HILLSHADE_METHOD} is set to `multidirectional` can you specify multiple light sources.
*
* @param value a int color value
* @return property wrapper around String color
* @param value a String[] value
* @return property wrapper around String[]
*/
public static PropertyValue<String> hillshadeHighlightColor(@ColorInt int value) {
return new PaintPropertyValue<>("hillshade-highlight-color", colorToRgbaString(value));
}
/**
* The shading color of areas that faces towards the light source.
*
* @param value a String value
* @return property wrapper around String
*/
public static PropertyValue<String> hillshadeHighlightColor(String value) {
public static PropertyValue<String[]> hillshadeHighlightColor(String[] value) {
return new PaintPropertyValue<>("hillshade-highlight-color", value);
}
/**
* The shading color of areas that faces towards the light source.
* The shading color of areas that faces towards the light source(s). Only when {@link Property.HILLSHADE_METHOD} is set to `multidirectional` can you specify multiple light sources.
*
* @param expression an expression statement
* @return property wrapper around an expression statement
@@ -1577,6 +1579,76 @@ The unit is in density-independent pixels only for SDF sprites that were created
return new PaintPropertyValue<>("hillshade-accent-color", expression);
}
/**
* The hillshade algorithm to use, one of `standard`, `basic`, `combined`, `igor`, or `multidirectional`. ![image](assets/hillshade_methods.png)
*
* @param value a String value
* @return property wrapper around String
*/
public static PropertyValue<String> hillshadeMethod(@Property.HILLSHADE_METHOD String value) {
return new PaintPropertyValue<>("hillshade-method", value);
}
/**
* The hillshade algorithm to use, one of `standard`, `basic`, `combined`, `igor`, or `multidirectional`. ![image](assets/hillshade_methods.png)
*
* @param expression an expression statement
* @return property wrapper around an expression statement
*/
public static PropertyValue<Expression> hillshadeMethod(Expression expression) {
return new PaintPropertyValue<>("hillshade-method", expression);
}
/**
* The opacity at which the color-relief will be drawn.
*
* @param value a Float value
* @return property wrapper around Float
*/
public static PropertyValue<Float> colorReliefOpacity(Float value) {
return new PaintPropertyValue<>("color-relief-opacity", value);
}
/**
* The opacity at which the color-relief will be drawn.
*
* @param expression an expression statement
* @return property wrapper around an expression statement
*/
public static PropertyValue<Expression> colorReliefOpacity(Expression expression) {
return new PaintPropertyValue<>("color-relief-opacity", expression);
}
/**
* Defines the color of each pixel based on its elevation. Should be an expression that uses `["elevation"]` as input.
*
* @param value a int color value
* @return property wrapper around String color
*/
public static PropertyValue<String> colorReliefColor(@ColorInt int value) {
return new PaintPropertyValue<>("color-relief-color", colorToRgbaString(value));
}
/**
* Defines the color of each pixel based on its elevation. Should be an expression that uses `["elevation"]` as input.
*
* @param value a String value
* @return property wrapper around String
*/
public static PropertyValue<String> colorReliefColor(String value) {
return new PaintPropertyValue<>("color-relief-color", value);
}
/**
* Defines the color of each pixel based on its elevation. Should be an expression that uses `["elevation"]` as input.
*
* @param expression an expression statement
* @return property wrapper around an expression statement
*/
public static PropertyValue<Expression> colorReliefColor(Expression expression) {
return new PaintPropertyValue<>("color-relief-color", expression);
}
/**
* The color with which the background will be drawn.
*
@@ -2228,7 +2300,7 @@ The unit is in density-independent pixels only for SDF sprites that were created
}
/**
* Font stack to use for displaying text.
* Fonts to use for displaying text. If the `glyphs` root property is specified, this array is joined together and interpreted as a font stack name. Otherwise, it is interpreted as a cascading fallback list of local font names.
*
* @param value a String[] value
* @return property wrapper around String[]
@@ -2238,7 +2310,7 @@ The unit is in density-independent pixels only for SDF sprites that were created
}
/**
* Font stack to use for displaying text.
* Fonts to use for displaying text. If the `glyphs` root property is specified, this array is joined together and interpreted as a font stack name. Otherwise, it is interpreted as a cascading fallback list of local font names.
*
* @param value a String[] value
* @return property wrapper around String[]
@@ -2395,7 +2467,9 @@ The unit is in density-independent pixels only for SDF sprites that were created
When present, this property takes precedence over {@link Property.TEXT_ANCHOR}, {@link PropertyFactory#textVariableAnchor}, {@link PropertyFactory#textOffset}, and {@link PropertyFactory#textRadialOffset}.
```json
{ "text-variable-anchor-offset": ["top", [0, 4], "left", [3,0], "bottom", [1, 1]] }
```
When the renderer chooses the `top` anchor, `[0, 4]` will be used for {@link PropertyFactory#textOffset}; the text will be shifted down by 4 ems.
@@ -2417,7 +2491,9 @@ The unit is in density-independent pixels only for SDF sprites that were created
When present, this property takes precedence over {@link Property.TEXT_ANCHOR}, {@link PropertyFactory#textVariableAnchor}, {@link PropertyFactory#textOffset}, and {@link PropertyFactory#textRadialOffset}.
```json
{ "text-variable-anchor-offset": ["top", [0, 4], "left", [3,0], "bottom", [1, 1]] }
```
When the renderer chooses the `top` anchor, `[0, 4]` will be used for {@link PropertyFactory#textOffset}; the text will be shifted down by 4 ems.