-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathCircle.kt
More file actions
99 lines (94 loc) · 3.63 KB
/
Circle.kt
File metadata and controls
99 lines (94 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.maps.android.compose
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReusableComposeNode
import androidx.compose.runtime.currentComposer
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import com.google.android.gms.maps.model.Circle
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.PatternItem
import com.google.maps.android.ktx.addCircle
internal class CircleNode(
val circle: Circle,
var onCircleClick: (Circle) -> Unit
) : MapNode {
override fun onRemoved() {
circle.remove()
}
}
/**
* A composable for a circle on the map.
*
* @param center the [LatLng] to use for the center of this circle
* @param clickable boolean indicating if the circle is clickable or not
* @param fillColor the fill color of the circle
* @param radius the radius of the circle in meters.
* @param strokeColor the stroke color of the circle
* @param strokePattern a sequence of [PatternItem] to be repeated along the circle's outline (null
* represents a solid line)
* @param tag optional tag to be associated with the circle
* @param strokeWidth the width of the circle's outline in screen pixels
* @param visible the visibility of the circle
* @param zIndex the z-index of the circle
* @param onClick a lambda invoked when the circle is clicked
*/
@Composable
@GoogleMapComposable
public fun Circle(
center: LatLng,
clickable: Boolean = false,
fillColor: Color = Color.Transparent,
radius: Double = 0.0,
strokeColor: Color = Color.Black,
strokePattern: List<PatternItem>? = null,
strokeWidth: Float = 10f,
tag: Any? = null,
visible: Boolean = true,
zIndex: Float = 0f,
onClick: (Circle) -> Unit = {},
) {
val mapApplier = currentComposer.applier as? MapApplier
ReusableComposeNode<CircleNode, MapApplier>(
factory = {
val circle = mapApplier?.map?.addCircle {
center(center)
clickable(clickable)
fillColor(fillColor.toArgb())
radius(radius)
strokeColor(strokeColor.toArgb())
strokePattern(strokePattern)
strokeWidth(strokeWidth)
visible(visible)
zIndex(zIndex)
} ?: error("Error adding circle")
circle.tag = tag
CircleNode(circle, onClick)
},
update = {
update(onClick) { this.onCircleClick = it }
set(center) { this.circle.center = it }
set(clickable) { this.circle.isClickable = it }
set(fillColor) { this.circle.fillColor = it.toArgb() }
set(radius) { this.circle.radius = it }
set(strokeColor) { this.circle.strokeColor = it.toArgb() }
set(strokePattern) { this.circle.strokePattern = it }
set(strokeWidth) { this.circle.strokeWidth = it }
set(tag) { this.circle.tag = it }
set(visible) { this.circle.isVisible = it }
set(zIndex) { this.circle.zIndex = it }
}
)
}