Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Collaborator

@westnordost westnordost Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raster DEM sources have the additional property encoding which is missing here. Could be represented with

/** The encoding used by a Raster DEM source. */
public sealed interface RasterDemEncoding {

  /** Mapbox Terrain RGB tiles. See https://www.mapbox.com/help/access-elevation-data/#mapbox-terrain-rgb for more info */
  public data object Mapbox : RasterDemEncoding

  /** Terrarium format PNG tiles. See https://aws.amazon.com/es/public-datasets/terrain/ for more info. */
  public data object Terrarium : RasterDemEncoding

  /** 
    Custom format using the given [redFactor], [blueFactor], [greenFactor] and [baseShift] parameters.
    Currently only supported in JS.
  */
  public data class Custom(
    /** Value that will be multiplied by the red channel value when decoding. */
    val redFactor: Float = 1f,
    /** Value that will be multiplied by the blue channel value when decoding. */
    val blueFactor: Float = 1f,
    /** Value that will be multiplied by the green channel value when decoding. */
    val greenFactor: Float = 1f,
    /** Value that will be added to the encoding mix when decoding. */
    val baseShift: Float = 0f,
  ) : RasterDemEncoding
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.maplibre.compose.sources

import org.maplibre.android.style.sources.RasterDemSource as MLNRasterDemSource
import org.maplibre.android.style.sources.TileSet
import org.maplibre.compose.util.correctedAndroidUri
import org.maplibre.compose.util.toLatLngBounds

public actual class RasterDemSource : Source {
override val impl: MLNRasterDemSource

internal constructor(source: MLNRasterDemSource) {
impl = source
}

public actual constructor(id: String, uri: String, tileSize: Int) {
impl = MLNRasterDemSource(id, uri.correctedAndroidUri(), tileSize)
}

public actual constructor(
id: String,
tiles: List<String>,
options: TileSetOptions,
tileSize: Int,
) {
impl =
MLNRasterDemSource(
id,
TileSet(
"{\"type\": \"raster-dem\"}",
*tiles.map { it.correctedAndroidUri() }.toTypedArray(),
)
.apply {
minZoom = options.minZoom.toFloat()
maxZoom = options.maxZoom.toFloat()
options.boundingBox?.let { setBounds(it.toLatLngBounds()) }
attribution = options.attributionHtml
},
tileSize,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.maplibre.compose.util.MaplibreComposable
* Terrain RGB, Mapzen Terrarium tiles and custom encodings.
*
* @param id Unique layer name.
* @param source Vector data source for this layer.
* @param source Raster DEM data source for this layer.
* @param minZoom The minimum zoom level for the layer. At zoom levels less than this, the layer
* will be hidden. A value in the range of `[0..24]`.
* @param maxZoom The maximum zoom level for the layer. At zoom levels equal to or greater than
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.maplibre.compose.sources

import androidx.compose.runtime.Composable
import androidx.compose.runtime.key

/** A map data source of DEM raster images. */
public expect class RasterDemSource : Source {

/**
* @param id Unique identifier for this source
* @param uri URI pointing to a JSON file that conforms to the
* [TileJSON specification](https://github.com/mapbox/tilejson-spec/)
* @param tileSize width and height (measured in points) of each tiled image in the raster tile
* source
*/
public constructor(id: String, uri: String, tileSize: Int = 512)

/**
* @param id Unique identifier for this source
* @param tiles List of URIs pointing to tile images
* @param options see [TileSetOptions]
* @param tileSize width and height (measured in points) of each tiled image in the raster tile
* source
*/
public constructor(
id: String,
tiles: List<String>,
options: TileSetOptions = TileSetOptions(),
tileSize: Int = SourceDefaults.RASTER_TILE_SIZE,
)
}

/** Remember a new [RasterDemSource] with the given [tileSize] from the given [uri]. */
@Composable
public fun rememberRasterDemSource(
uri: String,
tileSize: Int = SourceDefaults.RASTER_TILE_SIZE,
): RasterDemSource =
key(uri, tileSize) {
rememberUserSource(
factory = { RasterDemSource(id = it, uri = uri, tileSize = tileSize) },
update = {},
)
}

@Composable
public fun rememberRasterDemSource(
tiles: List<String>,
options: TileSetOptions = TileSetOptions(),
tileSize: Int = SourceDefaults.RASTER_TILE_SIZE,
): RasterDemSource =
key(tiles, options, tileSize) {
rememberUserSource(
factory = { RasterDemSource(id = it, tiles = tiles, options = options, tileSize = tileSize) },
update = {},
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.maplibre.compose.sources

public actual class RasterDemSource : Source {
public actual constructor(id: String, uri: String, tileSize: Int) : super() {
this.impl = TODO()
}

public actual constructor(
id: String,
tiles: List<String>,
options: TileSetOptions,
tileSize: Int,
) : super() {
this.impl = TODO()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe at least use TODO("Not implemented") or similar for clarity, after all, a TODO produces a runtime exception if that code is reached, IIRC.

}

override val impl: Nothing
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.maplibre.compose.sources

public actual class RasterDemSource : Source {
public actual constructor(id: String, uri: String, tileSize: Int) : super() {
this.impl = TODO()
}

public actual constructor(
id: String,
tiles: List<String>,
options: TileSetOptions,
tileSize: Int,
) : super() {
this.impl = TODO()
}

override val impl: Nothing
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.maplibre.compose.sources

public actual class RasterDemSource : Source {
public actual constructor(id: String, uri: String, tileSize: Int) : super() {
this.impl = TODO()
}

public actual constructor(
id: String,
tiles: List<String>,
options: TileSetOptions,
tileSize: Int,
) : super() {
this.impl = TODO()
}

override val impl: Nothing
}
Loading