Package com.massifmaps.layers
Class HillshadeRasterTileLayer
java.lang.Object
com.massifmaps.layers.Layer
com.massifmaps.layers.TileLayer
com.massifmaps.layers.RasterTileLayer
com.massifmaps.layers.CustomRasterTileLayer
com.massifmaps.layers.HillshadeRasterTileLayer
A tile layer that displays an overlay hillshading. Should be used together with corresponding data source that encodes height in RGBA image.
The shading is based on the direction of the main light source, which can be configured using Options class.
Note: this class is experimental and may change or even be removed in future SDK versions.
The shading is based on the direction of the main light source, which can be configured using Options class.
Note: this class is experimental and may change or even be removed in future SDK versions.
-
Constructor Summary
ConstructorsConstructorDescriptionHillshadeRasterTileLayer(TileDataSource dataSource) HillshadeRasterTileLayer(TileDataSource dataSource, ElevationDecoder elevationDecoder) Constructs a HillshadeRasterTileLayer object from a data source. -
Method Summary
Modifier and TypeMethodDescriptionReturns the shading color used to accentuate rugged terrain like sharp cliffs and gorges.Returns the contour line color.floatReturns the spacing between contour lines in meters.floatReturns the contour line half-width in screen pixels.floatReturns the contrast of the hillshade overlay.doublegetElevation(MapPos pos) getElevations(MapPosVector poses) booleanReturns the normal vector tile should be exagerated based on the zoom level.floatReturns the per-frame relief exaggeration factor, i.e.floatReturns the height scale of the hillshade overlay.Returns the shading color of areas that faces towards the light source.intReturns the hillshade rendering method.Returns the illumination direction of the layer.booleanReturns wheter the illumination direction should change with the map rotation.Returns the shading color of areas that face away from the light source.booleanReturns whether GPU contour lines are drawn over the hillshade.booleanReturns whether the normal map encodes absolute elevation (so a custom normal-map lighting
shader can call getElevation()).booleanReturns whether the legacy (pre-MapLibre-parity) height scale formula is used.booleanReturns whether the layer may shade the 3D terrain's own elevation texture instead of
loading a DEM tile set of its own.booleanReturns whether the terrain paint shades from the elevation source's own maximum zoom.voidsetAccentColor(Color color) Sets the shading color used to accentuate rugged terrain like sharp cliffs and gorges.voidsetContourColor(Color color) Sets the contour line color.voidsetContourEnabled(boolean enabled) Sets whether to draw anti-aliased contour lines over the hillshade, computed in the shader
from the elevation data.voidsetContourInterval(float interval) Sets the spacing between contour lines in meters.voidsetContourWidth(float width) Sets the contour line half-width in screen pixels.voidsetContrast(float contrast) Sets the contrast of the hillshade overlay.voidsetElevationEncodingEnabled(boolean enabled) Sets whether the normal map encodes absolute elevation in addition to the surface normal.
Required for a custom normal-map lighting shader that reads getElevation()/getMapZoom() (e.g.
to draw its own per-zoom contour lines).voidsetExagerateHeightScaleEnabled(boolean enabled) Sets wheter the normal vector tile should be exagerated based on the zoom level.voidsetExaggeration(float exaggeration) Sets the per-frame relief exaggeration factor.voidsetHeightScale(float heightScale) Sets the height scale of the hillshade overlay.voidsetHighlightColor(Color color) Sets the shading color of areas that faces towards the light source.voidsetHillshadeMethod(int method) Sets the hillshade rendering method.voidsetIlluminationDirection(MapVec direction) Sets the illumination direction.
The horizontal part is read as a compass bearing (x = sin(azimuth), y = cos(azimuth), with
azimuth 0 = north, increasing clockwise) pointing towards the light, and z points down
towards the ground: -sin(altitude).voidsetIlluminationMapRotationEnabled(boolean enabled) Sets wheter the illumination direction should change with the map rotation.voidsetLegacyHeightScaleEnabled(boolean enabled) Sets whether to use the legacy (pre-MapLibre-parity) height scale formula, in which the
relief is damped by the absolute zoom level and therefore flattens as the camera zooms in.
The default formula instead follows MapLibre: the true slope from zoom 15 up, boosted
below it.voidsetNormalMapLightingShader(String shader) Sets a custom normalmap lighting shader.voidsetShadowColor(Color color) Sets the shading color of areas that face away from the light source.voidsetTerrainPaintEnabled(boolean enabled) Sets whether the layer may shade the shared 3D terrain elevation texture instead of
loading, decoding and uploading a DEM tile set of its own.voidsetTerrainPaintFullDetailEnabled(boolean enabled) Sets whether the terrain paint shades from the elevation source's own maximum zoom
instead of the coarser level the terrain MESH needs (one texel per half surface cell,
which costs two zoom levels of relief - at high zoom, all of it).Methods inherited from class com.massifmaps.layers.CustomRasterTileLayer
getShaderSource, setShaderSourceMethods inherited from class com.massifmaps.layers.RasterTileLayer
getRasterTileEventListener, getTextureCacheCapacity, getTileBlendingSpeed, getTileFilterMode, setRasterTileEventListener, setTextureCacheCapacity, setTileBlendingSpeed, setTileFilterModeMethods inherited from class com.massifmaps.layers.TileLayer
bakeDrapeCoverage, bakeGroundAOMask, bakeSpanDrapeTile, calculateMapTile, calculateMapTileBounds, calculateMapTileOrigin, clearTileCaches, collectDrapeStackOrder, collectSpanDrapeTiles, consumeShadowCastersMissingElevation, getDataSource, getFrameNr, getMaxOverzoomLevel, getMaxStandInLevel, getMaxUnderzoomLevel, getPreloadingTileCount, getProjection, getTileLoadListener, getTileSubstitutionPolicy, getUTFGridDataSource, getUTFGridEventListener, getVisibleTileCount, getZoomLevelBias, isGroundAOActive, isGroundAOBakeable, isLabelOcclusionWanted, isPreloading, isSynchronizedRefresh, isTerrainDecodeSettled, isUpdateInProgress, renderGroundAOMask, renderLabelOcclusionDepth, renderTerrainShadowMask, setDrapeCoverageMasks, setFrameNr, setGroundDrapeTextures, setLabelOcclusionDepth, setMaxOverzoomLevel, setMaxStandInLevel, setMaxUnderzoomLevel, setPreloading, setSpanDrapeTextures, setSynchronizedRefresh, setTerrainShadowMask, setTileLoadListener, setTileSubstitutionPolicy, setUTFGridDataSource, setUTFGridEventListener, setZoomLevelBiasMethods inherited from class com.massifmaps.layers.Layer
containsMetaDataKey, equals, getMetaData, getMetaDataElement, getOpacity, getUpdatePriority, getVisibleZoomRange, hashCode, isPostProcessed, isVisible, refresh, setCullDelay, setMetaData, setMetaDataElement, setOpacity, setPostProcessed, setUpdatePriority, setVisible, setVisibleZoomRange, simulateClick, update
-
Constructor Details
-
HillshadeRasterTileLayer
Constructs a HillshadeRasterTileLayer object from a data source.- Parameters:
dataSource- The data source from which this layer loads data.
-
HillshadeRasterTileLayer
-
-
Method Details
-
getContrast
public float getContrast()Returns the contrast of the hillshade overlay. This is the equivalent of MapLibre's
'hillshade-exaggeration' paint property: it controls the slope response curve and the
overall strength of the shading, not the relief itself.- Returns:
- The contrast value (between 0..1). Default is 0.5.
-
setContrast
public void setContrast(float contrast) Sets the contrast of the hillshade overlay. Equivalent to MapLibre's
'hillshade-exaggeration'; 0.5 is the neutral value.- Parameters:
contrast- The contrast value (between 0..1).
-
getHeightScale
public float getHeightScale()Returns the height scale of the hillshade overlay.- Returns:
- The relative height scale. Default is 0.05.
-
setHeightScale
public void setHeightScale(float heightScale) Sets the height scale of the hillshade overlay. Baked into the normal map at decode time,
so changing it reloads the tiles. See setLegacyHeightScaleEnabled for the old default.- Parameters:
heightScale- The relative height scale. Actual height is multiplied by this values.
-
getExaggeration
public float getExaggeration()Returns the per-frame relief exaggeration factor, i.e. the vertical exaggeration of the
slope. Unlike height scale this is a shader uniform applied at render time (no tile
re-decode), so it can be animated smoothly.- Returns:
- The exaggeration factor. Default is 1.0.
-
setExaggeration
public void setExaggeration(float exaggeration) Sets the per-frame relief exaggeration factor. Multiplies the hillshade slope in the
shader without re-decoding tiles, so it can change smoothly (e.g. with zoom). 1.0 leaves the
appearance unchanged.- Parameters:
exaggeration- The exaggeration factor.
-
getShadowColor
Returns the shading color of areas that face away from the light source.- Returns:
- The shadow color of the layer.
-
setShadowColor
Sets the shading color of areas that face away from the light source.- Parameters:
color- The new shadow color of the layer.
-
getAccentColor
Returns the shading color used to accentuate rugged terrain like sharp cliffs and gorges.- Returns:
- The accent color of the layer.
-
setAccentColor
Sets the shading color used to accentuate rugged terrain like sharp cliffs and gorges.- Parameters:
color- The new accent color of the layer.
-
getHighlightColor
Returns the shading color of areas that faces towards the light source.- Returns:
- The highlight color of the layer.
-
setHighlightColor
Sets the shading color of areas that faces towards the light source.- Parameters:
color- The new highlight color of the layer.
-
getNormalMapLightingShader
-
setNormalMapLightingShader
Sets a custom normalmap lighting shader.- Parameters:
shader- The custom shader.
-
getIlluminationDirection
Returns the illumination direction of the layer.- Returns:
- The direction vector for the hillshade illumination
-
setIlluminationDirection
Sets the illumination direction.
The horizontal part is read as a compass bearing (x = sin(azimuth), y = cos(azimuth), with
azimuth 0 = north, increasing clockwise) pointing towards the light, and z points down
towards the ground: -sin(altitude). MapLibre's default 'hillshade-illumination-direction'
of 335 degrees at a 45 degree altitude is therefore (-0.4226, 0.9063, -0.7071), which is
the default here too. -
getIlluminationMapRotationEnabled
public boolean getIlluminationMapRotationEnabled()Returns wheter the illumination direction should change with the map rotation.- Returns:
- enabled
-
setIlluminationMapRotationEnabled
public void setIlluminationMapRotationEnabled(boolean enabled) Sets wheter the illumination direction should change with the map rotation.- Parameters:
enabled- whether to enable or not.
-
getExagerateHeightScaleEnabled
public boolean getExagerateHeightScaleEnabled()Returns the normal vector tile should be exagerated based on the zoom level.- Returns:
- enabled
-
setExagerateHeightScaleEnabled
public void setExagerateHeightScaleEnabled(boolean enabled) Sets wheter the normal vector tile should be exagerated based on the zoom level.- Parameters:
enabled- whether to enable or not.
-
isLegacyHeightScaleEnabled
public boolean isLegacyHeightScaleEnabled()Returns whether the legacy (pre-MapLibre-parity) height scale formula is used.- Returns:
- True if the legacy formula is used. Default is false.
-
setLegacyHeightScaleEnabled
public void setLegacyHeightScaleEnabled(boolean enabled) Sets whether to use the legacy (pre-MapLibre-parity) height scale formula, in which the
relief is damped by the absolute zoom level and therefore flattens as the camera zooms in.
The default formula instead follows MapLibre: the true slope from zoom 15 up, boosted
below it. Styles tuned against the legacy formula should enable this and also call
setHeightScale(0.09f), which was the old default height scale.- Parameters:
enabled- Whether to use the legacy formula.
-
getHillshadeMethod
public int getHillshadeMethod()Returns the hillshade rendering method.- Returns:
- The hillshade method. Default is IGOR.
-
setHillshadeMethod
public void setHillshadeMethod(int method) Sets the hillshade rendering method.- Parameters:
method- The hillshade method to use.
-
isElevationEncodingEnabled
public boolean isElevationEncodingEnabled()Returns whether the normal map encodes absolute elevation (so a custom normal-map lighting
shader can call getElevation()).- Returns:
- True if elevation encoding is enabled. Default is false.
-
setElevationEncodingEnabled
public void setElevationEncodingEnabled(boolean enabled) Sets whether the normal map encodes absolute elevation in addition to the surface normal.
Required for a custom normal-map lighting shader that reads getElevation()/getMapZoom() (e.g.
to draw its own per-zoom contour lines). Enabling contour lines turns this on implicitly.- Parameters:
enabled- True to encode elevation into the normal map.
-
isContourEnabled
public boolean isContourEnabled()Returns whether GPU contour lines are drawn over the hillshade.- Returns:
- True if contour lines are enabled. Default is false.
-
setContourEnabled
public void setContourEnabled(boolean enabled) Sets whether to draw anti-aliased contour lines over the hillshade, computed in the shader
from the elevation data. Enabling this makes the normal map encode absolute elevation (which
is also available to a custom normal-map lighting shader). Note: this class is experimental.- Parameters:
enabled- True to draw contour lines.
-
getContourInterval
public float getContourInterval()Returns the spacing between contour lines in meters.- Returns:
- The contour interval in meters. Default is 100.
-
setContourInterval
public void setContourInterval(float interval) Sets the spacing between contour lines in meters.- Parameters:
interval- The contour interval in meters.
-
getContourColor
Returns the contour line color.- Returns:
- The contour line color.
-
setContourColor
Sets the contour line color.- Parameters:
color- The contour line color.
-
getContourWidth
public float getContourWidth()Returns the contour line half-width in screen pixels.- Returns:
- The contour line width. Default is 0.75.
-
setContourWidth
public void setContourWidth(float width) Sets the contour line half-width in screen pixels.- Parameters:
width- The contour line width in pixels.
-
isTerrainPaintEnabled
public boolean isTerrainPaintEnabled()Returns whether the layer may shade the 3D terrain's own elevation texture instead of
loading a DEM tile set of its own.- Returns:
- True if terrain paint mode is allowed. Default is true.
-
setTerrainPaintEnabled
public void setTerrainPaintEnabled(boolean enabled) Sets whether the layer may shade the shared 3D terrain elevation texture instead of
loading, decoding and uploading a DEM tile set of its own. It applies only when the map
renders 3D terrain with draped fills FROM THE SAME data source, and not while the
built-in contour lines are enabled: the layer then draws one quad per terrain tile, at
its own place in the layer order, and fetches nothing. In any other configuration the
layer keeps its normal map tile set. Disable it to compare the two paths.
Note that the shading is then computed from the TERRAIN's elevation grid, so it does not
follow this layer's own zoom level bias, and it resolves the relief slightly differently
from a magnified normal map raster.- Parameters:
enabled- True to allow terrain paint mode.
-
isTerrainPaintFullDetailEnabled
public boolean isTerrainPaintFullDetailEnabled()Returns whether the terrain paint shades from the elevation source's own maximum zoom.- Returns:
- True if full DEM detail is used. Default is true.
-
setTerrainPaintFullDetailEnabled
public void setTerrainPaintFullDetailEnabled(boolean enabled) Sets whether the terrain paint shades from the elevation source's own maximum zoom
instead of the coarser level the terrain MESH needs (one texel per half surface cell,
which costs two zoom levels of relief - at high zoom, all of it). Shading is per fragment
and resolves what the mesh cannot, so this is on by default; turning it off gives the
terrain's own elevation textures back and is measurably faster.- Parameters:
enabled- True to shade from the DEM's own maximum zoom.
-
getElevation
-
getElevations
-