forked from RxSwiftCommunity/RxGoogleMaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RxGoogleMapsBridge.swift
190 lines (149 loc) · 6.49 KB
/
RxGoogleMapsBridge.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Copyright (c) RxSwiftCommunity
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import Foundation
import UIKit
import GoogleMaps
import RxGoogleMaps
import RxCocoa
import RxSwift
extension RxGMSMapViewDelegateProxy: GMSMapViewDelegate {
public func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
return self.didHandleTap(marker)
}
public func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
return self.markerInfoWindow(marker: marker)
}
public func mapView(_ mapView: GMSMapView, markerInfoContents marker: GMSMarker) -> UIView? {
return self.markerInfoContents(marker: marker)
}
public func didTapMyLocationButton(for mapView: GMSMapView) -> Bool {
return self.didTapMyLocationButton()
}
}
extension GoogleMaps.GMSMapView: RxGMSMapView {
public var delegateWrapper: RxGMSMapViewDelegate? {
get { return delegate as? RxGMSMapViewDelegate }
set { delegate = newValue as? GMSMapViewDelegate }
}
public var cameraWrapper: RxGMSCameraPosition {
get { return camera as RxGMSCameraPosition }
set { camera = newValue as! GMSCameraPosition }
}
public var selectedMarkerWrapper: RxGMSMarker? {
get { return selectedMarker as? RxGMSMarker }
set { selectedMarker = newValue as? GMSMarker }
}
public func animateWrapper(to cameraPosition: RxGMSCameraPosition) {
animate(to: cameraPosition as! GMSCameraPosition)
}
public var settingsWrapper: RxGMSUISettings {
return settings as RxGMSUISettings
}
}
extension Reactive where Base: GoogleMaps.GMSMapView {
/**
Wrapper of: mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition)
*/
public var didChangePosition: ControlEvent<GMSCameraPosition> {
return ControlEvent(events: didChangePositionWrapper.map { $0 as! GMSCameraPosition })
}
/**
Wrapper of: mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition)
*/
public var idleAtPosition: ControlEvent<GMSCameraPosition> {
return ControlEvent(events: idleAtPositionWrapper.map { $0 as! GMSCameraPosition })
}
/**
Wrapper of: func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool
*/
public var didTapMarker: ControlEvent<GMSMarker> {
return ControlEvent(events: didTapMarkerWrapper.map { $0 as! GMSMarker })
}
/**
Wrapper of: func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker)
*/
public var didTapInfoWindow: ControlEvent<GMSMarker> {
return ControlEvent(events: didTapInfoWindowWrapper.map { $0 as! GMSMarker })
}
/**
Wrapper of: func mapView(_ mapView: GMSMapView, didLongPressInfoWindowOf marker: GMSMarker)
*/
public var didLongPressInfoWindow: ControlEvent<GMSMarker> {
return ControlEvent(events: didLongPressInfoWindowWrapper.map { $0 as! GMSMarker })
}
/**
Wrapper of: func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D)
*/
public var didTapOverlay: ControlEvent<GMSOverlay> {
return ControlEvent(events: didTapOverlayWrapper.map { $0 as! GMSOverlay })
}
/**
Wrapper of: func mapView(_ mapView: GMSMapView, didCloseInfoWindowOf marker: GMSMarker)
*/
public var didCloseInfoWindow: ControlEvent<GMSMarker> {
return ControlEvent(events: didCloseInfoWindowWrapper.map { $0 as! GMSMarker })
}
/**
Wrapper of: func mapView(_ mapView: GMSMapView, didBeginDragging marker: GMSMarker)
*/
public var didBeginDraggingMarker: ControlEvent<GMSMarker> {
return ControlEvent(events: didBeginDraggingMarkerWrapper.map { $0 as! GMSMarker })
}
/**
Wrapper of: func mapView(_ mapView: GMSMapView, didEndDragging marker: GMSMarker)
*/
public var didEndDraggingMarker: ControlEvent<GMSMarker> {
return ControlEvent(events: didEndDraggingMarkerWrapper.map { $0 as! GMSMarker })
}
/**
Wrapper of: func mapView(_ mapView: GMSMapView, didDrag marker: GMSMarker)
*/
public var didDragMarker: ControlEvent<GMSMarker> {
return ControlEvent(events: didDragMarkerWrapper.map { $0 as! GMSMarker })
}
}
extension Reactive where Base: GoogleMaps.GMSMapView {
public func handleTapMarker(_ closure: ((GMSMarker) -> (Bool))?) {
if let c = closure {
handleTapMarkerWrapper { c($0 as! GMSMarker) }
} else {
handleTapMarkerWrapper(nil)
}
}
public func handleMarkerInfoWindow(_ closure: ((GMSMarker) -> (UIView?))?) {
if let c = closure {
handleMarkerInfoWindowWrapper { c($0 as! GMSMarker) }
} else {
handleMarkerInfoWindowWrapper(nil)
}
}
public func handleMarkerInfoContents(_ closure: ((GMSMarker) -> (UIView?))?) {
if let c = closure {
handleMarkerInfoContentsWrapper { c($0 as! GMSMarker) }
} else {
handleMarkerInfoContentsWrapper(nil)
}
}
}
extension GoogleMaps.GMSUISettings: RxGMSUISettings { }
extension GoogleMaps.GMSCameraPosition: RxGMSCameraPosition { }
extension GoogleMaps.GMSOverlay: RxGMSOverlay { }
extension GoogleMaps.GMSMarker: RxGMSMarker { }
extension GoogleMaps.GMSCircle: RxGMSCircle { }
extension GoogleMaps.GMSPolyline: RxGMSPolyline { }
extension GoogleMaps.GMSPolygon: RxGMSPolygon { }
extension GoogleMaps.GMSGroundOverlay: RxGMSGroundOverlay { }