Skip to content

Commit 3c3046b

Browse files
committed
Add an init rule for CameraPosition
1 parent d60038f commit 3c3046b

File tree

1 file changed

+10
-4
lines changed
  • kmp-maps/core/src/commonMain/kotlin/com/swmansion/kmpmaps/core

1 file changed

+10
-4
lines changed

kmp-maps/core/src/commonMain/kotlin/com/swmansion/kmpmaps/core/MapTypes.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ public fun Polyline.getId(): String = "polyline_${hashCode()}"
204204
/**
205205
* Represents the camera position and orientation of the map.
206206
*
207-
* At least one of [coordinates] or [bounds] should be provided to position the camera:
208-
* - When [bounds] is set, the camera zooms to fit the entire region regardless of [zoom].
209-
* - When only [coordinates] is set, [zoom] controls the zoom level (defaults to 0 if null).
207+
* **Configuration Rules:** To successfully initialize, you must provide either:
208+
* 1. Both [coordinates] **and** [zoom].
209+
* 2. Or [bounds] (which takes precedence for positioning).
210210
*
211211
* @property coordinates The center coordinates of the camera view, or null to use [bounds] center
212212
* @property zoom The zoom level of the map (typically 0–20), or null to use default (0)
@@ -221,7 +221,13 @@ public data class CameraPosition(
221221
val bounds: MapBounds? = null,
222222
val androidCameraPosition: AndroidCameraPosition? = null,
223223
val iosCameraPosition: IosCameraPosition? = null,
224-
)
224+
) {
225+
init {
226+
require((coordinates != null && zoom != null) || bounds != null) {
227+
"CameraPosition requires at least one of 'coordinates' or 'bounds' to be set."
228+
}
229+
}
230+
}
225231

226232
/**
227233
* Represents a group of markers that have been combined into a single cluster.

0 commit comments

Comments
 (0)