-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMapPolyline.kt
More file actions
59 lines (54 loc) · 1.84 KB
/
MapPolyline.kt
File metadata and controls
59 lines (54 loc) · 1.84 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
package com.rngooglemapsplus
import com.facebook.react.uimanager.PixelUtil.dpToPx
import com.google.android.gms.maps.model.ButtCap
import com.google.android.gms.maps.model.Cap
import com.google.android.gms.maps.model.JointType
import com.google.android.gms.maps.model.PolylineOptions
import com.google.android.gms.maps.model.RoundCap
import com.google.android.gms.maps.model.SquareCap
class MapPolylineOptions {
fun buildPolylineOptions(pl: RNPolyline): PolylineOptions =
PolylineOptions().apply {
pl.coordinates.forEach { pt ->
add(
com.google.android.gms.maps.model
.LatLng(pt.latitude, pt.longitude),
)
}
pl.width?.let { width(it.dpToPx()) }
pl.lineCap?.let { startCap(mapLineCap(it)) }
pl.lineCap?.let { endCap(mapLineCap(it)) }
pl.lineJoin?.let { jointType(mapLineJoin(it)) }
pl.color?.let { color(it.toColor()) }
zIndex(pl.zIndex.toFloat())
}
fun mapLineCap(type: RNLineCapType?): Cap =
when (type) {
RNLineCapType.ROUND -> RoundCap()
RNLineCapType.SQUARE -> SquareCap()
else -> ButtCap()
}
fun mapLineJoin(type: RNLineJoinType?): Int =
when (type) {
RNLineJoinType.ROUND -> JointType.ROUND
RNLineJoinType.BEVEL -> JointType.BEVEL
RNLineJoinType.MITER -> JointType.DEFAULT
null -> JointType.DEFAULT
}
}
fun RNPolyline.polylineEquals(b: RNPolyline): Boolean {
if (zIndex != b.zIndex) return false
if ((width ?: 0.0) != (b.width ?: 0.0)) return false
if (lineCap != b.lineCap) return false
if (lineJoin != b.lineJoin) return false
if (color != b.color) return false
val ac = coordinates
val bc = b.coordinates
if (ac.size != bc.size) return false
for (i in ac.indices) {
val p = ac[i]
val q = bc[i]
if (p.latitude != q.latitude || p.longitude != q.longitude) return false
}
return true
}