-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMapPolygonBuilder.kt
More file actions
47 lines (44 loc) · 1.47 KB
/
MapPolygonBuilder.kt
File metadata and controls
47 lines (44 loc) · 1.47 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
package com.rngooglemapsplus
import android.graphics.Color
import com.facebook.react.uimanager.PixelUtil.dpToPx
import com.google.android.gms.maps.model.Polygon
import com.google.android.gms.maps.model.PolygonOptions
import com.rngooglemapsplus.extensions.toColor
import com.rngooglemapsplus.extensions.toLatLng
class MapPolygonBuilder {
fun build(poly: RNPolygon): PolygonOptions =
PolygonOptions().apply {
poly.coordinates.forEach { pt ->
add(
pt.toLatLng(),
)
}
poly.fillColor?.let { fillColor(it.toColor()) }
poly.strokeColor?.let { strokeColor(it.toColor()) }
poly.strokeWidth?.let { strokeWidth(it.dpToPx()) }
poly.pressable?.let { clickable(it) }
poly.geodesic?.let { geodesic(it) }
poly.holes?.forEach { hole ->
addHole(hole.coordinates.map { it.toLatLng() })
}
poly.zIndex?.let { zIndex(it.toFloat()) }
}
fun update(
poly: Polygon,
next: RNPolygon,
) {
poly.points =
next.coordinates.map {
it.toLatLng()
}
poly.fillColor = next.fillColor?.toColor() ?: Color.TRANSPARENT
poly.strokeColor = next.strokeColor?.toColor() ?: Color.BLACK
poly.strokeWidth = next.strokeWidth?.dpToPx() ?: 1f
poly.isClickable = next.pressable ?: false
poly.isGeodesic = next.geodesic ?: false
poly.holes = next.holes?.map { hole ->
hole.coordinates.map { it.toLatLng() }
} ?: emptyList()
poly.zIndex = next.zIndex?.toFloat() ?: 0f
}
}