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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.maplibre.compose.camera

import androidx.compose.runtime.Immutable
import kotlinx.serialization.Serializable
import org.maplibre.spatialk.geojson.Position

/**
Expand All @@ -13,6 +14,7 @@ import org.maplibre.spatialk.geojson.Position
* @param zoom Zoom level at target. A value in the range of `[0 .. 25.5]`
*/
@Immutable
@Serializable
public data class CameraPosition(
public val bearing: Double = 0.0,
public val target: Position = Position(0.0, 0.0),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.maplibre.compose.camera

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.maplibre.spatialk.geojson.Position

class CameraPositionTest {
@Test
fun roundTripsCameraThroughJson() {
val expected =
CameraPosition(
bearing = 42.5,
target = Position(longitude = -122.675, latitude = 45.521, altitude = 12.0),
tilt = 30.0,
zoom = 13.0,
)

val encoded = Json.encodeToString(expected)

assertEquals(expected, Json.decodeFromString<CameraPosition>(encoded))
}

@Test
fun restoresOmittedFieldsToConstructorDefaults() {
val restored = Json.decodeFromString<CameraPosition>("{}")

assertEquals(CameraPosition(), restored)
}
}
Loading