react-native-google-maps-plus 1.7.0-dev.6 → 1.7.0-dev.8

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 (35) hide show
  1. package/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt +354 -487
  2. package/android/src/main/java/com/rngooglemapsplus/MapCircleBuilder.kt +2 -1
  3. package/android/src/main/java/com/rngooglemapsplus/MapHeatmapBuilder.kt +1 -1
  4. package/android/src/main/java/com/rngooglemapsplus/MapHelper.kt +22 -0
  5. package/android/src/main/java/com/rngooglemapsplus/MapMarkerBuilder.kt +4 -2
  6. package/android/src/main/java/com/rngooglemapsplus/MapPolygonBuilder.kt +2 -1
  7. package/android/src/main/java/com/rngooglemapsplus/MapPolylineBuilder.kt.kt +2 -1
  8. package/android/src/main/java/com/rngooglemapsplus/RNGoogleMapsPlusView.kt +11 -22
  9. package/ios/GoogleMapViewImpl.swift +8 -2
  10. package/ios/MapCircleBuilder.swift +2 -0
  11. package/ios/MapHeatmapBuilder.swift +2 -1
  12. package/ios/MapMarkerBuilder.swift +4 -0
  13. package/ios/MapPolygonBuilder.swift +2 -0
  14. package/ios/MapPolylineBuilder.swift +2 -0
  15. package/ios/MapUrlTileOverlayBuilder.swift +1 -0
  16. package/ios/RNGoogleMapsPlusView.swift +5 -5
  17. package/lib/typescript/src/RNGoogleMapsPlusView.nitro.d.ts +1 -1
  18. package/lib/typescript/src/RNGoogleMapsPlusView.nitro.d.ts.map +1 -1
  19. package/nitrogen/generated/android/RNGoogleMapsPlusOnLoad.cpp +2 -0
  20. package/nitrogen/generated/android/c++/JFunc_void_RNRegion_RNCamera.hpp +83 -0
  21. package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.cpp +19 -18
  22. package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.hpp +2 -2
  23. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/Func_void_RNRegion_RNCamera.kt +81 -0
  24. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/HybridRNGoogleMapsPlusViewSpec.kt +3 -3
  25. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Bridge.cpp +8 -0
  26. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Bridge.hpp +29 -7
  27. package/nitrogen/generated/ios/c++/HybridRNGoogleMapsPlusViewSpecSwift.hpp +8 -8
  28. package/nitrogen/generated/ios/swift/Func_void_RNRegion_RNCamera.swift +47 -0
  29. package/nitrogen/generated/ios/swift/HybridRNGoogleMapsPlusViewSpec.swift +1 -1
  30. package/nitrogen/generated/ios/swift/HybridRNGoogleMapsPlusViewSpec_cxx.swift +12 -12
  31. package/nitrogen/generated/shared/c++/HybridRNGoogleMapsPlusViewSpec.hpp +8 -8
  32. package/nitrogen/generated/shared/c++/views/HybridRNGoogleMapsPlusViewComponent.cpp +2 -2
  33. package/nitrogen/generated/shared/c++/views/HybridRNGoogleMapsPlusViewComponent.hpp +3 -3
  34. package/package.json +4 -2
  35. package/src/RNGoogleMapsPlusView.nitro.ts +1 -1
@@ -8,7 +8,6 @@ import android.util.Size
8
8
  import android.widget.FrameLayout
9
9
  import androidx.core.graphics.scale
10
10
  import com.facebook.react.bridge.LifecycleEventListener
11
- import com.facebook.react.bridge.UiThreadUtil
12
11
  import com.facebook.react.uimanager.PixelUtil.dpToPx
13
12
  import com.facebook.react.uimanager.ThemedReactContext
14
13
  import com.google.android.gms.maps.CameraUpdateFactory
@@ -34,6 +33,8 @@ import com.google.android.gms.maps.model.TileOverlay
34
33
  import com.google.android.gms.maps.model.TileOverlayOptions
35
34
  import com.google.maps.android.data.kml.KmlLayer
36
35
  import com.margelo.nitro.core.Promise
36
+ import com.rngooglemapsplus.extensions.onUi
37
+ import com.rngooglemapsplus.extensions.onUiSync
37
38
  import com.rngooglemapsplus.extensions.toGooglePriority
38
39
  import com.rngooglemapsplus.extensions.toLatLng
39
40
  import com.rngooglemapsplus.extensions.toLocationErrorCode
@@ -75,6 +76,7 @@ class GoogleMapsViewImpl(
75
76
  GoogleMap.OnMyLocationButtonClickListener,
76
77
  LifecycleEventListener {
77
78
  private var initialized = false
79
+ private var loaded = false
78
80
  private var destroyed = false
79
81
  private var googleMap: GoogleMap? = null
80
82
  private var mapView: MapView? = null
@@ -101,101 +103,102 @@ class GoogleMapsViewImpl(
101
103
  reactContext.addLifecycleEventListener(this)
102
104
  }
103
105
 
104
- fun initMapView(googleMapsOptions: GoogleMapOptions) {
105
- if (initialized) return
106
- initialized = true
107
- val result = playServiceHandler.playServicesAvailability()
108
- val errorCode = result.toRNMapErrorCodeOrNull()
106
+ fun initMapView(googleMapsOptions: GoogleMapOptions) =
107
+ onUi {
108
+ if (initialized) return@onUi
109
+ initialized = true
109
110
 
110
- if (errorCode != null) {
111
- onMapError?.invoke(errorCode)
111
+ val result = playServiceHandler.playServicesAvailability()
112
+ val errorCode = result.toRNMapErrorCodeOrNull()
113
+ if (errorCode != null) {
114
+ onMapError?.invoke(errorCode)
115
+ if (errorCode == RNMapErrorCode.PLAY_SERVICES_MISSING ||
116
+ errorCode == RNMapErrorCode.PLAY_SERVICES_INVALID
117
+ ) {
118
+ return@onUi
119
+ }
120
+ }
112
121
 
113
- if (errorCode == RNMapErrorCode.PLAY_SERVICES_MISSING ||
114
- errorCode == RNMapErrorCode.PLAY_SERVICES_INVALID
115
- ) {
116
- return
122
+ mapView = MapView(reactContext, googleMapsOptions)
123
+ super.addView(mapView)
124
+
125
+ mapView?.onCreate(null)
126
+ mapView?.getMapAsync { map ->
127
+ googleMap = map
128
+ googleMap?.setOnMapLoadedCallback {
129
+ googleMap?.setOnCameraMoveStartedListener(this@GoogleMapsViewImpl)
130
+ googleMap?.setOnCameraMoveListener(this@GoogleMapsViewImpl)
131
+ googleMap?.setOnCameraIdleListener(this@GoogleMapsViewImpl)
132
+ googleMap?.setOnMarkerClickListener(this@GoogleMapsViewImpl)
133
+ googleMap?.setOnPolylineClickListener(this@GoogleMapsViewImpl)
134
+ googleMap?.setOnPolygonClickListener(this@GoogleMapsViewImpl)
135
+ googleMap?.setOnCircleClickListener(this@GoogleMapsViewImpl)
136
+ googleMap?.setOnMapClickListener(this@GoogleMapsViewImpl)
137
+ googleMap?.setOnMapLongClickListener(this@GoogleMapsViewImpl)
138
+ googleMap?.setOnPoiClickListener(this@GoogleMapsViewImpl)
139
+ googleMap?.setOnMarkerDragListener(this@GoogleMapsViewImpl)
140
+ googleMap?.setOnInfoWindowClickListener(this@GoogleMapsViewImpl)
141
+ googleMap?.setOnInfoWindowCloseListener(this@GoogleMapsViewImpl)
142
+ googleMap?.setOnInfoWindowLongClickListener(this@GoogleMapsViewImpl)
143
+ googleMap?.setOnMyLocationClickListener(this@GoogleMapsViewImpl)
144
+ googleMap?.setOnMyLocationButtonClickListener(this@GoogleMapsViewImpl)
145
+ loaded = true
146
+ onMapLoaded?.invoke(
147
+ map.projection.visibleRegion.toRnRegion(),
148
+ map.cameraPosition.toRnCamera(),
149
+ )
150
+ }
151
+ applyProps()
152
+ initLocationCallbacks()
153
+ onMapReady?.invoke(true)
117
154
  }
118
155
  }
119
156
 
120
- mapView =
121
- MapView(
122
- reactContext,
123
- googleMapsOptions,
157
+ override fun onCameraMoveStarted(reason: Int) =
158
+ onUi {
159
+ if (!loaded) return@onUi
160
+ cameraMoveReason = reason
161
+ val visibleRegion = googleMap?.projection?.visibleRegion ?: return@onUi
162
+ val cameraPosition = googleMap?.cameraPosition ?: return@onUi
163
+ onCameraChangeStart?.invoke(
164
+ visibleRegion.toRnRegion(),
165
+ cameraPosition.toRnCamera(),
166
+ GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == reason,
124
167
  )
125
-
126
- super.addView(mapView)
127
-
128
- mapView?.onCreate(null)
129
- mapView?.getMapAsync { map ->
130
- googleMap = map
131
- googleMap?.setOnMapLoadedCallback {
132
- googleMap?.setOnCameraMoveStartedListener(this@GoogleMapsViewImpl)
133
- googleMap?.setOnCameraMoveListener(this@GoogleMapsViewImpl)
134
- googleMap?.setOnCameraIdleListener(this@GoogleMapsViewImpl)
135
- googleMap?.setOnMarkerClickListener(this@GoogleMapsViewImpl)
136
- googleMap?.setOnPolylineClickListener(this@GoogleMapsViewImpl)
137
- googleMap?.setOnPolygonClickListener(this@GoogleMapsViewImpl)
138
- googleMap?.setOnCircleClickListener(this@GoogleMapsViewImpl)
139
- googleMap?.setOnMapClickListener(this@GoogleMapsViewImpl)
140
- googleMap?.setOnMapLongClickListener(this@GoogleMapsViewImpl)
141
- googleMap?.setOnPoiClickListener(this@GoogleMapsViewImpl)
142
- googleMap?.setOnMarkerDragListener(this@GoogleMapsViewImpl)
143
- googleMap?.setOnInfoWindowClickListener(this@GoogleMapsViewImpl)
144
- googleMap?.setOnInfoWindowCloseListener(this@GoogleMapsViewImpl)
145
- googleMap?.setOnInfoWindowLongClickListener(this@GoogleMapsViewImpl)
146
- googleMap?.setOnMyLocationClickListener(this@GoogleMapsViewImpl)
147
- googleMap?.setOnMyLocationButtonClickListener(this@GoogleMapsViewImpl)
148
- onMapLoaded?.invoke(true)
149
- }
150
- applyProps()
151
- initLocationCallbacks()
152
- onMapReady?.invoke(true)
153
168
  }
154
- }
155
-
156
- override fun onCameraMoveStarted(reason: Int) {
157
- cameraMoveReason = reason
158
- val visibleRegion = googleMap?.projection?.visibleRegion ?: return
159
- val cameraPosition = googleMap?.cameraPosition ?: return
160
-
161
- onCameraChangeStart?.invoke(
162
- visibleRegion.toRnRegion(),
163
- cameraPosition.toRnCamera(),
164
- GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == reason,
165
- )
166
- }
167
-
168
- override fun onCameraMove() {
169
- val visibleRegion = googleMap?.projection?.visibleRegion ?: return
170
- val cameraPosition = googleMap?.cameraPosition ?: return
171
- val gesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason
172
-
173
- onCameraChange?.invoke(
174
- visibleRegion.toRnRegion(),
175
- cameraPosition.toRnCamera(),
176
- gesture,
177
- )
178
- }
179
169
 
180
- override fun onCameraIdle() {
181
- val visibleRegion = googleMap?.projection?.visibleRegion ?: return
182
- val cameraPosition = googleMap?.cameraPosition ?: return
183
- val gesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason
170
+ override fun onCameraMove() =
171
+ onUi {
172
+ if (!loaded) return@onUi
173
+ val visibleRegion = googleMap?.projection?.visibleRegion ?: return@onUi
174
+ val cameraPosition = googleMap?.cameraPosition ?: return@onUi
175
+ val gesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason
176
+ onCameraChange?.invoke(
177
+ visibleRegion.toRnRegion(),
178
+ cameraPosition.toRnCamera(),
179
+ gesture,
180
+ )
181
+ }
184
182
 
185
- onCameraChangeComplete?.invoke(
186
- visibleRegion.toRnRegion(),
187
- cameraPosition.toRnCamera(),
188
- gesture,
189
- )
190
- }
183
+ override fun onCameraIdle() =
184
+ onUi {
185
+ if (!loaded) return@onUi
186
+ val visibleRegion = googleMap?.projection?.visibleRegion ?: return@onUi
187
+ val cameraPosition = googleMap?.cameraPosition ?: return@onUi
188
+ val gesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason
189
+ onCameraChangeComplete?.invoke(
190
+ visibleRegion.toRnRegion(),
191
+ cameraPosition.toRnCamera(),
192
+ gesture,
193
+ )
194
+ }
191
195
 
192
196
  fun initLocationCallbacks() {
193
197
  locationHandler.onUpdate = { location ->
194
- onLocationUpdate?.invoke(location.toRnLocation())
198
+ onUi { onLocationUpdate?.invoke(location.toRnLocation()) }
195
199
  }
196
-
197
200
  locationHandler.onError = { error ->
198
- onLocationError?.invoke(error)
201
+ onUi { onLocationError?.invoke(error) }
199
202
  }
200
203
  locationHandler.start()
201
204
  }
@@ -214,57 +217,37 @@ class GoogleMapsViewImpl(
214
217
  locationConfig = locationConfig
215
218
 
216
219
  if (pendingMarkers.isNotEmpty()) {
217
- pendingMarkers.forEach { (id, opts) ->
218
- internalAddMarker(id, opts)
219
- }
220
+ pendingMarkers.forEach { (id, opts) -> internalAddMarker(id, opts) }
220
221
  pendingMarkers.clear()
221
222
  }
222
-
223
223
  if (pendingPolylines.isNotEmpty()) {
224
- pendingPolylines.forEach { (id, opts) ->
225
- internalAddPolyline(id, opts)
226
- }
224
+ pendingPolylines.forEach { (id, opts) -> internalAddPolyline(id, opts) }
227
225
  pendingPolylines.clear()
228
226
  }
229
-
230
227
  if (pendingPolygons.isNotEmpty()) {
231
- pendingPolygons.forEach { (id, opts) ->
232
- internalAddPolygon(id, opts)
233
- }
228
+ pendingPolygons.forEach { (id, opts) -> internalAddPolygon(id, opts) }
234
229
  pendingPolygons.clear()
235
230
  }
236
-
237
231
  if (pendingCircles.isNotEmpty()) {
238
- pendingCircles.forEach { (id, opts) ->
239
- internalAddCircle(id, opts)
240
- }
232
+ pendingCircles.forEach { (id, opts) -> internalAddCircle(id, opts) }
241
233
  pendingCircles.clear()
242
234
  }
243
-
244
235
  if (pendingHeatmaps.isNotEmpty()) {
245
- pendingHeatmaps.forEach { (id, opts) ->
246
- internalAddHeatmap(id, opts)
247
- }
236
+ pendingHeatmaps.forEach { (id, opts) -> internalAddHeatmap(id, opts) }
248
237
  pendingHeatmaps.clear()
249
238
  }
250
-
251
239
  if (pendingKmlLayers.isNotEmpty()) {
252
- pendingKmlLayers.forEach { (id, string) ->
253
- internalAddKmlLayer(id, string)
254
- }
240
+ pendingKmlLayers.forEach { (id, str) -> internalAddKmlLayer(id, str) }
255
241
  pendingKmlLayers.clear()
256
242
  }
257
-
258
243
  if (pendingUrlTilesOverlays.isNotEmpty()) {
259
- pendingUrlTilesOverlays.forEach { (id, string) ->
260
- internalAddUrlTileOverlay(id, string)
261
- }
244
+ pendingUrlTilesOverlays.forEach { (id, opts) -> internalAddUrlTileOverlay(id, opts) }
262
245
  pendingUrlTilesOverlays.clear()
263
246
  }
264
247
  }
265
248
 
266
249
  val currentCamera: CameraPosition?
267
- get() = googleMap?.cameraPosition
250
+ get() = onUiSync { googleMap?.cameraPosition }
268
251
 
269
252
  var initialProps: RNInitialProps? = null
270
253
 
@@ -300,8 +283,8 @@ class GoogleMapsViewImpl(
300
283
  onUi {
301
284
  try {
302
285
  googleMap?.isMyLocationEnabled = value ?: false
303
- } catch (se: SecurityException) {
304
- onLocationError?.invoke(RNLocationErrorCode.PERMISSION_DENIED)
286
+ } catch (_: SecurityException) {
287
+ onLocationError?.let { cb -> cb(RNLocationErrorCode.PERMISSION_DENIED) }
305
288
  } catch (ex: Exception) {
306
289
  val error = ex.toLocationErrorCode(context)
307
290
  onLocationError?.invoke(error)
@@ -312,41 +295,31 @@ class GoogleMapsViewImpl(
312
295
  var buildingEnabled: Boolean? = null
313
296
  set(value) {
314
297
  field = value
315
- onUi {
316
- googleMap?.isBuildingsEnabled = value ?: false
317
- }
298
+ onUi { googleMap?.isBuildingsEnabled = value ?: false }
318
299
  }
319
300
 
320
301
  var trafficEnabled: Boolean? = null
321
302
  set(value) {
322
303
  field = value
323
- onUi {
324
- googleMap?.isTrafficEnabled = value ?: false
325
- }
304
+ onUi { googleMap?.isTrafficEnabled = value ?: false }
326
305
  }
327
306
 
328
307
  var indoorEnabled: Boolean? = null
329
308
  set(value) {
330
309
  field = value
331
- onUi {
332
- googleMap?.isIndoorEnabled = value ?: false
333
- }
310
+ onUi { googleMap?.isIndoorEnabled = value ?: false }
334
311
  }
335
312
 
336
313
  var customMapStyle: MapStyleOptions? = null
337
314
  set(value) {
338
315
  field = value
339
- onUi {
340
- googleMap?.setMapStyle(value)
341
- }
316
+ onUi { googleMap?.setMapStyle(value) }
342
317
  }
343
318
 
344
319
  var userInterfaceStyle: Int? = null
345
320
  set(value) {
346
321
  field = value
347
- onUi {
348
- googleMap?.mapColorScheme = value ?: MapColorScheme.FOLLOW_SYSTEM
349
- }
322
+ onUi { googleMap?.mapColorScheme = value ?: MapColorScheme.FOLLOW_SYSTEM }
350
323
  }
351
324
 
352
325
  var mapZoomConfig: RNMapZoomConfig? = null
@@ -374,9 +347,7 @@ class GoogleMapsViewImpl(
374
347
  var mapType: Int? = null
375
348
  set(value) {
376
349
  field = value
377
- onUi {
378
- googleMap?.mapType = value ?: 1
379
- }
350
+ onUi { googleMap?.mapType = value ?: 1 }
380
351
  }
381
352
 
382
353
  var locationConfig: RNLocationConfig? = null
@@ -391,7 +362,7 @@ class GoogleMapsViewImpl(
391
362
 
392
363
  var onMapError: ((RNMapErrorCode) -> Unit)? = null
393
364
  var onMapReady: ((Boolean) -> Unit)? = null
394
- var onMapLoaded: ((Boolean) -> Unit)? = null
365
+ var onMapLoaded: ((RNRegion, RNCamera) -> Unit)? = null
395
366
  var onLocationUpdate: ((RNLocation) -> Unit)? = null
396
367
  var onLocationError: ((RNLocationErrorCode) -> Unit)? = null
397
368
  var onMapPress: ((RNLatLng) -> Unit)? = null
@@ -419,15 +390,12 @@ class GoogleMapsViewImpl(
419
390
  cameraPosition: CameraPosition,
420
391
  animated: Boolean,
421
392
  durationMs: Int,
422
- ) {
423
- onUi {
424
- val update = CameraUpdateFactory.newCameraPosition(cameraPosition)
425
-
426
- if (animated) {
427
- googleMap?.animateCamera(update, durationMs, null)
428
- } else {
429
- googleMap?.moveCamera(update)
430
- }
393
+ ) = onUi {
394
+ val update = CameraUpdateFactory.newCameraPosition(cameraPosition)
395
+ if (animated) {
396
+ googleMap?.animateCamera(update, durationMs, null)
397
+ } else {
398
+ googleMap?.moveCamera(update)
431
399
  }
432
400
  }
433
401
 
@@ -436,93 +404,81 @@ class GoogleMapsViewImpl(
436
404
  padding: RNMapPadding,
437
405
  animated: Boolean,
438
406
  durationMs: Int,
439
- ) {
440
- if (coordinates.isEmpty()) {
441
- return
442
- }
443
- onUi {
444
- val builder = LatLngBounds.Builder()
445
- coordinates.forEach { coord ->
446
- builder.include(coord.toLatLng())
447
- }
448
- val bounds = builder.build()
449
-
450
- val latSpan = bounds.northeast.latitude - bounds.southwest.latitude
451
- val lngSpan = bounds.northeast.longitude - bounds.southwest.longitude
452
-
453
- val latPerPixel = latSpan / (mapView?.height ?: 0)
454
- val lngPerPixel = lngSpan / (mapView?.width ?: 0)
407
+ ) = onUi {
408
+ if (coordinates.isEmpty()) return@onUi
409
+ val builder = LatLngBounds.Builder()
410
+ coordinates.forEach { coord -> builder.include(coord.toLatLng()) }
411
+ val bounds = builder.build()
412
+
413
+ val latSpan = bounds.northeast.latitude - bounds.southwest.latitude
414
+ val lngSpan = bounds.northeast.longitude - bounds.southwest.longitude
415
+
416
+ val h = (mapView?.height ?: 0)
417
+ val w = (mapView?.width ?: 0)
418
+ val latPerPixel = if (h != 0) latSpan / h else 0.0
419
+ val lngPerPixel = if (w != 0) lngSpan / w else 0.0
420
+
421
+ builder.include(
422
+ LatLng(
423
+ bounds.northeast.latitude + (padding.top.dpToPx() * latPerPixel),
424
+ bounds.northeast.longitude,
425
+ ),
426
+ )
427
+ builder.include(
428
+ LatLng(
429
+ bounds.southwest.latitude - (padding.bottom.dpToPx() * latPerPixel),
430
+ bounds.southwest.longitude,
431
+ ),
432
+ )
433
+ builder.include(
434
+ LatLng(
435
+ bounds.northeast.latitude,
436
+ bounds.northeast.longitude + (padding.right.dpToPx() * lngPerPixel),
437
+ ),
438
+ )
439
+ builder.include(
440
+ LatLng(
441
+ bounds.southwest.latitude,
442
+ bounds.southwest.longitude - (padding.left.dpToPx() * lngPerPixel),
443
+ ),
444
+ )
455
445
 
456
- builder.include(
457
- LatLng(
458
- bounds.northeast.latitude + (padding.top.dpToPx() * latPerPixel),
459
- bounds.northeast.longitude,
460
- ),
461
- )
462
- builder.include(
463
- LatLng(
464
- bounds.southwest.latitude - (padding.bottom.dpToPx() * latPerPixel),
465
- bounds.southwest.longitude,
466
- ),
446
+ val paddedBounds = builder.build()
447
+ val adjustedWidth =
448
+ (w - padding.left.dpToPx() - padding.right.dpToPx()).toInt().coerceAtLeast(0)
449
+ val adjustedHeight =
450
+ (h - padding.top.dpToPx() - padding.bottom.dpToPx()).toInt().coerceAtLeast(0)
451
+
452
+ val update =
453
+ CameraUpdateFactory.newLatLngBounds(
454
+ paddedBounds,
455
+ adjustedWidth,
456
+ adjustedHeight,
457
+ 0,
467
458
  )
468
- builder.include(
469
- LatLng(
470
- bounds.northeast.latitude,
471
- bounds.northeast.longitude + (padding.right.dpToPx() * lngPerPixel),
472
- ),
473
- )
474
- builder.include(
475
- LatLng(
476
- bounds.southwest.latitude,
477
- bounds.southwest.longitude - (padding.left.dpToPx() * lngPerPixel),
478
- ),
479
- )
480
-
481
- val paddedBounds = builder.build()
482
-
483
- val adjustedWidth =
484
- ((mapView?.width ?: 0) - padding.left.dpToPx() - padding.right.dpToPx()).toInt()
485
- val adjustedHeight =
486
- ((mapView?.height ?: 0) - padding.top.dpToPx() - padding.bottom.dpToPx()).toInt()
487
-
488
- val update =
489
- CameraUpdateFactory.newLatLngBounds(
490
- paddedBounds,
491
- adjustedWidth,
492
- adjustedHeight,
493
- 0,
494
- )
495
- if (animated) {
496
- googleMap?.animateCamera(update, durationMs, null)
497
- } else {
498
- googleMap?.moveCamera(update)
499
- }
459
+ if (animated) {
460
+ googleMap?.animateCamera(update, durationMs, null)
461
+ } else {
462
+ googleMap?.moveCamera(update)
500
463
  }
501
464
  }
502
465
 
503
- fun setCameraBounds(bounds: LatLngBounds?) {
466
+ fun setCameraBounds(bounds: LatLngBounds?) =
504
467
  onUi {
505
468
  googleMap?.setLatLngBoundsForCameraTarget(bounds)
506
469
  }
507
- }
508
470
 
509
471
  fun animateToBounds(
510
472
  bounds: LatLngBounds,
511
473
  padding: Int,
512
474
  durationMs: Int,
513
475
  lockBounds: Boolean,
514
- ) {
515
- onUi {
516
- if (lockBounds) {
517
- googleMap?.setLatLngBoundsForCameraTarget(bounds)
518
- }
519
- val update =
520
- CameraUpdateFactory.newLatLngBounds(
521
- bounds,
522
- padding,
523
- )
524
- googleMap?.animateCamera(update, durationMs, null)
476
+ ) = onUi {
477
+ if (lockBounds) {
478
+ googleMap?.setLatLngBoundsForCameraTarget(bounds)
525
479
  }
480
+ val update = CameraUpdateFactory.newLatLngBounds(bounds, padding)
481
+ googleMap?.animateCamera(update, durationMs, null)
526
482
  }
527
483
 
528
484
  fun snapshot(
@@ -540,12 +496,7 @@ class GoogleMapsViewImpl(
540
496
  promise.resolve(null)
541
497
  return@snapshot
542
498
  }
543
-
544
- val scaledBitmap =
545
- size?.let {
546
- bitmap.scale(it.width, it.height)
547
- } ?: bitmap
548
-
499
+ val scaledBitmap = size?.let { bitmap.scale(it.width, it.height) } ?: bitmap
549
500
  val output = ByteArrayOutputStream()
550
501
  scaledBitmap.compress(compressFormat, (quality * 100).toInt().coerceIn(0, 100), output)
551
502
  val bytes = output.toByteArray()
@@ -559,367 +510,288 @@ class GoogleMapsViewImpl(
559
510
  promise.resolve("data:image/$format;base64,$base64")
560
511
  }
561
512
 
562
- if (scaledBitmap != bitmap) {
563
- scaledBitmap.recycle()
564
- }
513
+ if (scaledBitmap !== bitmap) scaledBitmap.recycle()
565
514
  bitmap.recycle()
566
- } catch (e: Exception) {
515
+ } catch (_: Exception) {
567
516
  promise.resolve(null)
568
517
  }
569
518
  }
570
519
  }
571
-
572
520
  return promise
573
521
  }
574
522
 
575
523
  fun addMarker(
576
524
  id: String,
577
525
  opts: MarkerOptions,
578
- ) {
526
+ ) = onUi {
579
527
  if (googleMap == null) {
580
528
  pendingMarkers.add(id to opts)
581
- return
582
- }
583
-
584
- onUi {
585
- markersById.remove(id)?.remove()
529
+ return@onUi
586
530
  }
531
+ markersById.remove(id)?.remove()
587
532
  internalAddMarker(id, opts)
588
533
  }
589
534
 
590
535
  private fun internalAddMarker(
591
536
  id: String,
592
537
  opts: MarkerOptions,
593
- ) {
594
- onUi {
595
- val marker =
596
- googleMap?.addMarker(opts).also {
597
- it?.tag = id
598
- }
599
- if (marker != null) {
600
- markersById[id] = marker
601
- }
602
- }
538
+ ) = onUi {
539
+ val marker = googleMap?.addMarker(opts).also { it?.tag = id }
540
+ if (marker != null) markersById[id] = marker
603
541
  }
604
542
 
605
543
  fun updateMarker(
606
544
  id: String,
607
545
  block: (Marker) -> Unit,
608
- ) {
609
- val marker = markersById[id] ?: return
610
- onUi {
611
- block(marker)
612
- }
546
+ ) = onUi {
547
+ val marker = markersById[id] ?: return@onUi
548
+ block(marker)
613
549
  }
614
550
 
615
- fun removeMarker(id: String) {
551
+ fun removeMarker(id: String) =
616
552
  onUi {
617
- val marker = markersById.remove(id)
618
- marker?.remove()
553
+ markersById.remove(id)?.remove()
619
554
  }
620
- }
621
555
 
622
- fun clearMarkers() {
556
+ fun clearMarkers() =
623
557
  onUi {
624
558
  markersById.values.forEach { it.remove() }
559
+ markersById.clear()
560
+ pendingMarkers.clear()
625
561
  }
626
- markersById.clear()
627
- pendingMarkers.clear()
628
- }
629
562
 
630
563
  fun addPolyline(
631
564
  id: String,
632
565
  opts: PolylineOptions,
633
- ) {
566
+ ) = onUi {
634
567
  if (googleMap == null) {
635
568
  pendingPolylines.add(id to opts)
636
- return
637
- }
638
- onUi {
639
- polylinesById.remove(id)?.remove()
569
+ return@onUi
640
570
  }
571
+ polylinesById.remove(id)?.remove()
641
572
  internalAddPolyline(id, opts)
642
573
  }
643
574
 
644
575
  private fun internalAddPolyline(
645
576
  id: String,
646
577
  opts: PolylineOptions,
647
- ) {
648
- onUi {
649
- val polyline =
650
- googleMap?.addPolyline(opts).also {
651
- it?.tag = id
652
- }
653
- if (polyline != null) {
654
- polylinesById[id] = polyline
655
- }
656
- }
578
+ ) = onUi {
579
+ val pl = googleMap?.addPolyline(opts).also { it?.tag = id }
580
+ if (pl != null) polylinesById[id] = pl
657
581
  }
658
582
 
659
583
  fun updatePolyline(
660
584
  id: String,
661
585
  block: (Polyline) -> Unit,
662
- ) {
663
- val pl = polylinesById[id] ?: return
664
- onUi {
665
- block(pl)
666
- }
586
+ ) = onUi {
587
+ val pl = polylinesById[id] ?: return@onUi
588
+ block(pl)
667
589
  }
668
590
 
669
- fun removePolyline(id: String) {
591
+ fun removePolyline(id: String) =
670
592
  onUi {
671
593
  polylinesById.remove(id)?.remove()
672
594
  }
673
- }
674
595
 
675
- fun clearPolylines() {
596
+ fun clearPolylines() =
676
597
  onUi {
677
598
  polylinesById.values.forEach { it.remove() }
599
+ polylinesById.clear()
600
+ pendingPolylines.clear()
678
601
  }
679
- polylinesById.clear()
680
- pendingPolylines.clear()
681
- }
682
602
 
683
603
  fun addPolygon(
684
604
  id: String,
685
605
  opts: PolygonOptions,
686
- ) {
606
+ ) = onUi {
687
607
  if (googleMap == null) {
688
608
  pendingPolygons.add(id to opts)
689
- return
690
- }
691
-
692
- onUi {
693
- polygonsById.remove(id)?.remove()
609
+ return@onUi
694
610
  }
611
+ polygonsById.remove(id)?.remove()
695
612
  internalAddPolygon(id, opts)
696
613
  }
697
614
 
698
615
  private fun internalAddPolygon(
699
616
  id: String,
700
617
  opts: PolygonOptions,
701
- ) {
702
- onUi {
703
- val polygon =
704
- googleMap?.addPolygon(opts).also {
705
- it?.tag = id
706
- }
707
- if (polygon != null) {
708
- polygonsById[id] = polygon
709
- }
710
- }
618
+ ) = onUi {
619
+ val polygon = googleMap?.addPolygon(opts).also { it?.tag = id }
620
+ if (polygon != null) polygonsById[id] = polygon
711
621
  }
712
622
 
713
623
  fun updatePolygon(
714
624
  id: String,
715
625
  block: (Polygon) -> Unit,
716
- ) {
717
- val polygon = polygonsById[id] ?: return
718
- onUi {
719
- block(polygon)
720
- }
626
+ ) = onUi {
627
+ val polygon = polygonsById[id] ?: return@onUi
628
+ block(polygon)
721
629
  }
722
630
 
723
- fun removePolygon(id: String) {
631
+ fun removePolygon(id: String) =
724
632
  onUi {
725
633
  polygonsById.remove(id)?.remove()
726
634
  }
727
- }
728
635
 
729
- fun clearPolygons() {
636
+ fun clearPolygons() =
730
637
  onUi {
731
638
  polygonsById.values.forEach { it.remove() }
639
+ polygonsById.clear()
640
+ pendingPolygons.clear()
732
641
  }
733
- polygonsById.clear()
734
- pendingPolygons.clear()
735
- }
736
642
 
737
643
  fun addCircle(
738
644
  id: String,
739
645
  opts: CircleOptions,
740
- ) {
646
+ ) = onUi {
741
647
  if (googleMap == null) {
742
648
  pendingCircles.add(id to opts)
743
- return
744
- }
745
-
746
- onUi {
747
- circlesById.remove(id)?.remove()
649
+ return@onUi
748
650
  }
651
+ circlesById.remove(id)?.remove()
749
652
  internalAddCircle(id, opts)
750
653
  }
751
654
 
752
655
  private fun internalAddCircle(
753
656
  id: String,
754
657
  opts: CircleOptions,
755
- ) {
756
- onUi {
757
- val circle =
758
- googleMap?.addCircle(opts).also {
759
- it?.tag = id
760
- }
761
- if (circle != null) {
762
- circlesById[id] = circle
763
- }
764
- }
658
+ ) = onUi {
659
+ val circle = googleMap?.addCircle(opts).also { it?.tag = id }
660
+ if (circle != null) circlesById[id] = circle
765
661
  }
766
662
 
767
663
  fun updateCircle(
768
664
  id: String,
769
665
  block: (Circle) -> Unit,
770
- ) {
771
- val circle = circlesById[id] ?: return
772
- onUi {
773
- block(circle)
774
- }
666
+ ) = onUi {
667
+ val circle = circlesById[id] ?: return@onUi
668
+ block(circle)
775
669
  }
776
670
 
777
- fun removeCircle(id: String) {
671
+ fun removeCircle(id: String) =
778
672
  onUi {
779
673
  circlesById.remove(id)?.remove()
780
674
  }
781
- }
782
675
 
783
- fun clearCircles() {
676
+ fun clearCircles() =
784
677
  onUi {
785
678
  circlesById.values.forEach { it.remove() }
679
+ circlesById.clear()
680
+ pendingCircles.clear()
786
681
  }
787
- circlesById.clear()
788
- pendingCircles.clear()
789
- }
790
682
 
791
683
  fun addHeatmap(
792
684
  id: String,
793
685
  opts: TileOverlayOptions,
794
- ) {
686
+ ) = onUi {
795
687
  if (googleMap == null) {
796
688
  pendingHeatmaps.add(id to opts)
797
- return
798
- }
799
-
800
- onUi {
801
- heatmapsById.remove(id)?.remove()
689
+ return@onUi
802
690
  }
691
+ heatmapsById.remove(id)?.remove()
803
692
  internalAddHeatmap(id, opts)
804
693
  }
805
694
 
806
695
  private fun internalAddHeatmap(
807
696
  id: String,
808
697
  opts: TileOverlayOptions,
809
- ) {
810
- onUi {
811
- val heatmap =
812
- googleMap?.addTileOverlay(opts)
813
- if (heatmap != null) {
814
- heatmapsById[id] = heatmap
815
- }
816
- }
698
+ ) = onUi {
699
+ val overlay = googleMap?.addTileOverlay(opts)
700
+ if (overlay != null) heatmapsById[id] = overlay
817
701
  }
818
702
 
819
- fun removeHeatmap(id: String) {
703
+ fun removeHeatmap(id: String) =
820
704
  onUi {
821
- heatmapsById.remove(id)?.remove()
705
+ heatmapsById.remove(id)?.let { heatMap ->
706
+ heatMap.clearTileCache()
707
+ heatMap.remove()
708
+ }
822
709
  }
823
- }
824
710
 
825
- fun clearHeatmaps() {
711
+ fun clearHeatmaps() =
826
712
  onUi {
827
713
  heatmapsById.values.forEach { it.remove() }
714
+ heatmapsById.clear()
715
+ pendingHeatmaps.clear()
828
716
  }
829
- heatmapsById.clear()
830
- pendingHeatmaps.clear()
831
- }
832
717
 
833
718
  fun addKmlLayer(
834
719
  id: String,
835
720
  kmlString: String,
836
- ) {
721
+ ) = onUi {
837
722
  if (googleMap == null) {
838
723
  pendingKmlLayers.add(id to kmlString)
839
- return
840
- }
841
- onUi {
842
- kmlLayersById.remove(id)?.removeLayerFromMap()
724
+ return@onUi
843
725
  }
726
+ kmlLayersById.remove(id)?.removeLayerFromMap()
844
727
  internalAddKmlLayer(id, kmlString)
845
728
  }
846
729
 
847
730
  private fun internalAddKmlLayer(
848
731
  id: String,
849
732
  kmlString: String,
850
- ) {
851
- onUi {
852
- try {
853
- val inputStream = ByteArrayInputStream(kmlString.toByteArray(StandardCharsets.UTF_8))
854
- val layer = KmlLayer(googleMap, inputStream, context)
855
- kmlLayersById[id] = layer
856
- layer.addLayerToMap()
857
- } catch (e: Exception) {
858
- // / ignore
859
- }
733
+ ) = onUi {
734
+ try {
735
+ val inputStream = ByteArrayInputStream(kmlString.toByteArray(StandardCharsets.UTF_8))
736
+ val layer = KmlLayer(googleMap, inputStream, context)
737
+ kmlLayersById[id] = layer
738
+ layer.addLayerToMap()
739
+ } catch (_: Exception) {
740
+ // ignore
860
741
  }
861
742
  }
862
743
 
863
- fun removeKmlLayer(id: String) {
744
+ fun removeKmlLayer(id: String) =
864
745
  onUi {
865
746
  kmlLayersById.remove(id)?.removeLayerFromMap()
866
747
  }
867
- }
868
748
 
869
- fun clearKmlLayer() {
749
+ fun clearKmlLayer() =
870
750
  onUi {
871
751
  kmlLayersById.values.forEach { it.removeLayerFromMap() }
752
+ kmlLayersById.clear()
753
+ pendingKmlLayers.clear()
872
754
  }
873
- kmlLayersById.clear()
874
- pendingKmlLayers.clear()
875
- }
876
755
 
877
756
  fun addUrlTileOverlay(
878
757
  id: String,
879
758
  opts: TileOverlayOptions,
880
- ) {
759
+ ) = onUi {
881
760
  if (googleMap == null) {
882
761
  pendingUrlTilesOverlays.add(id to opts)
883
- return
884
- }
885
-
886
- onUi {
887
- urlTileOverlaysById.remove(id)?.remove()
762
+ return@onUi
888
763
  }
764
+ urlTileOverlaysById.remove(id)?.remove()
889
765
  internalAddUrlTileOverlay(id, opts)
890
766
  }
891
767
 
892
768
  private fun internalAddUrlTileOverlay(
893
769
  id: String,
894
770
  opts: TileOverlayOptions,
895
- ) {
896
- onUi {
897
- val urlTile =
898
- googleMap?.addTileOverlay(opts)
899
- if (urlTile != null) {
900
- urlTileOverlaysById[id] = urlTile
901
- }
902
- }
771
+ ) = onUi {
772
+ val overlay = googleMap?.addTileOverlay(opts)
773
+ if (overlay != null) urlTileOverlaysById[id] = overlay
903
774
  }
904
775
 
905
- fun removeUrlTileOverlay(id: String) {
776
+ fun removeUrlTileOverlay(id: String) =
906
777
  onUi {
907
- urlTileOverlaysById.remove(id)?.remove()
778
+ urlTileOverlaysById.remove(id)?.let { urlTileOverlay ->
779
+ urlTileOverlay.clearTileCache()
780
+ urlTileOverlay.remove()
781
+ }
908
782
  }
909
- }
910
783
 
911
- fun clearUrlTileOverlays() {
784
+ fun clearUrlTileOverlays() =
912
785
  onUi {
913
786
  urlTileOverlaysById.values.forEach { it.remove() }
787
+ urlTileOverlaysById.clear()
788
+ pendingUrlTilesOverlays.clear()
914
789
  }
915
- urlTileOverlaysById.clear()
916
- pendingUrlTilesOverlays.clear()
917
- }
918
790
 
919
- fun destroyInternal() {
920
- if (destroyed) return
921
- destroyed = true
791
+ fun destroyInternal() =
922
792
  onUi {
793
+ if (destroyed) return@onUi
794
+ destroyed = true
923
795
  locationHandler.stop()
924
796
  markerBuilder.cancelAllJobs()
925
797
  clearMarkers()
@@ -958,7 +830,6 @@ class GoogleMapsViewImpl(
958
830
  reactContext.removeLifecycleEventListener(this)
959
831
  initialized = false
960
832
  }
961
- }
962
833
 
963
834
  override fun requestLayout() {
964
835
  super.requestLayout()
@@ -972,130 +843,126 @@ class GoogleMapsViewImpl(
972
843
  }
973
844
  }
974
845
 
975
- override fun onAttachedToWindow() {
976
- super.onAttachedToWindow()
977
- locationHandler.start()
978
- }
846
+ override fun onAttachedToWindow() =
847
+ onUi {
848
+ super.onAttachedToWindow()
849
+ locationHandler.start()
850
+ }
979
851
 
980
- override fun onDetachedFromWindow() {
981
- super.onDetachedFromWindow()
982
- locationHandler.stop()
983
- }
852
+ override fun onDetachedFromWindow() =
853
+ onUi {
854
+ super.onDetachedFromWindow()
855
+ locationHandler.stop()
856
+ }
984
857
 
985
- override fun onHostResume() {
858
+ override fun onHostResume() =
986
859
  onUi {
987
860
  locationHandler.start()
988
861
  mapView?.onResume()
989
862
  }
990
- }
991
863
 
992
- override fun onHostPause() {
864
+ override fun onHostPause() =
993
865
  onUi {
994
866
  locationHandler.stop()
995
867
  mapView?.onPause()
996
868
  }
997
- }
998
869
 
999
870
  override fun onHostDestroy() {
1000
871
  destroyInternal()
1001
872
  }
1002
873
 
1003
874
  override fun onMarkerClick(marker: Marker): Boolean {
1004
- marker.showInfoWindow()
1005
- onMarkerPress?.invoke(marker.tag?.toString())
875
+ onUi {
876
+ marker.showInfoWindow()
877
+ onMarkerPress?.invoke(marker.tag?.toString())
878
+ }
1006
879
  return false
1007
880
  }
1008
881
 
1009
- override fun onPolylineClick(polyline: Polyline) {
1010
- onPolylinePress?.invoke(polyline.tag?.toString())
1011
- }
882
+ override fun onPolylineClick(polyline: Polyline) =
883
+ onUi {
884
+ onPolylinePress?.invoke(polyline.tag?.toString())
885
+ }
1012
886
 
1013
- override fun onPolygonClick(polygon: Polygon) {
1014
- onPolygonPress?.invoke(polygon.tag?.toString())
1015
- }
887
+ override fun onPolygonClick(polygon: Polygon) =
888
+ onUi {
889
+ onPolygonPress?.invoke(polygon.tag?.toString())
890
+ }
1016
891
 
1017
- override fun onCircleClick(circle: Circle) {
1018
- onCirclePress?.invoke(circle.tag?.toString())
1019
- }
892
+ override fun onCircleClick(circle: Circle) =
893
+ onUi {
894
+ onCirclePress?.invoke(circle.tag?.toString())
895
+ }
1020
896
 
1021
- override fun onMapClick(coordinates: LatLng) {
1022
- onMapPress?.invoke(
1023
- coordinates.toRnLatLng(),
1024
- )
1025
- }
897
+ override fun onMapClick(coordinates: LatLng) =
898
+ onUi {
899
+ onMapPress?.invoke(coordinates.toRnLatLng())
900
+ }
1026
901
 
1027
- override fun onMapLongClick(coordinates: LatLng) {
1028
- onMapLongPress?.invoke(
1029
- coordinates.toRnLatLng(),
1030
- )
1031
- }
902
+ override fun onMapLongClick(coordinates: LatLng) =
903
+ onUi {
904
+ onMapLongPress?.invoke(coordinates.toRnLatLng())
905
+ }
1032
906
 
1033
- override fun onMarkerDragStart(marker: Marker) {
1034
- onMarkerDragStart?.invoke(
1035
- marker.tag?.toString(),
1036
- marker.position.toRnLatLng(),
1037
- )
1038
- }
907
+ override fun onMarkerDragStart(marker: Marker) =
908
+ onUi {
909
+ onMarkerDragStart?.invoke(marker.tag?.toString(), marker.position.toRnLatLng())
910
+ }
1039
911
 
1040
- override fun onMarkerDrag(marker: Marker) {
1041
- onMarkerDrag?.invoke(
1042
- marker.tag?.toString(),
1043
- marker.position.toRnLatLng(),
1044
- )
1045
- }
912
+ override fun onMarkerDrag(marker: Marker) =
913
+ onUi {
914
+ onMarkerDrag?.invoke(marker.tag?.toString(), marker.position.toRnLatLng())
915
+ }
1046
916
 
1047
- override fun onMarkerDragEnd(marker: Marker) {
1048
- onMarkerDragEnd?.invoke(
1049
- marker.tag?.toString(),
1050
- marker.position.toRnLatLng(),
1051
- )
1052
- }
917
+ override fun onMarkerDragEnd(marker: Marker) =
918
+ onUi {
919
+ onMarkerDragEnd?.invoke(marker.tag?.toString(), marker.position.toRnLatLng())
920
+ }
1053
921
 
1054
- override fun onIndoorBuildingFocused() {
1055
- val building = googleMap?.focusedBuilding ?: return
1056
- onIndoorBuildingFocused?.invoke(building.toRNIndoorBuilding())
1057
- }
922
+ override fun onIndoorBuildingFocused() =
923
+ onUi {
924
+ val building = googleMap?.focusedBuilding ?: return@onUi
925
+ onIndoorBuildingFocused?.invoke(building.toRNIndoorBuilding())
926
+ }
1058
927
 
1059
- override fun onIndoorLevelActivated(indoorBuilding: IndoorBuilding) {
1060
- val activeLevel = indoorBuilding.levels.getOrNull(indoorBuilding.activeLevelIndex) ?: return
1061
- onIndoorLevelActivated?.invoke(
1062
- activeLevel.toRNIndoorLevel(
1063
- indoorBuilding.activeLevelIndex,
1064
- true,
1065
- ),
1066
- )
1067
- }
928
+ override fun onIndoorLevelActivated(indoorBuilding: IndoorBuilding) =
929
+ onUi {
930
+ val activeLevel =
931
+ indoorBuilding.levels.getOrNull(indoorBuilding.activeLevelIndex) ?: return@onUi
932
+ onIndoorLevelActivated?.invoke(
933
+ activeLevel.toRNIndoorLevel(indoorBuilding.activeLevelIndex, true),
934
+ )
935
+ }
1068
936
 
1069
- override fun onPoiClick(poi: PointOfInterest) {
1070
- onPoiPress?.invoke(poi.placeId, poi.name, poi.latLng.toRnLatLng())
1071
- }
937
+ override fun onPoiClick(poi: PointOfInterest) =
938
+ onUi {
939
+ onPoiPress?.invoke(poi.placeId, poi.name, poi.latLng.toRnLatLng())
940
+ }
1072
941
 
1073
- override fun onInfoWindowClick(marker: Marker) {
1074
- onInfoWindowPress?.invoke(marker.tag?.toString())
1075
- }
942
+ override fun onInfoWindowClick(marker: Marker) =
943
+ onUi {
944
+ onInfoWindowPress?.invoke(marker.tag?.toString())
945
+ }
1076
946
 
1077
- override fun onInfoWindowClose(marker: Marker) {
1078
- onInfoWindowClose?.invoke(marker.tag?.toString())
1079
- }
947
+ override fun onInfoWindowClose(marker: Marker) =
948
+ onUi {
949
+ onInfoWindowClose?.invoke(marker.tag?.toString())
950
+ }
1080
951
 
1081
- override fun onInfoWindowLongClick(marker: Marker) {
1082
- onInfoWindowLongPress?.invoke(marker.tag?.toString())
1083
- }
952
+ override fun onInfoWindowLongClick(marker: Marker) =
953
+ onUi {
954
+ onInfoWindowLongPress?.invoke(marker.tag?.toString())
955
+ }
1084
956
 
1085
- override fun onMyLocationClick(location: Location) {
1086
- onMyLocationPress?.invoke(location.toRnLocation())
1087
- }
957
+ override fun onMyLocationClick(location: Location) =
958
+ onUi {
959
+ onMyLocationPress?.invoke(location.toRnLocation())
960
+ }
1088
961
 
1089
962
  override fun onMyLocationButtonClick(): Boolean {
1090
- onMyLocationButtonPress?.invoke(true)
963
+ onUi {
964
+ onMyLocationButtonPress?.invoke(true)
965
+ }
1091
966
  return false
1092
967
  }
1093
968
  }
1094
-
1095
- private inline fun onUi(crossinline block: () -> Unit) {
1096
- if (UiThreadUtil.isOnUiThread()) {
1097
- block()
1098
- } else {
1099
- UiThreadUtil.runOnUiThread { block() }
1100
- }
1101
- }