react-native-google-maps-plus 1.7.0-dev.6 → 1.7.0-dev.7
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.
- package/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt +337 -484
- package/android/src/main/java/com/rngooglemapsplus/MapCircleBuilder.kt +2 -1
- package/android/src/main/java/com/rngooglemapsplus/MapHelper.kt +22 -0
- package/android/src/main/java/com/rngooglemapsplus/MapMarkerBuilder.kt +4 -2
- package/android/src/main/java/com/rngooglemapsplus/MapPolygonBuilder.kt +2 -1
- package/android/src/main/java/com/rngooglemapsplus/MapPolylineBuilder.kt.kt +2 -1
- package/android/src/main/java/com/rngooglemapsplus/RNGoogleMapsPlusView.kt +10 -21
- package/ios/MapCircleBuilder.swift +2 -0
- package/ios/MapHeatmapBuilder.swift +1 -0
- package/ios/MapMarkerBuilder.swift +4 -0
- package/ios/MapPolygonBuilder.swift +2 -0
- package/ios/MapPolylineBuilder.swift +2 -0
- package/ios/MapUrlTileOverlayBuilder.swift +1 -0
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ 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.rngooglemapsplus.extensions.onUi
|
|
7
8
|
import com.rngooglemapsplus.extensions.toColor
|
|
8
9
|
import com.rngooglemapsplus.extensions.toLatLng
|
|
9
10
|
|
|
@@ -23,7 +24,7 @@ class MapCircleBuilder {
|
|
|
23
24
|
prev: RNCircle,
|
|
24
25
|
next: RNCircle,
|
|
25
26
|
circle: Circle,
|
|
26
|
-
) {
|
|
27
|
+
) = onUi {
|
|
27
28
|
if (prev.center.latitude != next.center.latitude ||
|
|
28
29
|
prev.center.longitude != next.center.longitude
|
|
29
30
|
) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package com.rngooglemapsplus.extensions
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.UiThreadUtil
|
|
4
|
+
import kotlinx.coroutines.CompletableDeferred
|
|
5
|
+
import kotlinx.coroutines.runBlocking
|
|
6
|
+
|
|
7
|
+
inline fun onUi(crossinline block: () -> Unit) {
|
|
8
|
+
if (UiThreadUtil.isOnUiThread()) {
|
|
9
|
+
block()
|
|
10
|
+
} else {
|
|
11
|
+
UiThreadUtil.runOnUiThread { block() }
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
inline fun <T> onUiSync(crossinline block: () -> T): T {
|
|
16
|
+
if (UiThreadUtil.isOnUiThread()) return block()
|
|
17
|
+
val result = CompletableDeferred<T>()
|
|
18
|
+
UiThreadUtil.runOnUiThread {
|
|
19
|
+
runCatching(block).onSuccess(result::complete).onFailure(result::completeExceptionally)
|
|
20
|
+
}
|
|
21
|
+
return runBlocking { result.await() }
|
|
22
|
+
}
|
|
@@ -16,6 +16,7 @@ import com.google.android.gms.maps.model.BitmapDescriptorFactory
|
|
|
16
16
|
import com.google.android.gms.maps.model.Marker
|
|
17
17
|
import com.google.android.gms.maps.model.MarkerOptions
|
|
18
18
|
import com.rngooglemapsplus.extensions.markerStyleEquals
|
|
19
|
+
import com.rngooglemapsplus.extensions.onUi
|
|
19
20
|
import com.rngooglemapsplus.extensions.styleHash
|
|
20
21
|
import com.rngooglemapsplus.extensions.toLatLng
|
|
21
22
|
import kotlinx.coroutines.CoroutineScope
|
|
@@ -28,6 +29,7 @@ import kotlinx.coroutines.withContext
|
|
|
28
29
|
import java.net.HttpURLConnection
|
|
29
30
|
import java.net.URL
|
|
30
31
|
import java.net.URLDecoder
|
|
32
|
+
import java.util.concurrent.ConcurrentHashMap
|
|
31
33
|
import kotlin.coroutines.coroutineContext
|
|
32
34
|
|
|
33
35
|
class MapMarkerBuilder(
|
|
@@ -42,7 +44,7 @@ class MapMarkerBuilder(
|
|
|
42
44
|
): Int = 1
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
private val jobsById =
|
|
47
|
+
private val jobsById = ConcurrentHashMap<String, Job>()
|
|
46
48
|
|
|
47
49
|
init {
|
|
48
50
|
// / TODO: refactor with androidsvg 1.5 release
|
|
@@ -162,7 +164,7 @@ class MapMarkerBuilder(
|
|
|
162
164
|
prev: RNMarker,
|
|
163
165
|
next: RNMarker,
|
|
164
166
|
marker: Marker,
|
|
165
|
-
) {
|
|
167
|
+
) = onUi {
|
|
166
168
|
if (prev.coordinate.latitude != next.coordinate.latitude ||
|
|
167
169
|
prev.coordinate.longitude != next.coordinate.longitude
|
|
168
170
|
) {
|
|
@@ -4,6 +4,7 @@ import android.graphics.Color
|
|
|
4
4
|
import com.facebook.react.uimanager.PixelUtil.dpToPx
|
|
5
5
|
import com.google.android.gms.maps.model.Polygon
|
|
6
6
|
import com.google.android.gms.maps.model.PolygonOptions
|
|
7
|
+
import com.rngooglemapsplus.extensions.onUi
|
|
7
8
|
import com.rngooglemapsplus.extensions.toColor
|
|
8
9
|
import com.rngooglemapsplus.extensions.toLatLng
|
|
9
10
|
|
|
@@ -30,7 +31,7 @@ class MapPolygonBuilder {
|
|
|
30
31
|
prev: RNPolygon,
|
|
31
32
|
next: RNPolygon,
|
|
32
33
|
poly: Polygon,
|
|
33
|
-
) {
|
|
34
|
+
) = onUi {
|
|
34
35
|
val coordsChanged =
|
|
35
36
|
prev.coordinates.size != next.coordinates.size ||
|
|
36
37
|
!prev.coordinates.zip(next.coordinates).all { (a, b) ->
|
|
@@ -9,6 +9,7 @@ import com.google.android.gms.maps.model.Polyline
|
|
|
9
9
|
import com.google.android.gms.maps.model.PolylineOptions
|
|
10
10
|
import com.google.android.gms.maps.model.RoundCap
|
|
11
11
|
import com.google.android.gms.maps.model.SquareCap
|
|
12
|
+
import com.rngooglemapsplus.extensions.onUi
|
|
12
13
|
import com.rngooglemapsplus.extensions.toColor
|
|
13
14
|
import com.rngooglemapsplus.extensions.toLatLng
|
|
14
15
|
|
|
@@ -34,7 +35,7 @@ class MapPolylineBuilder {
|
|
|
34
35
|
prev: RNPolyline,
|
|
35
36
|
next: RNPolyline,
|
|
36
37
|
polyline: Polyline,
|
|
37
|
-
) {
|
|
38
|
+
) = onUi {
|
|
38
39
|
val coordsChanged =
|
|
39
40
|
prev.coordinates.size != next.coordinates.size ||
|
|
40
41
|
!prev.coordinates.zip(next.coordinates).all { (a, b) ->
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package com.rngooglemapsplus
|
|
2
2
|
|
|
3
3
|
import com.facebook.proguard.annotations.DoNotStrip
|
|
4
|
-
import com.facebook.react.bridge.UiThreadUtil
|
|
5
4
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
6
5
|
import com.google.android.gms.maps.GoogleMapOptions
|
|
7
6
|
import com.google.android.gms.maps.model.MapStyleOptions
|
|
@@ -155,7 +154,7 @@ class RNGoogleMapsPlusView(
|
|
|
155
154
|
|
|
156
155
|
!prev.markerEquals(next) ->
|
|
157
156
|
view.updateMarker(id) { marker ->
|
|
158
|
-
|
|
157
|
+
markerBuilder.update(prev, next, marker)
|
|
159
158
|
}
|
|
160
159
|
}
|
|
161
160
|
}
|
|
@@ -179,7 +178,7 @@ class RNGoogleMapsPlusView(
|
|
|
179
178
|
|
|
180
179
|
!prev.polylineEquals(next) ->
|
|
181
180
|
view.updatePolyline(id) { polyline ->
|
|
182
|
-
|
|
181
|
+
polylineBuilder.update(prev, next, polyline)
|
|
183
182
|
}
|
|
184
183
|
}
|
|
185
184
|
}
|
|
@@ -204,7 +203,7 @@ class RNGoogleMapsPlusView(
|
|
|
204
203
|
|
|
205
204
|
!prev.polygonEquals(next) ->
|
|
206
205
|
view.updatePolygon(id) { polygon ->
|
|
207
|
-
|
|
206
|
+
polygonBuilder.update(prev, next, polygon)
|
|
208
207
|
}
|
|
209
208
|
}
|
|
210
209
|
}
|
|
@@ -229,7 +228,7 @@ class RNGoogleMapsPlusView(
|
|
|
229
228
|
|
|
230
229
|
!prev.circleEquals(next) ->
|
|
231
230
|
view.updateCircle(id) { circle ->
|
|
232
|
-
|
|
231
|
+
circleBuilder.update(prev, next, circle)
|
|
233
232
|
}
|
|
234
233
|
}
|
|
235
234
|
}
|
|
@@ -416,14 +415,12 @@ class RNGoogleMapsPlusView(
|
|
|
416
415
|
animated: Boolean?,
|
|
417
416
|
durationMs: Double?,
|
|
418
417
|
) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
)
|
|
426
|
-
}
|
|
418
|
+
val current = view.currentCamera
|
|
419
|
+
view.setCamera(
|
|
420
|
+
camera.toCameraPosition(current),
|
|
421
|
+
animated == true,
|
|
422
|
+
durationMs?.toInt() ?: 3000,
|
|
423
|
+
)
|
|
427
424
|
}
|
|
428
425
|
|
|
429
426
|
override fun setCameraToCoordinates(
|
|
@@ -481,11 +478,3 @@ class RNGoogleMapsPlusView(
|
|
|
481
478
|
|
|
482
479
|
override fun isGooglePlayServicesAvailable(): Boolean = playServiceHandler.isPlayServicesAvailable()
|
|
483
480
|
}
|
|
484
|
-
|
|
485
|
-
private inline fun onUi(crossinline block: () -> Unit) {
|
|
486
|
-
if (UiThreadUtil.isOnUiThread()) {
|
|
487
|
-
block()
|
|
488
|
-
} else {
|
|
489
|
-
UiThreadUtil.runOnUiThread { block() }
|
|
490
|
-
}
|
|
491
|
-
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import GoogleMaps
|
|
2
2
|
|
|
3
3
|
final class MapCircleBuilder {
|
|
4
|
+
@MainActor
|
|
4
5
|
func build(_ c: RNCircle) -> GMSCircle {
|
|
5
6
|
let circle = GMSCircle()
|
|
6
7
|
circle.position = c.center.toCLLocationCoordinate2D()
|
|
@@ -14,6 +15,7 @@ final class MapCircleBuilder {
|
|
|
14
15
|
return circle
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
@MainActor
|
|
17
19
|
func update(_ prev: RNCircle, _ next: RNCircle, _ c: GMSCircle) {
|
|
18
20
|
if prev.center.latitude != next.center.latitude
|
|
19
21
|
|| prev.center.longitude != next.center.longitude {
|
|
@@ -10,6 +10,7 @@ final class MapMarkerBuilder {
|
|
|
10
10
|
}()
|
|
11
11
|
private var tasks: [String: Task<Void, Never>] = [:]
|
|
12
12
|
|
|
13
|
+
@MainActor
|
|
13
14
|
func build(_ m: RNMarker, icon: UIImage?) -> GMSMarker {
|
|
14
15
|
let marker = GMSMarker(
|
|
15
16
|
position: m.coordinate.toCLLocationCoordinate2D()
|
|
@@ -160,11 +161,13 @@ final class MapMarkerBuilder {
|
|
|
160
161
|
tasks[id] = task
|
|
161
162
|
}
|
|
162
163
|
|
|
164
|
+
@MainActor
|
|
163
165
|
func cancelIconTask(_ id: String) {
|
|
164
166
|
tasks[id]?.cancel()
|
|
165
167
|
tasks.removeValue(forKey: id)
|
|
166
168
|
}
|
|
167
169
|
|
|
170
|
+
@MainActor
|
|
168
171
|
func cancelAllIconTasks() {
|
|
169
172
|
let ids = Array(tasks.keys)
|
|
170
173
|
for id in ids {
|
|
@@ -174,6 +177,7 @@ final class MapMarkerBuilder {
|
|
|
174
177
|
iconCache.removeAllObjects()
|
|
175
178
|
}
|
|
176
179
|
|
|
180
|
+
@MainActor
|
|
177
181
|
private func renderUIImage(_ m: RNMarker, _ scale: CGFloat) async -> UIImage? {
|
|
178
182
|
guard let iconSvg = m.iconSvg,
|
|
179
183
|
let data = iconSvg.svgString.data(using: .utf8)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import GoogleMaps
|
|
2
2
|
|
|
3
3
|
final class MapPolygonBuilder {
|
|
4
|
+
@MainActor
|
|
4
5
|
func build(_ p: RNPolygon) -> GMSPolygon {
|
|
5
6
|
let path = GMSMutablePath()
|
|
6
7
|
p.coordinates.forEach {
|
|
@@ -28,6 +29,7 @@ final class MapPolygonBuilder {
|
|
|
28
29
|
return pg
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
@MainActor
|
|
31
33
|
func update(_ prev: RNPolygon, _ next: RNPolygon, _ pg: GMSPolygon) {
|
|
32
34
|
let coordsChanged =
|
|
33
35
|
prev.coordinates.count != next.coordinates.count
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import GoogleMaps
|
|
2
2
|
|
|
3
3
|
final class MapPolylineBuilder {
|
|
4
|
+
@MainActor
|
|
4
5
|
func build(_ p: RNPolyline) -> GMSPolyline {
|
|
5
6
|
let path = GMSMutablePath()
|
|
6
7
|
p.coordinates.forEach {
|
|
@@ -22,6 +23,7 @@ final class MapPolylineBuilder {
|
|
|
22
23
|
return pl
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
@MainActor
|
|
25
27
|
func update(_ prev: RNPolyline, _ next: RNPolyline, _ pl: GMSPolyline) {
|
|
26
28
|
let coordsChanged =
|
|
27
29
|
prev.coordinates.count != next.coordinates.count
|
package/package.json
CHANGED