CircleState
CircleState manages the configuration and behavior of circular overlays on the map. It provides reactive properties for center position, radiusMeters, styling, and interaction settings.
Constructor
Section titled “Constructor”CircleState( center: GeoPoint, radiusMeters: Double, clickable: Boolean = true, strokeColor: Color = Color.Red, strokeWidth: Dp = 1.dp, fillColor: Color = Color(red = 255, green = 255, blue = 255, alpha = 127), id: String? = null, zIndex: Int? = null, extra: Serializable? = null)Properties
Section titled “Properties”Core Properties
Section titled “Core Properties”id: String: Unique identifier (auto-generated if not provided)center: GeoPoint: Geographic center of the circleradiusMeters: Double: radiusMeters in metersclickable: Boolean: Whether the circle responds to click eventsextra: Serializable?: Additional data attached to the circle
Visual Properties
Section titled “Visual Properties”strokeColor: Color: Border colorstrokeWidth: Dp: Border widthfillColor: Color: Interior fill colorzIndex: Int?: Drawing order (higher values drawn on top)
Methods
Section titled “Methods”fun copy(...): CircleState // Create a modified copyfun fingerPrint(): CircleFingerPrint // Change detectionfun asFlow(): Flow<CircleFingerPrint> // Reactive updatesUsage Examples
Section titled “Usage Examples”Basic Circle
Section titled “Basic Circle”val circleState = CircleState( center = GeoPointImpl.fromLatLong(37.7749, -122.4194), radiusMeters = 1000.0, strokeColor = Color.Blue, fillColor = Color.Blue.copy(alpha = 0.3f))
// Replace MapView with your chosen map provider, such as GoogleMapView, MapboxMapViewMapView(state = mapViewState) { Circle(circleState)}Interactive Circle
Section titled “Interactive Circle”@Composablefun InteractiveCircleExample() { var circleState by remember { mutableStateOf( CircleState( center = GeoPointImpl.fromLatLong(37.7749, -122.4194), radiusMeters = 500.0, strokeColor = Color.Red, fillColor = Color.Red.copy(alpha = 0.2f), clickable = true ) ) }
Column { Slider( value = circleState.radiusMeters.toFloat(), onValueChange = { circleState = circleState.copy(radiusMeters = it.toDouble()) }, valueRange = 100f..2000f )
// Replace MapView with your chosen map provider, such as GoogleMapView, MapboxMapViewMapView( state = mapViewState, onCircleClick = { event -> println("Circle clicked at: ${event.clicked}") } ) { Circle(circleState) } }}Multiple Circles with Z-Index
Section titled “Multiple Circles with Z-Index”val circles = listOf( CircleState( center = GeoPointImpl.fromLatLong(37.7749, -122.4194), radiusMeters = 1000.0, fillColor = Color.Red.copy(alpha = 0.3f), zIndex = 1 ), CircleState( center = GeoPointImpl.fromLatLong(37.7749, -122.4194), radiusMeters = 500.0, fillColor = Color.Blue.copy(alpha = 0.5f), zIndex = 2 ))
// Replace MapView with your chosen map provider, such as GoogleMapView, MapboxMapViewMapView(state = mapViewState) { circles.forEach { circleState -> Circle(circleState) }}Event Handling
Section titled “Event Handling”Circle events provide both the state and click location:
data class CircleEvent( val state: CircleState, val clicked: GeoPoint)
typealias OnCircleEventHandler = (CircleEvent) -> UnitBest Practices
Section titled “Best Practices”- Radius Units: Always specify radius in meters for consistency
- Color Alpha: Use alpha transparency for better map visibility
- Z-Index: Use z-index to control overlapping circles
- Performance: Avoid creating too many large circles
- Reactivity: Update properties directly for efficient re-rendering