-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMapPolylineBuilder.kt
More file actions
69 lines (59 loc) · 1.96 KB
/
MapPolylineBuilder.kt
File metadata and controls
69 lines (59 loc) · 1.96 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
package com.rngooglemapsplus
import android.graphics.Color
import com.facebook.react.uimanager.PixelUtil.dpToPx
import com.google.android.gms.maps.model.Polyline
import com.google.android.gms.maps.model.PolylineOptions
import com.rngooglemapsplus.extensions.coordinatesEquals
import com.rngooglemapsplus.extensions.toColor
import com.rngooglemapsplus.extensions.toLatLng
import com.rngooglemapsplus.extensions.toMapJointType
import com.rngooglemapsplus.extensions.toMapLineCap
class MapPolylineBuilder {
fun build(pl: RNPolyline): PolylineOptions =
PolylineOptions().apply {
pl.coordinates.forEach { pt ->
add(pt.toLatLng())
}
pl.width?.let { width(it.dpToPx()) }
pl.lineCap?.let {
startCap(it.toMapLineCap())
endCap(it.toMapLineCap())
}
pl.lineJoin?.let { jointType(it.toMapJointType()) }
pl.color?.let { color(it.toColor()) }
pl.geodesic?.let { geodesic(it) }
pl.pressable?.let { clickable(it) }
pl.zIndex?.let { zIndex(it.toFloat()) }
}
fun update(
prev: RNPolyline,
next: RNPolyline,
polyline: Polyline,
) = onUi {
if (!prev.coordinatesEquals(next)) {
polyline.points = next.coordinates.map { it.toLatLng() }
}
if (prev.width != next.width) {
polyline.width = next.width?.dpToPx() ?: 1f
}
if (prev.lineCap != next.lineCap) {
polyline.startCap = next.lineCap.toMapLineCap()
polyline.endCap = next.lineCap.toMapLineCap()
}
if (prev.lineJoin != next.lineJoin) {
polyline.jointType = next.lineJoin.toMapJointType()
}
if (prev.color != next.color) {
polyline.color = next.color?.toColor() ?: Color.BLACK
}
if (prev.pressable != next.pressable) {
polyline.isClickable = next.pressable ?: false
}
if (prev.geodesic != next.geodesic) {
polyline.isGeodesic = next.geodesic ?: false
}
if (prev.zIndex != next.zIndex) {
polyline.zIndex = next.zIndex?.toFloat() ?: 0f
}
}
}