react-native-google-maps-plus 1.3.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt +15 -23
  3. package/android/src/main/java/com/rngooglemapsplus/MapCircleBuilder.kt +33 -9
  4. package/android/src/main/java/com/rngooglemapsplus/MapMarkerBuilder.kt +73 -18
  5. package/android/src/main/java/com/rngooglemapsplus/MapPolygonBuilder.kt +59 -12
  6. package/android/src/main/java/com/rngooglemapsplus/MapPolylineBuilder.kt.kt +47 -12
  7. package/android/src/main/java/com/rngooglemapsplus/RNGoogleMapsPlusView.kt +12 -9
  8. package/android/src/main/java/com/rngooglemapsplus/extensions/LatLngExtension.kt +6 -0
  9. package/android/src/main/java/com/rngooglemapsplus/extensions/RNCameraExtension.kt +1 -2
  10. package/android/src/main/java/com/rngooglemapsplus/extensions/RNLatLngExtension.kt +6 -0
  11. package/android/src/main/java/com/rngooglemapsplus/extensions/RNMarkerExtension.kt +8 -0
  12. package/android/src/main/java/com/rngooglemapsplus/extensions/RNPolygonExtension.kt +2 -0
  13. package/android/src/main/java/com/rngooglemapsplus/extensions/RNPolylineExtension.kt +1 -0
  14. package/ios/GoogleMapViewImpl.swift +18 -49
  15. package/ios/MapCircleBuilder.swift +30 -18
  16. package/ios/MapMarkerBuilder.swift +64 -20
  17. package/ios/MapPolygonBuilder.swift +62 -13
  18. package/ios/MapPolylineBuilder.swift +33 -15
  19. package/ios/RNGoogleMapsPlusView.swift +10 -8
  20. package/ios/extensions/CLLocationCoordinate2D+Extension.swift +7 -0
  21. package/ios/extensions/RNLatLng+Extension.swift +7 -0
  22. package/ios/extensions/RNMarker+Extension.swift +5 -0
  23. package/ios/extensions/RNPolygon+Extension.swift.swift +16 -1
  24. package/ios/extensions/RNPolyline+Extension.swift.swift +1 -0
  25. package/lib/module/types.js.map +1 -1
  26. package/lib/typescript/src/types.d.ts +8 -0
  27. package/lib/typescript/src/types.d.ts.map +1 -1
  28. package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.cpp +4 -0
  29. package/nitrogen/generated/android/c++/JRNMarker.hpp +8 -0
  30. package/nitrogen/generated/android/c++/JRNPolygon.hpp +29 -2
  31. package/nitrogen/generated/android/c++/JRNPolygonHole.hpp +72 -0
  32. package/nitrogen/generated/android/c++/JRNPolyline.hpp +4 -0
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNMarker.kt +6 -0
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNPolygon.kt +7 -1
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNPolygonHole.kt +29 -0
  36. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNPolyline.kt +3 -0
  37. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/views/HybridRNGoogleMapsPlusViewManager.kt +1 -1
  38. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Bridge.cpp +16 -16
  39. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Bridge.hpp +51 -20
  40. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Umbrella.hpp +3 -0
  41. package/nitrogen/generated/ios/c++/HybridRNGoogleMapsPlusViewSpecSwift.hpp +6 -3
  42. package/nitrogen/generated/ios/swift/HybridRNGoogleMapsPlusViewSpec_cxx.swift +7 -56
  43. package/nitrogen/generated/ios/swift/RNCamera.swift +1 -8
  44. package/nitrogen/generated/ios/swift/RNHeatmap.swift +1 -8
  45. package/nitrogen/generated/ios/swift/RNHeatmapGradient.swift +11 -15
  46. package/nitrogen/generated/ios/swift/RNInitialProps.swift +1 -8
  47. package/nitrogen/generated/ios/swift/RNLocationConfig.swift +2 -16
  48. package/nitrogen/generated/ios/swift/RNMarker.swift +47 -15
  49. package/nitrogen/generated/ios/swift/RNPolygon.swift +66 -1
  50. package/nitrogen/generated/ios/swift/RNPolygonHole.swift +47 -0
  51. package/nitrogen/generated/ios/swift/RNPolyline.swift +24 -1
  52. package/nitrogen/generated/ios/swift/RNSnapshotOptions.swift +1 -8
  53. package/nitrogen/generated/shared/c++/RNAndroidLocationConfig.hpp +8 -0
  54. package/nitrogen/generated/shared/c++/RNCamera.hpp +8 -0
  55. package/nitrogen/generated/shared/c++/RNCircle.hpp +8 -0
  56. package/nitrogen/generated/shared/c++/RNHeatmap.hpp +8 -0
  57. package/nitrogen/generated/shared/c++/RNHeatmapGradient.hpp +8 -0
  58. package/nitrogen/generated/shared/c++/RNHeatmapPoint.hpp +8 -0
  59. package/nitrogen/generated/shared/c++/RNIOSLocationConfig.hpp +8 -0
  60. package/nitrogen/generated/shared/c++/RNIndoorBuilding.hpp +8 -0
  61. package/nitrogen/generated/shared/c++/RNIndoorLevel.hpp +8 -0
  62. package/nitrogen/generated/shared/c++/RNInitialProps.hpp +8 -0
  63. package/nitrogen/generated/shared/c++/RNKMLayer.hpp +8 -0
  64. package/nitrogen/generated/shared/c++/RNLatLng.hpp +8 -0
  65. package/nitrogen/generated/shared/c++/RNLatLngBounds.hpp +8 -0
  66. package/nitrogen/generated/shared/c++/RNLocation.hpp +8 -0
  67. package/nitrogen/generated/shared/c++/RNLocationConfig.hpp +8 -0
  68. package/nitrogen/generated/shared/c++/RNLocationPermissionResult.hpp +8 -0
  69. package/nitrogen/generated/shared/c++/RNMapPadding.hpp +8 -0
  70. package/nitrogen/generated/shared/c++/RNMapUiSettings.hpp +8 -0
  71. package/nitrogen/generated/shared/c++/RNMapZoomConfig.hpp +8 -0
  72. package/nitrogen/generated/shared/c++/RNMarker.hpp +17 -1
  73. package/nitrogen/generated/shared/c++/RNMarkerSvg.hpp +8 -0
  74. package/nitrogen/generated/shared/c++/RNPolygon.hpp +21 -2
  75. package/nitrogen/generated/shared/c++/RNPolygonHole.hpp +77 -0
  76. package/nitrogen/generated/shared/c++/RNPolyline.hpp +13 -1
  77. package/nitrogen/generated/shared/c++/RNPosition.hpp +8 -0
  78. package/nitrogen/generated/shared/c++/RNRegion.hpp +8 -0
  79. package/nitrogen/generated/shared/c++/RNSize.hpp +8 -0
  80. package/nitrogen/generated/shared/c++/RNSnapshotOptions.hpp +8 -0
  81. package/package.json +4 -4
  82. package/src/types.ts +9 -0
@@ -28,7 +28,7 @@ apply from: "./fix-prefab.gradle"
28
28
  if (rootProject.name != "rngooglemapsplus.example") {
29
29
  apply plugin: "com.facebook.react"
30
30
  } else {
31
- println("\u001B[33m⚠️ Skipping React Native Gradle plugin in library (example build detected)\u001B[0m")
31
+ println("\u001B[33mSkipping React Native Gradle plugin in library (example build detected)\u001B[0m")
32
32
  }
33
33
 
34
34
  def getExtOrIntegerDefault(name) {
@@ -35,9 +35,11 @@ import com.google.android.gms.maps.model.TileOverlayOptions
35
35
  import com.google.maps.android.data.kml.KmlLayer
36
36
  import com.margelo.nitro.core.Promise
37
37
  import com.rngooglemapsplus.extensions.toGooglePriority
38
+ import com.rngooglemapsplus.extensions.toLatLng
38
39
  import com.rngooglemapsplus.extensions.toLocationErrorCode
39
40
  import com.rngooglemapsplus.extensions.toRNIndoorBuilding
40
41
  import com.rngooglemapsplus.extensions.toRNIndoorLevel
42
+ import com.rngooglemapsplus.extensions.toRnLatLng
41
43
  import java.io.ByteArrayInputStream
42
44
  import java.io.ByteArrayOutputStream
43
45
  import java.io.File
@@ -88,11 +90,7 @@ class GoogleMapsViewImpl(
88
90
  reactContext.addLifecycleEventListener(this)
89
91
  }
90
92
 
91
- fun initMapView(
92
- mapId: String?,
93
- liteMode: Boolean?,
94
- cameraPosition: CameraPosition?,
95
- ) {
93
+ fun initMapView(googleMapsOptions: GoogleMapOptions) {
96
94
  if (initialized) return
97
95
  initialized = true
98
96
  val result = playServiceHandler.playServicesAvailability()
@@ -126,13 +124,7 @@ class GoogleMapsViewImpl(
126
124
  mapView =
127
125
  MapView(
128
126
  reactContext,
129
- GoogleMapOptions().apply {
130
- mapId?.let { mapId(it) }
131
- liteMode?.let { liteMode(it) }
132
- cameraPosition?.let {
133
- camera(it)
134
- }
135
- },
127
+ googleMapsOptions,
136
128
  )
137
129
 
138
130
  super.addView(mapView)
@@ -173,12 +165,12 @@ class GoogleMapsViewImpl(
173
165
 
174
166
  onCameraChangeStart?.invoke(
175
167
  RNRegion(
176
- center = RNLatLng(bounds.center.latitude, bounds.center.longitude),
168
+ center = bounds.center.toRnLatLng(),
177
169
  latitudeDelta = latDelta,
178
170
  longitudeDelta = lngDelta,
179
171
  ),
180
172
  RNCamera(
181
- center = RNLatLng(cameraPosition.target.latitude, cameraPosition.target.longitude),
173
+ center = cameraPosition.target.toRnLatLng(),
182
174
  zoom = cameraPosition.zoom.toDouble(),
183
175
  bearing = cameraPosition.bearing.toDouble(),
184
176
  tilt = cameraPosition.tilt.toDouble(),
@@ -205,12 +197,12 @@ class GoogleMapsViewImpl(
205
197
 
206
198
  onCameraChange?.invoke(
207
199
  RNRegion(
208
- center = RNLatLng(bounds.center.latitude, bounds.center.longitude),
200
+ center = bounds.center.toRnLatLng(),
209
201
  latitudeDelta = latDelta,
210
202
  longitudeDelta = lngDelta,
211
203
  ),
212
204
  RNCamera(
213
- center = RNLatLng(cameraPosition.target.latitude, cameraPosition.target.longitude),
205
+ center = cameraPosition.target.toRnLatLng(),
214
206
  zoom = cameraPosition.zoom.toDouble(),
215
207
  bearing = cameraPosition.bearing.toDouble(),
216
208
  tilt = cameraPosition.tilt.toDouble(),
@@ -233,12 +225,12 @@ class GoogleMapsViewImpl(
233
225
 
234
226
  onCameraChangeComplete?.invoke(
235
227
  RNRegion(
236
- center = RNLatLng(bounds.center.latitude, bounds.center.longitude),
228
+ center = bounds.center.toRnLatLng(),
237
229
  latitudeDelta = latDelta,
238
230
  longitudeDelta = lngDelta,
239
231
  ),
240
232
  RNCamera(
241
- center = RNLatLng(cameraPosition.target.latitude, cameraPosition.target.longitude),
233
+ center = cameraPosition.target.toRnLatLng(),
242
234
  zoom = cameraPosition.zoom.toDouble(),
243
235
  bearing = cameraPosition.bearing.toDouble(),
244
236
  tilt = cameraPosition.tilt.toDouble(),
@@ -544,7 +536,7 @@ class GoogleMapsViewImpl(
544
536
  onUi {
545
537
  val builder = LatLngBounds.Builder()
546
538
  coordinates.forEach { coord ->
547
- builder.include(LatLng(coord.latitude, coord.longitude))
539
+ builder.include(coord.toLatLng())
548
540
  }
549
541
  val bounds = builder.build()
550
542
 
@@ -1069,28 +1061,28 @@ class GoogleMapsViewImpl(
1069
1061
 
1070
1062
  override fun onMapClick(coordinates: LatLng) {
1071
1063
  onMapPress?.invoke(
1072
- RNLatLng(coordinates.latitude, coordinates.longitude),
1064
+ coordinates.toRnLatLng(),
1073
1065
  )
1074
1066
  }
1075
1067
 
1076
1068
  override fun onMarkerDragStart(marker: Marker) {
1077
1069
  onMarkerDragStart?.invoke(
1078
1070
  marker.tag?.toString(),
1079
- RNLatLng(marker.position.latitude, marker.position.longitude),
1071
+ marker.position.toRnLatLng(),
1080
1072
  )
1081
1073
  }
1082
1074
 
1083
1075
  override fun onMarkerDrag(marker: Marker) {
1084
1076
  onMarkerDrag?.invoke(
1085
1077
  marker.tag?.toString(),
1086
- RNLatLng(marker.position.latitude, marker.position.longitude),
1078
+ marker.position.toRnLatLng(),
1087
1079
  )
1088
1080
  }
1089
1081
 
1090
1082
  override fun onMarkerDragEnd(marker: Marker) {
1091
1083
  onMarkerDragEnd?.invoke(
1092
1084
  marker.tag?.toString(),
1093
- RNLatLng(marker.position.latitude, marker.position.longitude),
1085
+ marker.position.toRnLatLng(),
1094
1086
  )
1095
1087
  }
1096
1088
 
@@ -4,13 +4,13 @@ import android.graphics.Color
4
4
  import com.facebook.react.uimanager.PixelUtil.dpToPx
5
5
  import com.google.android.gms.maps.model.Circle
6
6
  import com.google.android.gms.maps.model.CircleOptions
7
- import com.google.android.gms.maps.model.LatLng
8
7
  import com.rngooglemapsplus.extensions.toColor
8
+ import com.rngooglemapsplus.extensions.toLatLng
9
9
 
10
10
  class MapCircleBuilder {
11
11
  fun build(circle: RNCircle): CircleOptions =
12
12
  CircleOptions().apply {
13
- center(LatLng(circle.center.latitude, circle.center.longitude))
13
+ center(circle.center.toLatLng())
14
14
  radius(circle.radius)
15
15
  circle.strokeWidth?.let { strokeWidth(it.dpToPx()) }
16
16
  circle.strokeColor?.let { strokeColor(it.toColor()) }
@@ -20,14 +20,38 @@ class MapCircleBuilder {
20
20
  }
21
21
 
22
22
  fun update(
23
- circle: Circle,
23
+ prev: RNCircle,
24
24
  next: RNCircle,
25
+ circle: Circle,
25
26
  ) {
26
- circle.center = LatLng(next.center.latitude, next.center.longitude)
27
- circle.radius = next.radius
28
- circle.strokeWidth = next.strokeWidth?.dpToPx() ?: 1f
29
- circle.strokeColor = next.strokeColor?.toColor() ?: Color.BLACK
30
- circle.fillColor = next.fillColor?.toColor() ?: Color.TRANSPARENT
31
- circle.zIndex = next.zIndex?.toFloat() ?: 0f
27
+ if (prev.center.latitude != next.center.latitude ||
28
+ prev.center.longitude != next.center.longitude
29
+ ) {
30
+ circle.center = next.center.toLatLng()
31
+ }
32
+
33
+ if (prev.radius != next.radius) {
34
+ circle.radius = next.radius
35
+ }
36
+
37
+ if (prev.strokeWidth != next.strokeWidth) {
38
+ circle.strokeWidth = next.strokeWidth?.dpToPx() ?: 1f
39
+ }
40
+
41
+ if (prev.strokeColor != next.strokeColor) {
42
+ circle.strokeColor = next.strokeColor?.toColor() ?: Color.BLACK
43
+ }
44
+
45
+ if (prev.fillColor != next.fillColor) {
46
+ circle.fillColor = next.fillColor?.toColor() ?: Color.TRANSPARENT
47
+ }
48
+
49
+ if (prev.pressable != next.pressable) {
50
+ circle.isClickable = next.pressable ?: false
51
+ }
52
+
53
+ if (prev.zIndex != next.zIndex) {
54
+ circle.zIndex = next.zIndex?.toFloat() ?: 0f
55
+ }
32
56
  }
33
57
  }
@@ -8,11 +8,11 @@ import com.caverock.androidsvg.SVG
8
8
  import com.facebook.react.uimanager.PixelUtil.dpToPx
9
9
  import com.google.android.gms.maps.model.BitmapDescriptor
10
10
  import com.google.android.gms.maps.model.BitmapDescriptorFactory
11
- import com.google.android.gms.maps.model.LatLng
12
11
  import com.google.android.gms.maps.model.Marker
13
12
  import com.google.android.gms.maps.model.MarkerOptions
14
13
  import com.rngooglemapsplus.extensions.markerStyleEquals
15
14
  import com.rngooglemapsplus.extensions.styleHash
15
+ import com.rngooglemapsplus.extensions.toLatLng
16
16
  import kotlinx.coroutines.CoroutineScope
17
17
  import kotlinx.coroutines.Dispatchers
18
18
  import kotlinx.coroutines.Job
@@ -40,43 +40,98 @@ class MapMarkerBuilder(
40
40
  icon: BitmapDescriptor?,
41
41
  ): MarkerOptions =
42
42
  MarkerOptions().apply {
43
- position(LatLng(m.coordinate.latitude, m.coordinate.longitude))
43
+ position(m.coordinate.toLatLng())
44
44
  icon(icon)
45
45
  m.title?.let { title(it) }
46
46
  m.snippet?.let { snippet(it) }
47
47
  m.opacity?.let { alpha(it.toFloat()) }
48
48
  m.flat?.let { flat(it) }
49
49
  m.draggable?.let { draggable(it) }
50
+ m.rotation?.let { rotation(it.toFloat()) }
51
+ m.infoWindowAnchor?.let { infoWindowAnchor(it.x.toFloat(), it.y.toFloat()) }
50
52
  m.anchor?.let { anchor((m.anchor.x).toFloat(), (m.anchor.y).toFloat()) }
51
53
  m.zIndex?.let { zIndex(it.toFloat()) }
52
54
  }
53
55
 
54
56
  fun update(
55
- marker: Marker,
56
57
  prev: RNMarker,
57
58
  next: RNMarker,
59
+ marker: Marker,
58
60
  ) {
59
- marker.position =
60
- LatLng(
61
- next.coordinate.latitude,
62
- next.coordinate.longitude,
63
- )
61
+ if (prev.coordinate.latitude != next.coordinate.latitude ||
62
+ prev.coordinate.longitude != next.coordinate.longitude
63
+ ) {
64
+ marker.position = next.coordinate.toLatLng()
65
+ }
64
66
 
65
67
  if (!prev.markerStyleEquals(next)) {
66
68
  buildIconAsync(marker.id, next) { icon ->
67
69
  marker.setIcon(icon)
70
+ if (prev.infoWindowAnchor?.x != next.infoWindowAnchor?.x ||
71
+ prev.infoWindowAnchor?.y != next.infoWindowAnchor?.y
72
+ ) {
73
+ marker.setInfoWindowAnchor(
74
+ (next.infoWindowAnchor?.x ?: 0.5f).toFloat(),
75
+ (next.infoWindowAnchor?.y ?: 0f).toFloat(),
76
+ )
77
+ }
78
+
79
+ if (prev.anchor?.x != next.anchor?.x ||
80
+ prev.anchor?.y != next.anchor?.y
81
+ ) {
82
+ marker.setAnchor(
83
+ (next.anchor?.x ?: 0.5f).toFloat(),
84
+ (next.anchor?.y ?: 1.0f).toFloat(),
85
+ )
86
+ }
68
87
  }
88
+ } else {
89
+ if (prev.infoWindowAnchor?.x != next.infoWindowAnchor?.x ||
90
+ prev.infoWindowAnchor?.y != next.infoWindowAnchor?.y
91
+ ) {
92
+ marker.setInfoWindowAnchor(
93
+ (next.infoWindowAnchor?.x ?: 0.5f).toFloat(),
94
+ (next.infoWindowAnchor?.y ?: 0f).toFloat(),
95
+ )
96
+ }
97
+
98
+ if (prev.anchor?.x != next.anchor?.x ||
99
+ prev.anchor?.y != next.anchor?.y
100
+ ) {
101
+ marker.setAnchor(
102
+ (next.anchor?.x ?: 0.5f).toFloat(),
103
+ (next.anchor?.y ?: 1.0f).toFloat(),
104
+ )
105
+ }
106
+ }
107
+
108
+ if (prev.title != next.title) {
109
+ marker.title = next.title
110
+ }
111
+
112
+ if (prev.snippet != next.snippet) {
113
+ marker.snippet = next.snippet
114
+ }
115
+
116
+ if (prev.opacity != next.opacity) {
117
+ marker.alpha = next.opacity?.toFloat() ?: 1f
118
+ }
119
+
120
+ if (prev.flat != next.flat) {
121
+ marker.isFlat = next.flat ?: false
122
+ }
123
+
124
+ if (prev.draggable != next.draggable) {
125
+ marker.isDraggable = next.draggable ?: false
126
+ }
127
+
128
+ if (prev.rotation != next.rotation) {
129
+ marker.rotation = next.rotation?.toFloat() ?: 0f
130
+ }
131
+
132
+ if (prev.zIndex != next.zIndex) {
133
+ marker.zIndex = next.zIndex?.toFloat() ?: 0f
69
134
  }
70
- marker.title = next.title
71
- marker.snippet = next.snippet
72
- marker.alpha = next.opacity?.toFloat() ?: 0f
73
- marker.isFlat = next.flat ?: false
74
- marker.isDraggable = next.draggable ?: false
75
- marker.setAnchor(
76
- (next.anchor?.x ?: 0.5).toFloat(),
77
- (next.anchor?.y ?: 1.0).toFloat(),
78
- )
79
- marker.zIndex = next.zIndex?.toFloat() ?: 0f
80
135
  }
81
136
 
82
137
  fun buildIconAsync(
@@ -2,38 +2,85 @@ package com.rngooglemapsplus
2
2
 
3
3
  import android.graphics.Color
4
4
  import com.facebook.react.uimanager.PixelUtil.dpToPx
5
- import com.google.android.gms.maps.model.LatLng
6
5
  import com.google.android.gms.maps.model.Polygon
7
6
  import com.google.android.gms.maps.model.PolygonOptions
8
7
  import com.rngooglemapsplus.extensions.toColor
8
+ import com.rngooglemapsplus.extensions.toLatLng
9
9
 
10
10
  class MapPolygonBuilder {
11
11
  fun build(poly: RNPolygon): PolygonOptions =
12
12
  PolygonOptions().apply {
13
13
  poly.coordinates.forEach { pt ->
14
14
  add(
15
- com.google.android.gms.maps.model
16
- .LatLng(pt.latitude, pt.longitude),
15
+ pt.toLatLng(),
17
16
  )
18
17
  }
19
18
  poly.fillColor?.let { fillColor(it.toColor()) }
20
19
  poly.strokeColor?.let { strokeColor(it.toColor()) }
21
20
  poly.strokeWidth?.let { strokeWidth(it.dpToPx()) }
22
21
  poly.pressable?.let { clickable(it) }
22
+ poly.geodesic?.let { geodesic(it) }
23
+ poly.holes?.forEach { hole ->
24
+ addHole(hole.coordinates.map { it.toLatLng() })
25
+ }
23
26
  poly.zIndex?.let { zIndex(it.toFloat()) }
24
27
  }
25
28
 
26
29
  fun update(
27
- gmsPoly: Polygon,
30
+ prev: RNPolygon,
28
31
  next: RNPolygon,
32
+ poly: Polygon,
29
33
  ) {
30
- gmsPoly.points =
31
- next.coordinates.map {
32
- LatLng(it.latitude, it.longitude)
33
- }
34
- gmsPoly.fillColor = next.fillColor?.toColor() ?: Color.TRANSPARENT
35
- gmsPoly.strokeColor = next.strokeColor?.toColor() ?: Color.BLACK
36
- gmsPoly.strokeWidth = next.strokeWidth?.dpToPx() ?: 1f
37
- gmsPoly.zIndex = next.zIndex?.toFloat() ?: 0f
34
+ val coordsChanged =
35
+ prev.coordinates.size != next.coordinates.size ||
36
+ !prev.coordinates.zip(next.coordinates).all { (a, b) ->
37
+ a.latitude == b.latitude && a.longitude == b.longitude
38
+ }
39
+
40
+ if (coordsChanged) {
41
+ poly.points = next.coordinates.map { it.toLatLng() }
42
+ }
43
+
44
+ val prevHoles = prev.holes?.toList() ?: emptyList()
45
+ val nextHoles = next.holes?.toList() ?: emptyList()
46
+ val holesChanged =
47
+ prevHoles.size != nextHoles.size ||
48
+ !prevHoles.zip(nextHoles).all { (ha, hb) ->
49
+ ha.coordinates.size == hb.coordinates.size &&
50
+ ha.coordinates.zip(hb.coordinates).all { (a, b) ->
51
+ a.latitude == b.latitude && a.longitude == b.longitude
52
+ }
53
+ }
54
+
55
+ if (holesChanged) {
56
+ poly.holes =
57
+ nextHoles.map { hole ->
58
+ hole.coordinates.map { it.toLatLng() }
59
+ }
60
+ }
61
+
62
+ if (prev.fillColor != next.fillColor) {
63
+ poly.fillColor = next.fillColor?.toColor() ?: Color.TRANSPARENT
64
+ }
65
+
66
+ if (prev.strokeColor != next.strokeColor) {
67
+ poly.strokeColor = next.strokeColor?.toColor() ?: Color.BLACK
68
+ }
69
+
70
+ if (prev.strokeWidth != next.strokeWidth) {
71
+ poly.strokeWidth = next.strokeWidth?.dpToPx() ?: 1f
72
+ }
73
+
74
+ if (prev.pressable != next.pressable) {
75
+ poly.isClickable = next.pressable ?: false
76
+ }
77
+
78
+ if (prev.geodesic != next.geodesic) {
79
+ poly.isGeodesic = next.geodesic ?: false
80
+ }
81
+
82
+ if (prev.zIndex != next.zIndex) {
83
+ poly.zIndex = next.zIndex?.toFloat() ?: 0f
84
+ }
38
85
  }
39
86
  }
@@ -5,18 +5,18 @@ import com.facebook.react.uimanager.PixelUtil.dpToPx
5
5
  import com.google.android.gms.maps.model.ButtCap
6
6
  import com.google.android.gms.maps.model.Cap
7
7
  import com.google.android.gms.maps.model.JointType
8
- import com.google.android.gms.maps.model.LatLng
9
8
  import com.google.android.gms.maps.model.Polyline
10
9
  import com.google.android.gms.maps.model.PolylineOptions
11
10
  import com.google.android.gms.maps.model.RoundCap
12
11
  import com.google.android.gms.maps.model.SquareCap
13
12
  import com.rngooglemapsplus.extensions.toColor
13
+ import com.rngooglemapsplus.extensions.toLatLng
14
14
 
15
15
  class MapPolylineBuilder {
16
16
  fun build(pl: RNPolyline): PolylineOptions =
17
17
  PolylineOptions().apply {
18
18
  pl.coordinates.forEach { pt ->
19
- add(LatLng(pt.latitude, pt.longitude))
19
+ add(pt.toLatLng())
20
20
  }
21
21
  pl.width?.let { width(it.dpToPx()) }
22
22
  pl.lineCap?.let {
@@ -25,23 +25,58 @@ class MapPolylineBuilder {
25
25
  }
26
26
  pl.lineJoin?.let { jointType(mapLineJoin(it)) }
27
27
  pl.color?.let { color(it.toColor()) }
28
+ pl.geodesic?.let { geodesic(it) }
28
29
  pl.pressable?.let { clickable(it) }
29
30
  pl.zIndex?.let { zIndex(it.toFloat()) }
30
31
  }
31
32
 
32
33
  fun update(
33
- polyline: Polyline,
34
+ prev: RNPolyline,
34
35
  next: RNPolyline,
36
+ polyline: Polyline,
35
37
  ) {
36
- polyline.points = next.coordinates.map { LatLng(it.latitude, it.longitude) }
37
-
38
- polyline.width = next.width?.dpToPx() ?: 1f
39
- val cap = mapLineCap(next.lineCap ?: RNLineCapType.BUTT)
40
- polyline.startCap = cap
41
- polyline.endCap = cap
42
- polyline.jointType = mapLineJoin(next.lineJoin ?: RNLineJoinType.MITER)
43
- polyline.color = next.color?.toColor() ?: Color.BLACK
44
- polyline.zIndex = next.zIndex?.toFloat() ?: 0f
38
+ val coordsChanged =
39
+ prev.coordinates.size != next.coordinates.size ||
40
+ !prev.coordinates.zip(next.coordinates).all { (a, b) ->
41
+ a.latitude == b.latitude && a.longitude == b.longitude
42
+ }
43
+
44
+ if (coordsChanged) {
45
+ polyline.points = next.coordinates.map { it.toLatLng() }
46
+ }
47
+
48
+ if (prev.width != next.width) {
49
+ polyline.width = next.width?.dpToPx() ?: 1f
50
+ }
51
+
52
+ val newCap = mapLineCap(next.lineCap ?: RNLineCapType.BUTT)
53
+ val prevCap = mapLineCap(prev.lineCap ?: RNLineCapType.BUTT)
54
+ if (newCap != prevCap) {
55
+ polyline.startCap = newCap
56
+ polyline.endCap = newCap
57
+ }
58
+
59
+ val newJoin = mapLineJoin(next.lineJoin ?: RNLineJoinType.MITER)
60
+ val prevJoin = mapLineJoin(prev.lineJoin ?: RNLineJoinType.MITER)
61
+ if (newJoin != prevJoin) {
62
+ polyline.jointType = newJoin
63
+ }
64
+
65
+ if (prev.color != next.color) {
66
+ polyline.color = next.color?.toColor() ?: Color.BLACK
67
+ }
68
+
69
+ if (prev.pressable != next.pressable) {
70
+ polyline.isClickable = next.pressable ?: false
71
+ }
72
+
73
+ if (prev.geodesic != next.geodesic) {
74
+ polyline.isGeodesic = next.geodesic ?: false
75
+ }
76
+
77
+ if (prev.zIndex != next.zIndex) {
78
+ polyline.zIndex = next.zIndex?.toFloat() ?: 0f
79
+ }
45
80
  }
46
81
 
47
82
  private fun mapLineCap(type: RNLineCapType?): Cap =
@@ -3,6 +3,7 @@ package com.rngooglemapsplus
3
3
  import com.facebook.proguard.annotations.DoNotStrip
4
4
  import com.facebook.react.bridge.UiThreadUtil
5
5
  import com.facebook.react.uimanager.ThemedReactContext
6
+ import com.google.android.gms.maps.GoogleMapOptions
6
7
  import com.google.android.gms.maps.model.MapStyleOptions
7
8
  import com.margelo.nitro.core.Promise
8
9
  import com.rngooglemapsplus.extensions.circleEquals
@@ -40,11 +41,13 @@ class RNGoogleMapsPlusView(
40
41
  super.afterUpdate()
41
42
  if (!propsInitialized) {
42
43
  propsInitialized = true
43
- view.initMapView(
44
- initialProps?.mapId,
45
- initialProps?.liteMode,
46
- initialProps?.camera?.toCameraPosition(),
47
- )
44
+ val options =
45
+ GoogleMapOptions().apply {
46
+ initialProps?.mapId?.let { mapId(it) }
47
+ initialProps?.liteMode?.let { liteMode(it) }
48
+ initialProps?.camera?.let { camera(it.toCameraPosition()) }
49
+ }
50
+ view.initMapView(options)
48
51
  }
49
52
  }
50
53
 
@@ -154,7 +157,7 @@ class RNGoogleMapsPlusView(
154
157
  } else if (!prev.markerEquals(next)) {
155
158
  view.updateMarker(id) { marker ->
156
159
  onUi {
157
- markerBuilder.update(marker, next, prev)
160
+ markerBuilder.update(prev, next, marker)
158
161
  }
159
162
  }
160
163
  }
@@ -178,7 +181,7 @@ class RNGoogleMapsPlusView(
178
181
  } else if (!prev.polylineEquals(next)) {
179
182
  view.updatePolyline(id) { polyline ->
180
183
  onUi {
181
- polylineBuilder.update(polyline, next)
184
+ polylineBuilder.update(prev, next, polyline)
182
185
  }
183
186
  }
184
187
  }
@@ -202,7 +205,7 @@ class RNGoogleMapsPlusView(
202
205
  view.addPolygon(id, polygonBuilder.build(next))
203
206
  } else if (!prev.polygonEquals(next)) {
204
207
  view.updatePolygon(id) { polygon ->
205
- onUi { polygonBuilder.update(polygon, next) }
208
+ onUi { polygonBuilder.update(prev, next, polygon) }
206
209
  }
207
210
  }
208
211
  }
@@ -226,7 +229,7 @@ class RNGoogleMapsPlusView(
226
229
  } else if (!prev.circleEquals(next)) {
227
230
  view.updateCircle(id) { circle ->
228
231
  onUi {
229
- circleBuilder.update(circle, next)
232
+ circleBuilder.update(prev, next, circle)
230
233
  }
231
234
  }
232
235
  }
@@ -0,0 +1,6 @@
1
+ package com.rngooglemapsplus.extensions
2
+
3
+ import com.google.android.gms.maps.model.LatLng
4
+ import com.rngooglemapsplus.RNLatLng
5
+
6
+ fun LatLng.toRnLatLng(): RNLatLng = RNLatLng(latitude, longitude)
@@ -1,14 +1,13 @@
1
1
  package com.rngooglemapsplus.extensions
2
2
 
3
3
  import com.google.android.gms.maps.model.CameraPosition
4
- import com.google.android.gms.maps.model.LatLng
5
4
  import com.rngooglemapsplus.RNCamera
6
5
 
7
6
  fun RNCamera.toCameraPosition(): CameraPosition {
8
7
  val builder = CameraPosition.builder()
9
8
 
10
9
  center?.let {
11
- builder.target(LatLng(it.latitude, it.longitude))
10
+ builder.target(it.toLatLng())
12
11
  }
13
12
 
14
13
  zoom?.let { builder.zoom(it.toFloat()) }
@@ -0,0 +1,6 @@
1
+ package com.rngooglemapsplus.extensions
2
+
3
+ import com.google.android.gms.maps.model.LatLng
4
+ import com.rngooglemapsplus.RNLatLng
5
+
6
+ fun RNLatLng.toLatLng(): LatLng = LatLng(latitude, longitude)
@@ -7,6 +7,14 @@ fun RNMarker.markerEquals(b: RNMarker): Boolean =
7
7
  zIndex == b.zIndex &&
8
8
  coordinate == b.coordinate &&
9
9
  anchor == b.anchor &&
10
+ showInfoWindow == b.showInfoWindow &&
11
+ title == b.title &&
12
+ snippet == b.snippet &&
13
+ opacity == b.opacity &&
14
+ flat == b.flat &&
15
+ draggable == b.draggable &&
16
+ rotation == b.rotation &&
17
+ infoWindowAnchor == b.infoWindowAnchor &&
10
18
  markerStyleEquals(b)
11
19
 
12
20
  fun RNMarker.markerStyleEquals(b: RNMarker): Boolean = iconSvg == b.iconSvg
@@ -8,6 +8,8 @@ fun RNPolygon.polygonEquals(b: RNPolygon): Boolean {
8
8
  if (strokeWidth != b.strokeWidth) return false
9
9
  if (fillColor != b.fillColor) return false
10
10
  if (strokeColor != b.strokeColor) return false
11
+ if (geodesic != b.geodesic) return false
12
+ if (!holes.contentEquals(b.holes)) return false
11
13
  val ac = coordinates
12
14
  val bc = b.coordinates
13
15
  if (ac.size != bc.size) return false
@@ -8,6 +8,7 @@ fun RNPolyline.polylineEquals(b: RNPolyline): Boolean {
8
8
  if ((width ?: 0.0) != (b.width ?: 0.0)) return false
9
9
  if (lineCap != b.lineCap) return false
10
10
  if (lineJoin != b.lineJoin) return false
11
+ if (geodesic != b.geodesic) return false
11
12
  if (color != b.color) return false
12
13
  val ac = coordinates
13
14
  val bc = b.coordinates