Class HillshadeRasterTileLayer


public class HillshadeRasterTileLayer extends CustomRasterTileLayer
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.
  • Constructor Details

    • HillshadeRasterTileLayer

      public HillshadeRasterTileLayer(TileDataSource dataSource, ElevationDecoder elevationDecoder)
      Constructs a HillshadeRasterTileLayer object from a data source.
      Parameters:
      dataSource - The data source from which this layer loads data.
    • HillshadeRasterTileLayer

      public HillshadeRasterTileLayer(TileDataSource dataSource)
  • 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

      public Color getShadowColor()
      Returns the shading color of areas that face away from the light source.
      Returns:
      The shadow color of the layer.
    • setShadowColor

      public void setShadowColor(Color color)
      Sets the shading color of areas that face away from the light source.
      Parameters:
      color - The new shadow color of the layer.
    • getAccentColor

      public Color getAccentColor()
      Returns the shading color used to accentuate rugged terrain like sharp cliffs and gorges.
      Returns:
      The accent color of the layer.
    • setAccentColor

      public void setAccentColor(Color color)
      Sets the shading color used to accentuate rugged terrain like sharp cliffs and gorges.
      Parameters:
      color - The new accent color of the layer.
    • getHighlightColor

      public Color getHighlightColor()
      Returns the shading color of areas that faces towards the light source.
      Returns:
      The highlight color of the layer.
    • setHighlightColor

      public void setHighlightColor(Color color)
      Sets the shading color of areas that faces towards the light source.
      Parameters:
      color - The new highlight color of the layer.
    • getNormalMapLightingShader

      public String getNormalMapLightingShader()
    • setNormalMapLightingShader

      public void setNormalMapLightingShader(String shader)
      Sets a custom normalmap lighting shader.
      Parameters:
      shader - The custom shader.
    • getIlluminationDirection

      public MapVec getIlluminationDirection()
      Returns the illumination direction of the layer.
      Returns:
      The direction vector for the hillshade illumination
    • setIlluminationDirection

      public void setIlluminationDirection(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). 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

      public Color getContourColor()
      Returns the contour line color.
      Returns:
      The contour line color.
    • setContourColor

      public void setContourColor(Color color)
      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

      public double getElevation(MapPos pos)
    • getElevations

      public DoubleVector getElevations(MapPosVector poses)