react-native-google-maps-plus 1.0.3-dev.1 → 1.1.0-dev.2
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/RNGoogleMapsPlus.podspec +2 -0
- package/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt +122 -29
- package/android/src/main/java/com/rngooglemapsplus/LocationHandler.kt +44 -44
- package/android/src/main/java/com/rngooglemapsplus/{MapCircle.kt → MapCircleBuilder.kt} +2 -12
- package/android/src/main/java/com/rngooglemapsplus/{MapMarker.kt → MapMarkerBuilder.kt} +23 -27
- package/android/src/main/java/com/rngooglemapsplus/{MapPolygon.kt → MapPolygonBuilder.kt} +2 -18
- package/android/src/main/java/com/rngooglemapsplus/{MapPolyline.kt → MapPolylineBuilder.kt.kt} +2 -19
- package/android/src/main/java/com/rngooglemapsplus/RNGoogleMapsPlusView.kt +45 -54
- package/android/src/main/java/com/rngooglemapsplus/extensions/RNCameraExtension.kt +19 -0
- package/android/src/main/java/com/rngooglemapsplus/extensions/RNLocationPriorityExtension.kt +12 -0
- package/android/src/main/java/com/rngooglemapsplus/extensions/RNMapCircleExtension.kt +14 -0
- package/android/src/main/java/com/rngooglemapsplus/extensions/RNMarkerExtension.kt +17 -0
- package/android/src/main/java/com/rngooglemapsplus/extensions/RNPolygonExtension.kt +20 -0
- package/android/src/main/java/com/rngooglemapsplus/extensions/RNPolylineExtension.kt +21 -0
- package/android/src/main/java/com/rngooglemapsplus/extensions/RNUserInterfaceExtension.kt +12 -0
- package/android/src/main/java/com/rngooglemapsplus/{Color.kt → extensions/StringExtension.kt} +1 -1
- package/android/src/main/java/com/rngooglemapsplus/extensions/ThrowableExtension.kt +38 -0
- package/ios/GoogleMapViewImpl.swift +165 -22
- package/ios/LocationHandler.swift +29 -69
- package/ios/MapCircleBuilder.swift +20 -0
- package/ios/{MapMarker.swift → MapMarkerBuilder.swift} +17 -32
- package/ios/MapPolygonBuilder.swift +20 -0
- package/ios/MapPolylineBuilder.swift +24 -0
- package/ios/RNGoogleMapsPlusView.swift +63 -116
- package/ios/extensions/RNCamera+Extension.swift +22 -0
- package/ios/{MapCircle.swift → extensions/RNCircle+Extension.swift} +0 -19
- package/ios/extensions/RNIOSLocationAccuracy+Extensions.swift +19 -0
- package/ios/extensions/RNMarker+Extension.swift +25 -0
- package/ios/{MapPolygon.swift → extensions/RNPolygon+Extension.swift.swift} +0 -19
- package/ios/{MapPolyline.swift → extensions/RNPolyline+Extension.swift.swift} +16 -39
- package/ios/extensions/RNUserInterface+Extension.swift +16 -0
- package/lib/module/types.js +14 -0
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/src/RNGoogleMapsPlusView.nitro.d.ts +5 -1
- package/lib/typescript/src/RNGoogleMapsPlusView.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +43 -2
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.cpp +64 -0
- package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.hpp +8 -0
- package/nitrogen/generated/android/c++/JRNAndroidLocationConfig.hpp +63 -0
- package/nitrogen/generated/android/c++/JRNAndroidLocationPriority.hpp +65 -0
- package/nitrogen/generated/android/c++/JRNIOSLocationAccuracy.hpp +65 -0
- package/nitrogen/generated/android/c++/JRNIOSLocationConfig.hpp +59 -0
- package/nitrogen/generated/android/c++/JRNInitialProps.hpp +4 -4
- package/nitrogen/generated/android/c++/JRNLocationConfig.hpp +65 -0
- package/nitrogen/generated/android/c++/JRNMapUiSettings.hpp +93 -0
- package/nitrogen/generated/android/c++/JRNMarker.hpp +6 -12
- package/nitrogen/generated/android/c++/JRNMarkerSvg.hpp +61 -0
- package/nitrogen/generated/android/c++/views/JHybridRNGoogleMapsPlusViewStateUpdater.cpp +16 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/HybridRNGoogleMapsPlusViewSpec.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNAndroidLocationConfig.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNAndroidLocationPriority.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNIOSLocationAccuracy.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNIOSLocationConfig.kt +32 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNInitialProps.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNLocationConfig.kt +32 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNMapUiSettings.kt +59 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNMarker.kt +1 -7
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNMarkerSvg.kt +35 -0
- package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Bridge.hpp +126 -0
- package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Umbrella.hpp +21 -0
- package/nitrogen/generated/ios/c++/HybridRNGoogleMapsPlusViewSpecSwift.hpp +49 -0
- package/nitrogen/generated/ios/c++/views/HybridRNGoogleMapsPlusViewComponent.mm +20 -0
- package/nitrogen/generated/ios/swift/HybridRNGoogleMapsPlusViewSpec.swift +4 -0
- package/nitrogen/generated/ios/swift/HybridRNGoogleMapsPlusViewSpec_cxx.swift +82 -0
- package/nitrogen/generated/ios/swift/RNAndroidLocationConfig.swift +93 -0
- package/nitrogen/generated/ios/swift/RNAndroidLocationPriority.swift +48 -0
- package/nitrogen/generated/ios/swift/RNIOSLocationAccuracy.swift +48 -0
- package/nitrogen/generated/ios/swift/RNIOSLocationConfig.swift +70 -0
- package/nitrogen/generated/ios/swift/RNInitialProps.swift +6 -6
- package/nitrogen/generated/ios/swift/RNLocationConfig.swift +84 -0
- package/nitrogen/generated/ios/swift/RNMapUiSettings.swift +277 -0
- package/nitrogen/generated/ios/swift/RNMarker.swift +24 -27
- package/nitrogen/generated/ios/swift/RNMarkerSvg.swift +57 -0
- package/nitrogen/generated/shared/c++/HybridRNGoogleMapsPlusViewSpec.cpp +8 -0
- package/nitrogen/generated/shared/c++/HybridRNGoogleMapsPlusViewSpec.hpp +14 -0
- package/nitrogen/generated/shared/c++/RNAndroidLocationConfig.hpp +77 -0
- package/nitrogen/generated/shared/c++/RNAndroidLocationPriority.hpp +64 -0
- package/nitrogen/generated/shared/c++/RNIOSLocationAccuracy.hpp +64 -0
- package/nitrogen/generated/shared/c++/RNIOSLocationConfig.hpp +73 -0
- package/nitrogen/generated/shared/c++/RNInitialProps.hpp +5 -5
- package/nitrogen/generated/shared/c++/RNLocationConfig.hpp +76 -0
- package/nitrogen/generated/shared/c++/RNMapUiSettings.hpp +107 -0
- package/nitrogen/generated/shared/c++/RNMarker.hpp +8 -13
- package/nitrogen/generated/shared/c++/RNMarkerSvg.hpp +75 -0
- package/nitrogen/generated/shared/c++/views/HybridRNGoogleMapsPlusViewComponent.cpp +48 -0
- package/nitrogen/generated/shared/c++/views/HybridRNGoogleMapsPlusViewComponent.hpp +6 -0
- package/nitrogen/generated/shared/json/RNGoogleMapsPlusViewConfig.json +4 -0
- package/package.json +1 -1
- package/src/RNGoogleMapsPlusView.nitro.ts +6 -0
- package/src/types.ts +49 -2
- /package/ios/{Color.swift → extensions/String+Extensions.swift} +0 -0
|
@@ -2,43 +2,43 @@ import CoreLocation
|
|
|
2
2
|
import Foundation
|
|
3
3
|
import UIKit
|
|
4
4
|
|
|
5
|
+
private let kCLLocationAccuracyDefault: CLLocationAccuracy =
|
|
6
|
+
kCLLocationAccuracyBest
|
|
7
|
+
private let kCLDistanceFilterNoneDefault: CLLocationDistance =
|
|
8
|
+
kCLDistanceFilterNone
|
|
9
|
+
|
|
5
10
|
final class LocationHandler: NSObject, CLLocationManagerDelegate {
|
|
6
11
|
|
|
7
12
|
private let manager = CLLocationManager()
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
|
|
14
|
+
var desiredAccuracy: CLLocationAccuracy? = kCLLocationAccuracyDefault {
|
|
15
|
+
didSet {
|
|
16
|
+
if let desiredAccuracy = desiredAccuracy {
|
|
17
|
+
manager.desiredAccuracy = desiredAccuracy
|
|
18
|
+
} else {
|
|
19
|
+
manager.desiredAccuracy = kCLLocationAccuracyBest
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var distanceFilterMeters: CLLocationDistance? = kCLDistanceFilterNoneDefault {
|
|
25
|
+
didSet {
|
|
26
|
+
if let distanceFilterMeters = distanceFilterMeters {
|
|
27
|
+
manager.distanceFilter = distanceFilterMeters
|
|
28
|
+
} else {
|
|
29
|
+
manager.distanceFilter = kCLDistanceFilterNone
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
12
33
|
|
|
13
34
|
var onUpdate: ((CLLocation) -> Void)?
|
|
14
35
|
var onError: ((_ error: RNLocationErrorCode) -> Void)?
|
|
15
36
|
|
|
16
|
-
private var lastEmit: Date?
|
|
17
|
-
|
|
18
37
|
override init() {
|
|
19
38
|
super.init()
|
|
20
39
|
manager.delegate = self
|
|
21
40
|
manager.pausesLocationUpdatesAutomatically = true
|
|
22
41
|
manager.activityType = .other
|
|
23
|
-
applyPriority()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
func setPriority(_ priority: Int) {
|
|
27
|
-
self.priority = priority
|
|
28
|
-
applyPriority()
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
func setInterval(_ seconds: Int) {
|
|
32
|
-
self.interval = max(0, TimeInterval(seconds))
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
func setFastestInterval(_ seconds: Int) {
|
|
36
|
-
self.minUpdateInterval = max(0, TimeInterval(seconds))
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
func setDistanceFilter(_ meters: Double) {
|
|
40
|
-
self.distanceFilterMeters = meters >= 0 ? meters : kCLDistanceFilterNone
|
|
41
|
-
manager.distanceFilter = distanceFilterMeters
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
func showLocationDialog() {
|
|
@@ -110,36 +110,13 @@ final class LocationHandler: NSObject, CLLocationManagerDelegate {
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
private func applyPriority() {
|
|
114
|
-
guard let p = Priority(rawValue: priority) else {
|
|
115
|
-
manager.desiredAccuracy = kCLLocationAccuracyBest
|
|
116
|
-
return
|
|
117
|
-
}
|
|
118
|
-
switch p {
|
|
119
|
-
case .highAccuracy:
|
|
120
|
-
manager.desiredAccuracy = kCLLocationAccuracyBest
|
|
121
|
-
case .balanced:
|
|
122
|
-
manager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
|
|
123
|
-
case .lowPower:
|
|
124
|
-
manager.desiredAccuracy = kCLLocationAccuracyHundredMeters
|
|
125
|
-
case .passive:
|
|
126
|
-
manager.desiredAccuracy = kCLLocationAccuracyKilometer
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
113
|
private func startUpdates() {
|
|
131
|
-
manager.
|
|
114
|
+
manager.desiredAccuracy = desiredAccuracy ?? kCLLocationAccuracyDefault
|
|
115
|
+
manager.distanceFilter =
|
|
116
|
+
distanceFilterMeters ?? kCLDistanceFilterNoneDefault
|
|
132
117
|
manager.startUpdatingLocation()
|
|
133
118
|
}
|
|
134
119
|
|
|
135
|
-
private func shouldEmit(now: Date) -> Bool {
|
|
136
|
-
if let last = lastEmit {
|
|
137
|
-
let delta = now.timeIntervalSince(last)
|
|
138
|
-
if delta < minUpdateInterval { return false }
|
|
139
|
-
}
|
|
140
|
-
return true
|
|
141
|
-
}
|
|
142
|
-
|
|
143
120
|
func locationManager(
|
|
144
121
|
_ manager: CLLocationManager,
|
|
145
122
|
didFailWithError error: Error
|
|
@@ -166,12 +143,7 @@ final class LocationHandler: NSObject, CLLocationManagerDelegate {
|
|
|
166
143
|
didUpdateLocations locations: [CLLocation]
|
|
167
144
|
) {
|
|
168
145
|
guard let loc = locations.last else { return }
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if shouldEmit(now: now) {
|
|
172
|
-
lastEmit = now
|
|
173
|
-
onUpdate?(loc)
|
|
174
|
-
}
|
|
146
|
+
onUpdate?(loc)
|
|
175
147
|
}
|
|
176
148
|
|
|
177
149
|
private static func topMostViewController() -> UIViewController? {
|
|
@@ -191,15 +163,3 @@ final class LocationHandler: NSObject, CLLocationManagerDelegate {
|
|
|
191
163
|
}
|
|
192
164
|
|
|
193
165
|
}
|
|
194
|
-
|
|
195
|
-
extension LocationHandler {
|
|
196
|
-
enum Priority: Int {
|
|
197
|
-
case highAccuracy = 100
|
|
198
|
-
/// Android: PRIORITY_BALANCED_POWER_ACCURACY
|
|
199
|
-
case balanced = 102
|
|
200
|
-
/// Android: PRIORITY_LOW_POWER
|
|
201
|
-
case lowPower = 104
|
|
202
|
-
/// Android: PRIORITY_PASSIVE
|
|
203
|
-
case passive = 105
|
|
204
|
-
}
|
|
205
|
-
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import GoogleMaps
|
|
2
|
+
|
|
3
|
+
final class MapCircleBuilder {
|
|
4
|
+
|
|
5
|
+
func buildCircle(_ c: RNCircle) -> GMSCircle {
|
|
6
|
+
let circle = GMSCircle()
|
|
7
|
+
circle.position = CLLocationCoordinate2D(
|
|
8
|
+
latitude: c.center.latitude,
|
|
9
|
+
longitude: c.center.longitude
|
|
10
|
+
)
|
|
11
|
+
if let r = c.radius { circle.radius = r }
|
|
12
|
+
if let fc = c.fillColor?.toUIColor() { circle.fillColor = fc }
|
|
13
|
+
if let sc = c.strokeColor?.toUIColor() { circle.strokeColor = sc }
|
|
14
|
+
if let sw = c.strokeWidth { circle.strokeWidth = CGFloat(sw) }
|
|
15
|
+
if let pr = c.pressable { circle.isTappable = pr }
|
|
16
|
+
if let zi = c.zIndex { circle.zIndex = Int32(zi) }
|
|
17
|
+
|
|
18
|
+
return circle
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -2,7 +2,7 @@ import GoogleMaps
|
|
|
2
2
|
import SVGKit
|
|
3
3
|
import UIKit
|
|
4
4
|
|
|
5
|
-
final class
|
|
5
|
+
final class MapMarkerBuilder {
|
|
6
6
|
private let iconCache = NSCache<NSString, UIImage>()
|
|
7
7
|
private var tasks: [String: Task<Void, Never>] = [:]
|
|
8
8
|
private let queue = DispatchQueue(
|
|
@@ -11,7 +11,7 @@ final class MapMarkerOptions {
|
|
|
11
11
|
attributes: .concurrent
|
|
12
12
|
)
|
|
13
13
|
|
|
14
|
-
func build(_ m: RNMarker, icon: UIImage) -> GMSMarker {
|
|
14
|
+
func build(_ m: RNMarker, icon: UIImage?) -> GMSMarker {
|
|
15
15
|
let marker = GMSMarker(
|
|
16
16
|
position: CLLocationCoordinate2D(
|
|
17
17
|
latitude: m.coordinate.latitude,
|
|
@@ -40,6 +40,11 @@ final class MapMarkerOptions {
|
|
|
40
40
|
) {
|
|
41
41
|
tasks[id]?.cancel()
|
|
42
42
|
|
|
43
|
+
if m.iconSvg == nil {
|
|
44
|
+
onReady(nil)
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
|
|
43
48
|
let key = m.styleHash()
|
|
44
49
|
if let cached = iconCache.object(forKey: key) {
|
|
45
50
|
onReady(cached)
|
|
@@ -85,7 +90,6 @@ final class MapMarkerOptions {
|
|
|
85
90
|
|
|
86
91
|
if !prev.markerStyleEquals(next) {
|
|
87
92
|
buildIconAsync(next.id, next) { img in
|
|
88
|
-
guard let img else { return }
|
|
89
93
|
m.tracksViewChanges = true
|
|
90
94
|
m.icon = img
|
|
91
95
|
if prev.anchor?.x != next.anchor?.x || prev.anchor?.y != next.anchor?.y {
|
|
@@ -117,21 +121,26 @@ final class MapMarkerOptions {
|
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
private func renderUIImage(_ m: RNMarker) async -> UIImage? {
|
|
120
|
-
|
|
124
|
+
guard let iconSvg = m.iconSvg else {
|
|
125
|
+
return nil
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return await withTaskCancellationHandler(
|
|
121
129
|
operation: {
|
|
122
|
-
await withCheckedContinuation {
|
|
130
|
+
await withCheckedContinuation {
|
|
131
|
+
(cont: CheckedContinuation<UIImage?, Never>) in
|
|
123
132
|
queue.async {
|
|
124
133
|
if Task.isCancelled {
|
|
125
134
|
cont.resume(returning: nil)
|
|
126
135
|
return
|
|
127
136
|
}
|
|
128
137
|
|
|
129
|
-
let targetW = max(1, Int(CGFloat(
|
|
130
|
-
let targetH = max(1, Int(CGFloat(
|
|
138
|
+
let targetW = max(1, Int(CGFloat(iconSvg.width)))
|
|
139
|
+
let targetH = max(1, Int(CGFloat(iconSvg.height)))
|
|
131
140
|
let size = CGSize(width: targetW, height: targetH)
|
|
132
141
|
|
|
133
142
|
guard
|
|
134
|
-
let data =
|
|
143
|
+
let data = iconSvg.svgString.data(using: .utf8),
|
|
135
144
|
let svgImg = SVGKImage(data: data)
|
|
136
145
|
else {
|
|
137
146
|
cont.resume(returning: nil)
|
|
@@ -174,27 +183,3 @@ final class MapMarkerOptions {
|
|
|
174
183
|
}
|
|
175
184
|
|
|
176
185
|
}
|
|
177
|
-
|
|
178
|
-
extension RNMarker {
|
|
179
|
-
func markerEquals(_ b: RNMarker) -> Bool {
|
|
180
|
-
id == b.id && zIndex == b.zIndex
|
|
181
|
-
&& coordinate.latitude == b.coordinate.latitude
|
|
182
|
-
&& coordinate.longitude == b.coordinate.longitude
|
|
183
|
-
&& anchor?.x == b.anchor?.x && anchor?.y == b.anchor?.y
|
|
184
|
-
&& markerStyleEquals(b)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
func markerStyleEquals(_ b: RNMarker) -> Bool {
|
|
188
|
-
width == b.width && height == b.height
|
|
189
|
-
&& iconSvg == b.iconSvg
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
func styleHash() -> NSString {
|
|
193
|
-
var hasher = Hasher()
|
|
194
|
-
hasher.combine(width)
|
|
195
|
-
hasher.combine(height)
|
|
196
|
-
hasher.combine(iconSvg)
|
|
197
|
-
return String(hasher.finalize()) as NSString
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import GoogleMaps
|
|
2
|
+
|
|
3
|
+
final class MapPolygonBuilder {
|
|
4
|
+
|
|
5
|
+
func buildPolygon(_ p: RNPolygon) -> GMSPolygon {
|
|
6
|
+
let path = GMSMutablePath()
|
|
7
|
+
p.coordinates.forEach {
|
|
8
|
+
path.add(
|
|
9
|
+
CLLocationCoordinate2D(latitude: $0.latitude, longitude: $0.longitude)
|
|
10
|
+
)
|
|
11
|
+
}
|
|
12
|
+
let pg = GMSPolygon(path: path)
|
|
13
|
+
if let fc = p.fillColor?.toUIColor() { pg.fillColor = fc }
|
|
14
|
+
if let sc = p.strokeColor?.toUIColor() { pg.strokeColor = sc }
|
|
15
|
+
if let sw = p.strokeWidth { pg.strokeWidth = CGFloat(sw) }
|
|
16
|
+
if let pr = p.pressable { pg.isTappable = pr }
|
|
17
|
+
if let zi = p.zIndex { pg.zIndex = Int32(zi) }
|
|
18
|
+
return pg
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import GoogleMaps
|
|
2
|
+
|
|
3
|
+
final class MapPolylineBuilder {
|
|
4
|
+
func buildPolyline(_ p: RNPolyline) -> GMSPolyline {
|
|
5
|
+
let path = GMSMutablePath()
|
|
6
|
+
p.coordinates.forEach {
|
|
7
|
+
path.add(
|
|
8
|
+
CLLocationCoordinate2D(latitude: $0.latitude, longitude: $0.longitude)
|
|
9
|
+
)
|
|
10
|
+
}
|
|
11
|
+
let pl = GMSPolyline(path: path)
|
|
12
|
+
if let w = p.width { pl.strokeWidth = CGFloat(w) }
|
|
13
|
+
if let c = p.color?.toUIColor() { pl.strokeColor = c }
|
|
14
|
+
if let cap = p.lineCap {
|
|
15
|
+
/// pl.lineCap = mapLineCap(cap)
|
|
16
|
+
}
|
|
17
|
+
if let join = p.lineJoin {
|
|
18
|
+
/// pl.strokeJoin = mapLineJoin(join)
|
|
19
|
+
}
|
|
20
|
+
if let pr = p.pressable { pl.isTappable = pr }
|
|
21
|
+
if let zi = p.zIndex { pl.zIndex = Int32(zi) }
|
|
22
|
+
return pl
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -8,10 +8,10 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
|
|
|
8
8
|
private let permissionHandler: PermissionHandler
|
|
9
9
|
private let locationHandler: LocationHandler
|
|
10
10
|
|
|
11
|
-
private let
|
|
12
|
-
private let
|
|
13
|
-
private let
|
|
14
|
-
private let
|
|
11
|
+
private let markerBuilder = MapMarkerBuilder()
|
|
12
|
+
private let polylineBuilder = MapPolylineBuilder()
|
|
13
|
+
private let polygonBuilder = MapPolygonBuilder()
|
|
14
|
+
private let circleBuilder = MapCircleBuilder()
|
|
15
15
|
|
|
16
16
|
private let impl: GoogleMapsViewImpl
|
|
17
17
|
|
|
@@ -24,15 +24,15 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
|
|
|
24
24
|
self.locationHandler = LocationHandler()
|
|
25
25
|
self.impl = GoogleMapsViewImpl(
|
|
26
26
|
locationHandler: locationHandler,
|
|
27
|
-
|
|
27
|
+
markerBuilder: markerBuilder
|
|
28
28
|
)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
/// TODO: prepareForRecycle
|
|
33
|
+
override func prepareForRecycle() {
|
|
34
|
+
impl.clearAll()
|
|
35
|
+
}
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
@MainActor
|
|
@@ -41,11 +41,21 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
|
|
|
41
41
|
impl.initMapView(
|
|
42
42
|
mapId: initialProps?.mapId,
|
|
43
43
|
liteMode: initialProps?.liteMode,
|
|
44
|
-
camera:
|
|
44
|
+
camera: initialProps?.camera?.toGMSCameraPosition(current: nil)
|
|
45
45
|
)
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
@MainActor
|
|
50
|
+
var uiSettings: RNMapUiSettings? {
|
|
51
|
+
didSet { impl.uiSettings = uiSettings }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@MainActor
|
|
55
|
+
var myLocationEnabled: Bool? {
|
|
56
|
+
didSet { impl.myLocationEnabled = myLocationEnabled }
|
|
57
|
+
}
|
|
58
|
+
|
|
49
59
|
@MainActor
|
|
50
60
|
var buildingEnabled: Bool? {
|
|
51
61
|
didSet { impl.buildingEnabled = buildingEnabled }
|
|
@@ -56,6 +66,11 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
|
|
|
56
66
|
didSet { impl.trafficEnabled = trafficEnabled }
|
|
57
67
|
}
|
|
58
68
|
|
|
69
|
+
@MainActor
|
|
70
|
+
var indoorEnabled: Bool? {
|
|
71
|
+
didSet { impl.indoorEnabled = indoorEnabled }
|
|
72
|
+
}
|
|
73
|
+
|
|
59
74
|
@MainActor
|
|
60
75
|
var customMapStyle: String? {
|
|
61
76
|
didSet {
|
|
@@ -68,9 +83,7 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
|
|
|
68
83
|
@MainActor
|
|
69
84
|
var userInterfaceStyle: RNUserInterfaceStyle? {
|
|
70
85
|
didSet {
|
|
71
|
-
impl.userInterfaceStyle =
|
|
72
|
-
userInterfaceStyle
|
|
73
|
-
)
|
|
86
|
+
impl.userInterfaceStyle = userInterfaceStyle?.toUIUserInterfaceStyle
|
|
74
87
|
}
|
|
75
88
|
}
|
|
76
89
|
|
|
@@ -115,20 +128,19 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
|
|
|
115
128
|
|
|
116
129
|
removed.forEach {
|
|
117
130
|
impl.removeMarker(id: $0)
|
|
118
|
-
|
|
131
|
+
markerBuilder.cancelIconTask($0)
|
|
119
132
|
}
|
|
120
133
|
|
|
121
134
|
for (id, next) in nextById {
|
|
122
135
|
if let prev = prevById[id] {
|
|
123
136
|
if !prev.markerEquals(next) {
|
|
124
137
|
impl.updateMarker(id: id) { m in
|
|
125
|
-
self.
|
|
138
|
+
self.markerBuilder.updateMarker(prev, next, m)
|
|
126
139
|
}
|
|
127
140
|
}
|
|
128
141
|
} else {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
let marker = self.markerOptions.build(next, icon: icon)
|
|
142
|
+
markerBuilder.buildIconAsync(next.id, next) { icon in
|
|
143
|
+
let marker = self.markerBuilder.build(next, icon: icon)
|
|
132
144
|
self.impl.addMarker(id: id, marker: marker)
|
|
133
145
|
}
|
|
134
146
|
}
|
|
@@ -162,7 +174,7 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
|
|
|
162
174
|
} else {
|
|
163
175
|
impl.addPolyline(
|
|
164
176
|
id: id,
|
|
165
|
-
polyline:
|
|
177
|
+
polyline: polylineBuilder.buildPolyline(next)
|
|
166
178
|
)
|
|
167
179
|
}
|
|
168
180
|
}
|
|
@@ -192,7 +204,7 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
|
|
|
192
204
|
}
|
|
193
205
|
}
|
|
194
206
|
} else {
|
|
195
|
-
impl.addPolygon(id: id, polygon:
|
|
207
|
+
impl.addPolygon(id: id, polygon: polygonBuilder.buildPolygon(next))
|
|
196
208
|
}
|
|
197
209
|
}
|
|
198
210
|
}
|
|
@@ -221,52 +233,15 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
|
|
|
221
233
|
}
|
|
222
234
|
}
|
|
223
235
|
} else {
|
|
224
|
-
impl.addCircle(id: id, circle:
|
|
236
|
+
impl.addCircle(id: id, circle: circleBuilder.buildCircle(next))
|
|
225
237
|
}
|
|
226
238
|
}
|
|
227
239
|
}
|
|
228
240
|
}
|
|
229
241
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
let zoom = Float(camera.zoom ?? Double(current?.zoom ?? 0))
|
|
234
|
-
let bearing = camera.bearing ?? current?.bearing ?? 0
|
|
235
|
-
let viewingAngle = camera.bearing ?? current?.viewingAngle ?? 0
|
|
236
|
-
|
|
237
|
-
let target = CLLocationCoordinate2D(
|
|
238
|
-
latitude: camera.center?.latitude ?? current?.target.latitude ?? 0,
|
|
239
|
-
longitude: camera.center?.longitude ?? current?.target.longitude ?? 0
|
|
240
|
-
)
|
|
241
|
-
|
|
242
|
-
let cam = GMSCameraPosition.camera(
|
|
243
|
-
withTarget: target,
|
|
244
|
-
zoom: zoom,
|
|
245
|
-
bearing: bearing,
|
|
246
|
-
viewingAngle: viewingAngle
|
|
247
|
-
)
|
|
248
|
-
onMain {
|
|
249
|
-
self.impl.setCamera(
|
|
250
|
-
camera: cam,
|
|
251
|
-
animated: animated ?? true,
|
|
252
|
-
durationMS: durationMS ?? 3000
|
|
253
|
-
)
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
func setCameraToCoordinates(
|
|
258
|
-
coordinates: [RNLatLng],
|
|
259
|
-
padding: RNMapPadding?,
|
|
260
|
-
animated: Bool?,
|
|
261
|
-
durationMS: Double?
|
|
262
|
-
) {
|
|
263
|
-
onMain {
|
|
264
|
-
self.impl.setCameraToCoordinates(
|
|
265
|
-
coordinates: coordinates,
|
|
266
|
-
padding: padding ?? RNMapPadding(0, 0, 0, 0),
|
|
267
|
-
animated: animated ?? true,
|
|
268
|
-
durationMS: durationMS ?? 3000
|
|
269
|
-
)
|
|
242
|
+
@MainActor var locationConfig: RNLocationConfig? {
|
|
243
|
+
didSet {
|
|
244
|
+
impl.locationConfig = locationConfig
|
|
270
245
|
}
|
|
271
246
|
}
|
|
272
247
|
|
|
@@ -307,6 +282,33 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
|
|
|
307
282
|
didSet { impl.onCameraChangeComplete = onCameraChangeComplete }
|
|
308
283
|
}
|
|
309
284
|
|
|
285
|
+
func setCamera(camera: RNCamera, animated: Bool?, durationMS: Double?) {
|
|
286
|
+
let cam = camera.toGMSCameraPosition(current: impl.currentCamera)
|
|
287
|
+
onMain {
|
|
288
|
+
self.impl.setCamera(
|
|
289
|
+
camera: cam,
|
|
290
|
+
animated: animated ?? true,
|
|
291
|
+
durationMS: durationMS ?? 3000
|
|
292
|
+
)
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
func setCameraToCoordinates(
|
|
297
|
+
coordinates: [RNLatLng],
|
|
298
|
+
padding: RNMapPadding?,
|
|
299
|
+
animated: Bool?,
|
|
300
|
+
durationMS: Double?
|
|
301
|
+
) {
|
|
302
|
+
onMain {
|
|
303
|
+
self.impl.setCameraToCoordinates(
|
|
304
|
+
coordinates: coordinates,
|
|
305
|
+
padding: padding ?? RNMapPadding(0, 0, 0, 0),
|
|
306
|
+
animated: animated ?? true,
|
|
307
|
+
durationMS: durationMS ?? 3000
|
|
308
|
+
)
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
310
312
|
func showLocationDialog() {
|
|
311
313
|
locationHandler.showLocationDialog()
|
|
312
314
|
}
|
|
@@ -324,61 +326,6 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
|
|
|
324
326
|
/// not supported
|
|
325
327
|
return true
|
|
326
328
|
}
|
|
327
|
-
|
|
328
|
-
private func mapCameraToGMSCamera(_ c: RNCamera?) -> GMSCameraPosition? {
|
|
329
|
-
guard let c = c else { return nil }
|
|
330
|
-
|
|
331
|
-
let current = impl.currentCamera
|
|
332
|
-
let center = CLLocationCoordinate2D(
|
|
333
|
-
latitude: c.center?.latitude ?? current?.target.latitude ?? 0,
|
|
334
|
-
longitude: c.center?.longitude ?? current?.target.longitude ?? 0
|
|
335
|
-
)
|
|
336
|
-
let z = Float(c.zoom ?? Double(current?.zoom ?? 0))
|
|
337
|
-
let b = c.bearing ?? current?.bearing ?? 0
|
|
338
|
-
let t = c.tilt ?? current?.viewingAngle ?? 0
|
|
339
|
-
|
|
340
|
-
return GMSCameraPosition.camera(
|
|
341
|
-
withTarget: center,
|
|
342
|
-
zoom: z,
|
|
343
|
-
bearing: b,
|
|
344
|
-
viewingAngle: t
|
|
345
|
-
)
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
func mapUserInterfaceStyleToUIUserInterfaceStyle(
|
|
349
|
-
_ style: RNUserInterfaceStyle?
|
|
350
|
-
) -> UIUserInterfaceStyle? {
|
|
351
|
-
guard let style = style else { return nil }
|
|
352
|
-
|
|
353
|
-
switch style {
|
|
354
|
-
case .light:
|
|
355
|
-
return .light
|
|
356
|
-
case .dark:
|
|
357
|
-
return .dark
|
|
358
|
-
case .default:
|
|
359
|
-
return .unspecified
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
extension UIUserInterfaceStyle {
|
|
365
|
-
init?(fromString string: String) {
|
|
366
|
-
switch string.lowercased() {
|
|
367
|
-
case "light": self = .light
|
|
368
|
-
case "dark": self = .dark
|
|
369
|
-
case "default": self = .unspecified
|
|
370
|
-
default: return nil
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
var stringValue: String {
|
|
375
|
-
switch self {
|
|
376
|
-
case .light: return "light"
|
|
377
|
-
case .dark: return "dark"
|
|
378
|
-
case .unspecified: return "default"
|
|
379
|
-
@unknown default: return "default"
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
329
|
}
|
|
383
330
|
|
|
384
331
|
@inline(__always)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
import GoogleMaps
|
|
3
|
+
|
|
4
|
+
extension RNCamera {
|
|
5
|
+
func toGMSCameraPosition(current: GMSCameraPosition?) -> GMSCameraPosition {
|
|
6
|
+
let center = CLLocationCoordinate2D(
|
|
7
|
+
latitude: center?.latitude ?? current?.target.latitude ?? 0,
|
|
8
|
+
longitude: center?.longitude ?? current?.target.longitude ?? 0
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
let zoom = Float(zoom ?? Double(current?.zoom ?? 0))
|
|
12
|
+
let bearing = bearing ?? current?.bearing ?? 0
|
|
13
|
+
let tilt = tilt ?? current?.viewingAngle ?? 0
|
|
14
|
+
|
|
15
|
+
return GMSCameraPosition.camera(
|
|
16
|
+
withTarget: center,
|
|
17
|
+
zoom: zoom,
|
|
18
|
+
bearing: bearing,
|
|
19
|
+
viewingAngle: tilt
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1,24 +1,5 @@
|
|
|
1
1
|
import GoogleMaps
|
|
2
2
|
|
|
3
|
-
class MapCircleOptions {
|
|
4
|
-
|
|
5
|
-
func buildCircle(_ c: RNCircle) -> GMSCircle {
|
|
6
|
-
let circle = GMSCircle()
|
|
7
|
-
circle.position = CLLocationCoordinate2D(
|
|
8
|
-
latitude: c.center.latitude,
|
|
9
|
-
longitude: c.center.longitude
|
|
10
|
-
)
|
|
11
|
-
if let r = c.radius { circle.radius = r }
|
|
12
|
-
if let fc = c.fillColor?.toUIColor() { circle.fillColor = fc }
|
|
13
|
-
if let sc = c.strokeColor?.toUIColor() { circle.strokeColor = sc }
|
|
14
|
-
if let sw = c.strokeWidth { circle.strokeWidth = CGFloat(sw) }
|
|
15
|
-
if let pr = c.pressable { circle.isTappable = pr }
|
|
16
|
-
if let zi = c.zIndex { circle.zIndex = Int32(zi) }
|
|
17
|
-
|
|
18
|
-
return circle
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
3
|
extension RNCircle {
|
|
23
4
|
func updateCircle(_ next: RNCircle, _ c: GMSCircle) {
|
|
24
5
|
c.position = CLLocationCoordinate2D(
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import CoreLocation
|
|
2
|
+
|
|
3
|
+
extension RNIOSLocationAccuracy {
|
|
4
|
+
var toCLLocationAccuracy: CLLocationAccuracy {
|
|
5
|
+
switch self {
|
|
6
|
+
case .accuracyBest:
|
|
7
|
+
return kCLLocationAccuracyBest
|
|
8
|
+
|
|
9
|
+
case .accuracyNearestTenMeter:
|
|
10
|
+
return kCLLocationAccuracyNearestTenMeters
|
|
11
|
+
|
|
12
|
+
case .accuracyNearestHundredMeter:
|
|
13
|
+
return kCLLocationAccuracyHundredMeters
|
|
14
|
+
|
|
15
|
+
case .accuracyKilometer:
|
|
16
|
+
return kCLLocationAccuracyKilometer
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import GoogleMaps
|
|
2
|
+
|
|
3
|
+
extension RNMarker {
|
|
4
|
+
func markerEquals(_ b: RNMarker) -> Bool {
|
|
5
|
+
id == b.id && zIndex == b.zIndex
|
|
6
|
+
&& coordinate.latitude == b.coordinate.latitude
|
|
7
|
+
&& coordinate.longitude == b.coordinate.longitude
|
|
8
|
+
&& anchor?.x == b.anchor?.x && anchor?.y == b.anchor?.y
|
|
9
|
+
&& markerStyleEquals(b)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
func markerStyleEquals(_ b: RNMarker) -> Bool {
|
|
13
|
+
iconSvg?.width == b.iconSvg?.width && iconSvg?.height == b.iconSvg?.height
|
|
14
|
+
&& iconSvg?.svgString == b.iconSvg?.svgString
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
func styleHash() -> NSString {
|
|
19
|
+
var hasher = Hasher()
|
|
20
|
+
hasher.combine(iconSvg?.width)
|
|
21
|
+
hasher.combine(iconSvg?.height)
|
|
22
|
+
hasher.combine(iconSvg?.svgString)
|
|
23
|
+
return String(hasher.finalize()) as NSString
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,24 +1,5 @@
|
|
|
1
1
|
import GoogleMaps
|
|
2
2
|
|
|
3
|
-
class MapPolygonOptions {
|
|
4
|
-
|
|
5
|
-
func buildPolygon(_ p: RNPolygon) -> GMSPolygon {
|
|
6
|
-
let path = GMSMutablePath()
|
|
7
|
-
p.coordinates.forEach {
|
|
8
|
-
path.add(
|
|
9
|
-
CLLocationCoordinate2D(latitude: $0.latitude, longitude: $0.longitude)
|
|
10
|
-
)
|
|
11
|
-
}
|
|
12
|
-
let pg = GMSPolygon(path: path)
|
|
13
|
-
if let fc = p.fillColor?.toUIColor() { pg.fillColor = fc }
|
|
14
|
-
if let sc = p.strokeColor?.toUIColor() { pg.strokeColor = sc }
|
|
15
|
-
if let sw = p.strokeWidth { pg.strokeWidth = CGFloat(sw) }
|
|
16
|
-
if let pr = p.pressable { pg.isTappable = pr }
|
|
17
|
-
if let zi = p.zIndex { pg.zIndex = Int32(zi) }
|
|
18
|
-
return pg
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
3
|
extension RNPolygon {
|
|
23
4
|
func updatePolygon(_ next: RNPolygon, _ pg: GMSPolygon) {
|
|
24
5
|
let path = GMSMutablePath()
|