@lugg/maps 0.2.0-alpha.9 → 1.0.0-beta.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 (184) hide show
  1. package/README.md +21 -20
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/luggmaps/LuggCalloutView.kt +74 -0
  4. package/android/src/main/java/com/luggmaps/LuggCalloutViewManager.kt +38 -0
  5. package/android/src/main/java/com/luggmaps/LuggMapView.kt +290 -0
  6. package/android/src/main/java/com/luggmaps/{LuggGoogleMapViewManager.kt → LuggMapViewManager.kt} +99 -36
  7. package/android/src/main/java/com/luggmaps/LuggMapWrapperView.kt +11 -14
  8. package/android/src/main/java/com/luggmaps/LuggMarkerView.kt +187 -21
  9. package/android/src/main/java/com/luggmaps/LuggMarkerViewManager.kt +28 -0
  10. package/android/src/main/java/com/luggmaps/LuggPackage.kt +8 -4
  11. package/android/src/main/java/com/luggmaps/LuggPolygonView.kt +85 -0
  12. package/android/src/main/java/com/luggmaps/LuggPolygonViewManager.kt +100 -0
  13. package/android/src/main/java/com/luggmaps/LuggPolylineView.kt +16 -0
  14. package/android/src/main/java/com/luggmaps/LuggPolylineViewManager.kt +22 -0
  15. package/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt +874 -0
  16. package/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +60 -0
  17. package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +89 -24
  18. package/android/src/main/java/com/luggmaps/events/LongPressEvent.kt +29 -0
  19. package/android/src/main/java/com/luggmaps/events/MarkerDragEvent.kt +41 -0
  20. package/android/src/main/java/com/luggmaps/events/MarkerPressEvent.kt +34 -0
  21. package/android/src/main/java/com/luggmaps/events/PolygonPressEvent.kt +12 -0
  22. package/android/src/main/java/com/luggmaps/events/PressEvent.kt +29 -0
  23. package/ios/LuggCalloutView.h +23 -0
  24. package/ios/LuggCalloutView.mm +145 -0
  25. package/ios/LuggMapView.h +9 -0
  26. package/ios/LuggMapView.mm +343 -0
  27. package/ios/LuggMarkerView.h +15 -0
  28. package/ios/LuggMarkerView.mm +136 -2
  29. package/ios/LuggPolygonView.h +31 -0
  30. package/ios/LuggPolygonView.mm +151 -0
  31. package/ios/LuggPolylineView.h +4 -0
  32. package/ios/LuggPolylineView.mm +23 -0
  33. package/ios/core/AppleMapProvider.h +15 -0
  34. package/ios/core/AppleMapProvider.mm +1173 -0
  35. package/ios/core/GMSPolylineAnimator.h +3 -0
  36. package/ios/core/GMSPolylineAnimator.m +101 -15
  37. package/ios/core/GoogleMapProvider.h +13 -0
  38. package/ios/core/GoogleMapProvider.mm +798 -0
  39. package/ios/core/LuggAnnotationView.h +12 -0
  40. package/ios/core/LuggAnnotationView.mm +55 -0
  41. package/ios/core/MKPolylineAnimator.h +4 -0
  42. package/ios/core/MKPolylineAnimator.m +167 -42
  43. package/ios/core/MapProviderDelegate.h +84 -0
  44. package/ios/core/PolylineAnimatorBase.h +24 -1
  45. package/ios/core/PolylineAnimatorBase.m +82 -19
  46. package/ios/events/LongPressEvent.h +29 -0
  47. package/ios/events/MarkerDragEvent.h +69 -0
  48. package/ios/events/MarkerPressEvent.h +29 -0
  49. package/ios/events/PolygonPressEvent.h +20 -0
  50. package/ios/events/PressEvent.h +29 -0
  51. package/ios/extensions/MKMapView+Zoom.h +2 -0
  52. package/ios/extensions/MKMapView+Zoom.m +14 -4
  53. package/lib/module/MapProvider.js +2 -4
  54. package/lib/module/MapProvider.js.map +1 -1
  55. package/lib/module/MapProvider.web.js +14 -7
  56. package/lib/module/MapProvider.web.js.map +1 -1
  57. package/lib/module/MapView.js +33 -16
  58. package/lib/module/MapView.js.map +1 -1
  59. package/lib/module/MapView.web.js +296 -181
  60. package/lib/module/MapView.web.js.map +1 -1
  61. package/lib/module/components/GeoJson.js +159 -0
  62. package/lib/module/components/GeoJson.js.map +1 -0
  63. package/lib/module/components/GeoJson.types.js +4 -0
  64. package/lib/module/components/GeoJson.types.js.map +1 -0
  65. package/lib/module/components/Marker.js +49 -8
  66. package/lib/module/components/Marker.js.map +1 -1
  67. package/lib/module/components/Marker.types.js +4 -0
  68. package/lib/module/components/Marker.types.js.map +1 -0
  69. package/lib/module/components/Marker.web.js +159 -24
  70. package/lib/module/components/Marker.web.js.map +1 -1
  71. package/lib/module/components/Polygon.js +46 -0
  72. package/lib/module/components/Polygon.js.map +1 -0
  73. package/lib/module/components/Polygon.types.js +4 -0
  74. package/lib/module/components/Polygon.types.js.map +1 -0
  75. package/lib/module/components/Polygon.web.js +87 -0
  76. package/lib/module/components/Polygon.web.js.map +1 -0
  77. package/lib/module/components/Polyline.js +17 -4
  78. package/lib/module/components/Polyline.js.map +1 -1
  79. package/lib/module/components/Polyline.types.js +4 -0
  80. package/lib/module/components/Polyline.types.js.map +1 -0
  81. package/lib/module/components/Polyline.web.js +108 -31
  82. package/lib/module/components/Polyline.web.js.map +1 -1
  83. package/lib/module/components/index.js +4 -2
  84. package/lib/module/components/index.js.map +1 -1
  85. package/lib/module/components/index.web.js +2 -0
  86. package/lib/module/components/index.web.js.map +1 -1
  87. package/lib/module/fabric/LuggCalloutViewNativeComponent.ts +20 -0
  88. package/lib/module/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +43 -7
  89. package/lib/module/fabric/LuggMarkerViewNativeComponent.ts +49 -1
  90. package/lib/module/fabric/LuggPolygonViewNativeComponent.ts +25 -0
  91. package/lib/module/fabric/LuggPolylineViewNativeComponent.ts +8 -0
  92. package/lib/module/index.js +4 -1
  93. package/lib/module/index.js.map +1 -1
  94. package/lib/module/index.web.js +4 -1
  95. package/lib/module/index.web.js.map +1 -1
  96. package/lib/typescript/src/MapProvider.d.ts +1 -1
  97. package/lib/typescript/src/MapProvider.d.ts.map +1 -1
  98. package/lib/typescript/src/MapProvider.web.d.ts +23 -1
  99. package/lib/typescript/src/MapProvider.web.d.ts.map +1 -1
  100. package/lib/typescript/src/MapView.d.ts +4 -4
  101. package/lib/typescript/src/MapView.d.ts.map +1 -1
  102. package/lib/typescript/src/MapView.types.d.ts +35 -9
  103. package/lib/typescript/src/MapView.types.d.ts.map +1 -1
  104. package/lib/typescript/src/MapView.web.d.ts +2 -11
  105. package/lib/typescript/src/MapView.web.d.ts.map +1 -1
  106. package/lib/typescript/src/components/GeoJson.d.ts +4 -0
  107. package/lib/typescript/src/components/GeoJson.d.ts.map +1 -0
  108. package/lib/typescript/src/components/GeoJson.types.d.ts +89 -0
  109. package/lib/typescript/src/components/GeoJson.types.d.ts.map +1 -0
  110. package/lib/typescript/src/components/Marker.d.ts +6 -33
  111. package/lib/typescript/src/components/Marker.d.ts.map +1 -1
  112. package/lib/typescript/src/components/Marker.types.d.ts +100 -0
  113. package/lib/typescript/src/components/Marker.types.d.ts.map +1 -0
  114. package/lib/typescript/src/components/Marker.web.d.ts +2 -5
  115. package/lib/typescript/src/components/Marker.web.d.ts.map +1 -1
  116. package/lib/typescript/src/components/Polygon.d.ts +10 -0
  117. package/lib/typescript/src/components/Polygon.d.ts.map +1 -0
  118. package/lib/typescript/src/components/Polygon.types.d.ts +33 -0
  119. package/lib/typescript/src/components/Polygon.types.d.ts.map +1 -0
  120. package/lib/typescript/src/components/Polygon.web.d.ts +3 -0
  121. package/lib/typescript/src/components/Polygon.web.d.ts.map +1 -0
  122. package/lib/typescript/src/components/Polyline.d.ts +6 -21
  123. package/lib/typescript/src/components/Polyline.d.ts.map +1 -1
  124. package/lib/typescript/src/components/Polyline.types.d.ts +53 -0
  125. package/lib/typescript/src/components/Polyline.types.d.ts.map +1 -0
  126. package/lib/typescript/src/components/Polyline.web.d.ts +2 -5
  127. package/lib/typescript/src/components/Polyline.web.d.ts.map +1 -1
  128. package/lib/typescript/src/components/index.d.ts +8 -2
  129. package/lib/typescript/src/components/index.d.ts.map +1 -1
  130. package/lib/typescript/src/components/index.web.d.ts +6 -2
  131. package/lib/typescript/src/components/index.web.d.ts.map +1 -1
  132. package/lib/typescript/src/fabric/LuggCalloutViewNativeComponent.d.ts +13 -0
  133. package/lib/typescript/src/fabric/LuggCalloutViewNativeComponent.d.ts.map +1 -0
  134. package/lib/typescript/src/fabric/{LuggGoogleMapViewNativeComponent.d.ts → LuggMapViewNativeComponent.d.ts} +30 -4
  135. package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts.map +1 -0
  136. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts +45 -1
  137. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts.map +1 -1
  138. package/lib/typescript/src/fabric/LuggPolygonViewNativeComponent.d.ts +18 -0
  139. package/lib/typescript/src/fabric/LuggPolygonViewNativeComponent.d.ts.map +1 -0
  140. package/lib/typescript/src/fabric/LuggPolylineViewNativeComponent.d.ts +7 -0
  141. package/lib/typescript/src/fabric/LuggPolylineViewNativeComponent.d.ts.map +1 -1
  142. package/lib/typescript/src/index.d.ts +11 -3
  143. package/lib/typescript/src/index.d.ts.map +1 -1
  144. package/lib/typescript/src/index.web.d.ts +9 -1
  145. package/lib/typescript/src/index.web.d.ts.map +1 -1
  146. package/lib/typescript/src/types.d.ts +11 -0
  147. package/lib/typescript/src/types.d.ts.map +1 -1
  148. package/package.json +11 -9
  149. package/src/MapProvider.tsx +1 -3
  150. package/src/MapProvider.web.tsx +22 -3
  151. package/src/MapView.tsx +32 -26
  152. package/src/MapView.types.ts +43 -9
  153. package/src/MapView.web.tsx +368 -210
  154. package/src/components/GeoJson.tsx +221 -0
  155. package/src/components/GeoJson.types.ts +118 -0
  156. package/src/components/Marker.tsx +75 -38
  157. package/src/components/Marker.types.ts +102 -0
  158. package/src/components/Marker.web.tsx +197 -19
  159. package/src/components/Polygon.tsx +52 -0
  160. package/src/components/Polygon.types.ts +33 -0
  161. package/src/components/Polygon.web.tsx +104 -0
  162. package/src/components/Polyline.tsx +23 -22
  163. package/src/components/Polyline.types.ts +55 -0
  164. package/src/components/Polyline.web.tsx +151 -37
  165. package/src/components/index.ts +17 -2
  166. package/src/components/index.web.ts +6 -2
  167. package/src/fabric/LuggCalloutViewNativeComponent.ts +20 -0
  168. package/src/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +43 -7
  169. package/src/fabric/LuggMarkerViewNativeComponent.ts +49 -1
  170. package/src/fabric/LuggPolygonViewNativeComponent.ts +25 -0
  171. package/src/fabric/LuggPolylineViewNativeComponent.ts +8 -0
  172. package/src/index.ts +30 -1
  173. package/src/index.web.ts +16 -1
  174. package/src/types.ts +13 -0
  175. package/android/src/main/java/com/luggmaps/LuggGoogleMapView.kt +0 -511
  176. package/ios/LuggAppleMapView.h +0 -16
  177. package/ios/LuggAppleMapView.mm +0 -592
  178. package/ios/LuggGoogleMapView.h +0 -13
  179. package/ios/LuggGoogleMapView.mm +0 -455
  180. package/lib/module/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
  181. package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts +0 -54
  182. package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts.map +0 -1
  183. package/lib/typescript/src/fabric/LuggGoogleMapViewNativeComponent.d.ts.map +0 -1
  184. package/src/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
@@ -1,511 +0,0 @@
1
- package com.luggmaps
2
-
3
- import android.annotation.SuppressLint
4
- import android.view.View
5
- import android.view.ViewGroup
6
- import com.facebook.react.uimanager.PixelUtil.dpToPx
7
- import com.facebook.react.uimanager.ThemedReactContext
8
- import com.facebook.react.util.RNLog
9
- import com.facebook.react.views.view.ReactViewGroup
10
- import com.google.android.gms.maps.CameraUpdateFactory
11
- import com.google.android.gms.maps.GoogleMap
12
- import com.google.android.gms.maps.GoogleMapOptions
13
- import com.google.android.gms.maps.MapView
14
- import com.google.android.gms.maps.OnMapReadyCallback
15
- import com.google.android.gms.maps.model.AdvancedMarker
16
- import com.google.android.gms.maps.model.AdvancedMarkerOptions
17
- import com.google.android.gms.maps.model.AdvancedMarkerOptions.CollisionBehavior
18
- import com.google.android.gms.maps.model.LatLng
19
- import com.google.android.gms.maps.model.PolylineOptions
20
- import com.luggmaps.core.PolylineAnimator
21
-
22
- interface LuggGoogleMapViewEventDelegate {
23
- fun onCameraMove(
24
- view: LuggGoogleMapView,
25
- latitude: Double,
26
- longitude: Double,
27
- zoom: Float,
28
- gesture: Boolean
29
- )
30
- fun onCameraIdle(
31
- view: LuggGoogleMapView,
32
- latitude: Double,
33
- longitude: Double,
34
- zoom: Float,
35
- gesture: Boolean
36
- )
37
- fun onReady(view: LuggGoogleMapView)
38
- }
39
-
40
- @SuppressLint("ViewConstructor")
41
- class LuggGoogleMapView(private val reactContext: ThemedReactContext) :
42
- ReactViewGroup(reactContext),
43
- OnMapReadyCallback,
44
- LuggMarkerViewDelegate,
45
- LuggPolylineViewDelegate,
46
- GoogleMap.OnCameraMoveStartedListener,
47
- GoogleMap.OnCameraMoveListener,
48
- GoogleMap.OnCameraIdleListener {
49
-
50
- var eventDelegate: LuggGoogleMapViewEventDelegate? = null
51
- private var mapView: MapView? = null
52
- private var mapWrapperView: LuggMapWrapperView? = null
53
- private var googleMap: GoogleMap? = null
54
- private var isMapReady = false
55
- private var isDragging = false
56
- private var mapId: String = DEMO_MAP_ID
57
- private val pendingMarkerViews = mutableListOf<LuggMarkerView>()
58
- private val pendingPolylineViews = mutableListOf<LuggPolylineView>()
59
- private val polylineAnimators = mutableMapOf<LuggPolylineView, PolylineAnimator>()
60
-
61
- // Initial camera settings
62
- private var initialLatitude: Double = 37.78
63
- private var initialLongitude: Double = -122.43
64
- private var initialZoom: Float = 14f
65
-
66
- // UI settings
67
- private var zoomEnabled: Boolean = true
68
- private var scrollEnabled: Boolean = true
69
- private var rotateEnabled: Boolean = true
70
- private var pitchEnabled: Boolean = true
71
- private var userLocationEnabled: Boolean = false
72
-
73
- // Zoom limits
74
- private var minZoom: Float? = null
75
- private var maxZoom: Float? = null
76
-
77
- // Padding
78
- private var paddingTop: Int = 0
79
- private var paddingLeft: Int = 0
80
- private var paddingBottom: Int = 0
81
- private var paddingRight: Int = 0
82
-
83
- // region View Lifecycle
84
-
85
- override fun addView(child: View?, index: Int) {
86
- super.addView(child, index)
87
- when (child) {
88
- is LuggMapWrapperView -> mapWrapperView = child
89
-
90
- is LuggMarkerView -> {
91
- child.delegate = this
92
- syncMarkerView(child)
93
- }
94
-
95
- is LuggPolylineView -> {
96
- child.delegate = this
97
- syncPolylineView(child)
98
- }
99
- }
100
- }
101
-
102
- override fun removeViewAt(index: Int) {
103
- val view = getChildAt(index)
104
- if (view is LuggMarkerView) {
105
- view.marker?.remove()
106
- view.marker = null
107
- } else if (view is LuggPolylineView) {
108
- polylineAnimators[view]?.destroy()
109
- polylineAnimators.remove(view)
110
- view.polyline?.remove()
111
- view.polyline = null
112
- }
113
- super.removeViewAt(index)
114
- }
115
-
116
- override fun onAttachedToWindow() {
117
- super.onAttachedToWindow()
118
- if (mapView == null && mapWrapperView != null) {
119
- initializeMap()
120
- }
121
- }
122
-
123
- fun onDropViewInstance() {
124
- pendingMarkerViews.clear()
125
- pendingPolylineViews.clear()
126
- polylineAnimators.values.forEach { it.destroy() }
127
- polylineAnimators.clear()
128
- googleMap?.clear()
129
- googleMap = null
130
- isMapReady = false
131
- mapView?.onPause()
132
- mapView?.onDestroy()
133
- mapView = null
134
- mapWrapperView = null
135
- }
136
-
137
- // endregion
138
-
139
- // region Map Initialization
140
-
141
- private fun initializeMap() {
142
- if (mapView != null || mapWrapperView == null) return
143
-
144
- val options = GoogleMapOptions().mapId(mapId)
145
- mapView = MapView(context, options).also { view ->
146
- view.onCreate(null)
147
- view.onResume()
148
- view.getMapAsync(this)
149
- mapWrapperView?.addView(
150
- view,
151
- LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
152
- )
153
- }
154
- }
155
-
156
- override fun onMapReady(map: GoogleMap) {
157
- googleMap = map
158
- isMapReady = true
159
-
160
- val position = LatLng(initialLatitude, initialLongitude)
161
- map.moveCamera(CameraUpdateFactory.newLatLngZoom(position, initialZoom))
162
-
163
- map.setOnCameraMoveStartedListener(this)
164
- map.setOnCameraMoveListener(this)
165
- map.setOnCameraIdleListener(this)
166
-
167
- applyUiSettings()
168
- applyZoomLimits()
169
- applyPadding()
170
- applyUserLocation()
171
- processPendingMarkers()
172
- processPendingPolylines()
173
-
174
- eventDelegate?.onReady(this)
175
- }
176
-
177
- override fun onCameraMoveStarted(reason: Int) {
178
- isDragging = reason == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE
179
- }
180
-
181
- override fun onCameraMove() {
182
- val map = googleMap ?: return
183
- val position = map.cameraPosition
184
- eventDelegate?.onCameraMove(this, position.target.latitude, position.target.longitude, position.zoom, isDragging)
185
- }
186
-
187
- override fun onCameraIdle() {
188
- val map = googleMap ?: return
189
- val position = map.cameraPosition
190
- eventDelegate?.onCameraIdle(this, position.target.latitude, position.target.longitude, position.zoom, isDragging)
191
- isDragging = false
192
- }
193
-
194
- private fun applyUiSettings() {
195
- googleMap?.uiSettings?.apply {
196
- isZoomGesturesEnabled = zoomEnabled
197
- isScrollGesturesEnabled = scrollEnabled
198
- isRotateGesturesEnabled = rotateEnabled
199
- isTiltGesturesEnabled = pitchEnabled
200
- }
201
- }
202
-
203
- private fun applyZoomLimits() {
204
- googleMap?.apply {
205
- minZoom?.let { setMinZoomPreference(it) }
206
- maxZoom?.let { setMaxZoomPreference(it) }
207
- }
208
- }
209
-
210
- private fun applyPadding() {
211
- googleMap?.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom)
212
- }
213
-
214
- @SuppressLint("MissingPermission")
215
- private fun applyUserLocation() {
216
- val hasPermission =
217
- context.checkSelfPermission(
218
- android.Manifest.permission.ACCESS_FINE_LOCATION
219
- ) == android.content.pm.PackageManager.PERMISSION_GRANTED ||
220
- context.checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) ==
221
- android.content.pm.PackageManager.PERMISSION_GRANTED
222
- googleMap?.isMyLocationEnabled = userLocationEnabled && hasPermission
223
- }
224
-
225
- // endregion
226
-
227
- // region PolylineViewDelegate
228
-
229
- override fun polylineViewDidUpdate(polylineView: LuggPolylineView) {
230
- syncPolylineView(polylineView)
231
- }
232
-
233
- // endregion
234
-
235
- // region MarkerViewDelegate
236
-
237
- override fun markerViewDidLayout(markerView: LuggMarkerView) {
238
- if (googleMap == null) {
239
- if (!pendingMarkerViews.contains(markerView)) {
240
- pendingMarkerViews.add(markerView)
241
- }
242
- return
243
- }
244
-
245
- if (markerView.hasCustomView) {
246
- // Recreate marker with custom view
247
- markerView.marker?.remove()
248
- addMarkerViewToMap(markerView)
249
- } else {
250
- syncMarkerView(markerView)
251
- }
252
- }
253
-
254
- override fun markerViewDidUpdate(markerView: LuggMarkerView) {
255
- syncMarkerView(markerView)
256
- }
257
-
258
- // endregion
259
-
260
- // region Marker Management
261
-
262
- private fun syncMarkerView(markerView: LuggMarkerView) {
263
- if (googleMap == null) {
264
- if (!pendingMarkerViews.contains(markerView)) {
265
- pendingMarkerViews.add(markerView)
266
- }
267
- return
268
- }
269
-
270
- if (markerView.marker == null) {
271
- // Custom views need layout first before adding to map
272
- if (markerView.hasCustomView) return
273
- addMarkerViewToMap(markerView)
274
- return
275
- }
276
-
277
- markerView.marker?.apply {
278
- position = LatLng(markerView.latitude, markerView.longitude)
279
- title = markerView.title
280
- snippet = markerView.description
281
- setAnchor(markerView.anchorX, markerView.anchorY)
282
- zIndex = markerView.zIndex
283
- if (!markerView.hasCustomView) {
284
- iconView = null
285
- }
286
- }
287
- }
288
-
289
- private fun processPendingMarkers() {
290
- if (googleMap == null) return
291
-
292
- pendingMarkerViews.forEach { addMarkerViewToMap(it) }
293
- pendingMarkerViews.clear()
294
- }
295
-
296
- private fun addMarkerViewToMap(markerView: LuggMarkerView) {
297
- val map = googleMap ?: run {
298
- RNLog.w(reactContext, "Lugg: addMarkerViewToMap called without a map")
299
- return
300
- }
301
-
302
- val position = LatLng(markerView.latitude, markerView.longitude)
303
- val iconView = markerView.iconView
304
-
305
- (iconView.parent as? ViewGroup)?.removeView(iconView)
306
-
307
- val options = AdvancedMarkerOptions()
308
- .position(position)
309
- .title(markerView.title)
310
- .snippet(markerView.description)
311
-
312
- if (markerView.hasCustomView) {
313
- options.iconView(iconView)
314
- }
315
-
316
- val marker = map.addMarker(options) as AdvancedMarker
317
- marker.setAnchor(markerView.anchorX, markerView.anchorY)
318
- marker.zIndex = markerView.zIndex
319
-
320
- markerView.marker = marker
321
- }
322
-
323
- // endregion
324
-
325
- // region Polyline Management
326
-
327
- private fun syncPolylineView(polylineView: LuggPolylineView) {
328
- if (googleMap == null) {
329
- if (!pendingPolylineViews.contains(polylineView)) {
330
- pendingPolylineViews.add(polylineView)
331
- }
332
- return
333
- }
334
-
335
- if (polylineView.polyline == null) {
336
- addPolylineViewToMap(polylineView)
337
- return
338
- }
339
-
340
- polylineView.polyline?.width = polylineView.strokeWidth.dpToPx()
341
-
342
- polylineAnimators[polylineView]?.apply {
343
- coordinates = polylineView.coordinates
344
- strokeColors = polylineView.strokeColors
345
- strokeWidth = polylineView.strokeWidth.dpToPx()
346
- animated = polylineView.animated
347
- update()
348
- }
349
- }
350
-
351
- private fun processPendingPolylines() {
352
- if (googleMap == null) return
353
-
354
- pendingPolylineViews.forEach { addPolylineViewToMap(it) }
355
- pendingPolylineViews.clear()
356
- }
357
-
358
- private fun addPolylineViewToMap(polylineView: LuggPolylineView) {
359
- val map = googleMap ?: return
360
-
361
- val options = PolylineOptions()
362
- .width(polylineView.strokeWidth.dpToPx())
363
-
364
- val polyline = map.addPolyline(options)
365
- polylineView.polyline = polyline
366
-
367
- val animator = PolylineAnimator().apply {
368
- this.polyline = polyline
369
- coordinates = polylineView.coordinates
370
- strokeColors = polylineView.strokeColors
371
- strokeWidth = polylineView.strokeWidth.dpToPx()
372
- animated = polylineView.animated
373
- update()
374
- }
375
-
376
- polylineAnimators[polylineView] = animator
377
- }
378
-
379
- // endregion
380
-
381
- // region Property Setters
382
-
383
- fun setMapId(value: String?) {
384
- if (value.isNullOrEmpty()) return
385
-
386
- if (mapView != null) {
387
- RNLog.w(reactContext, "Lugg: mapId cannot be changed after map is initialized")
388
- return
389
- }
390
-
391
- mapId = value
392
- }
393
-
394
- fun setInitialCoordinate(latitude: Double, longitude: Double) {
395
- initialLatitude = latitude
396
- initialLongitude = longitude
397
- }
398
-
399
- fun setInitialZoom(zoom: Double) {
400
- initialZoom = zoom.toFloat()
401
- }
402
-
403
- fun setZoomEnabled(enabled: Boolean) {
404
- zoomEnabled = enabled
405
- googleMap?.uiSettings?.isZoomGesturesEnabled = enabled
406
- }
407
-
408
- fun setScrollEnabled(enabled: Boolean) {
409
- scrollEnabled = enabled
410
- googleMap?.uiSettings?.isScrollGesturesEnabled = enabled
411
- }
412
-
413
- fun setRotateEnabled(enabled: Boolean) {
414
- rotateEnabled = enabled
415
- googleMap?.uiSettings?.isRotateGesturesEnabled = enabled
416
- }
417
-
418
- fun setPitchEnabled(enabled: Boolean) {
419
- pitchEnabled = enabled
420
- googleMap?.uiSettings?.isTiltGesturesEnabled = enabled
421
- }
422
-
423
- fun setUserLocationEnabled(enabled: Boolean) {
424
- userLocationEnabled = enabled
425
- applyUserLocation()
426
- }
427
-
428
- fun setMinZoom(zoom: Double) {
429
- minZoom = if (zoom > 0) zoom.toFloat() else null
430
- googleMap?.let { map ->
431
- minZoom?.let { map.setMinZoomPreference(it) } ?: map.resetMinMaxZoomPreference()
432
- }
433
- }
434
-
435
- fun setMaxZoom(zoom: Double) {
436
- maxZoom = if (zoom > 0) zoom.toFloat() else null
437
- googleMap?.let { map ->
438
- maxZoom?.let { map.setMaxZoomPreference(it) } ?: map.resetMinMaxZoomPreference()
439
- }
440
- }
441
-
442
- fun setMapPadding(top: Int, left: Int, bottom: Int, right: Int) {
443
- paddingTop = top
444
- paddingLeft = left
445
- paddingBottom = bottom
446
- paddingRight = right
447
- applyPadding()
448
- }
449
-
450
- // endregion
451
-
452
- // region Commands
453
-
454
- fun moveCamera(latitude: Double, longitude: Double, zoom: Double, duration: Int) {
455
- val map = googleMap ?: return
456
- val position = LatLng(latitude, longitude)
457
- val cameraUpdate = CameraUpdateFactory.newLatLngZoom(position, zoom.toFloat())
458
- when {
459
- duration < 0 -> map.animateCamera(cameraUpdate)
460
- duration > 0 -> map.animateCamera(cameraUpdate, duration, null)
461
- else -> map.moveCamera(cameraUpdate)
462
- }
463
- }
464
-
465
- fun fitCoordinates(
466
- coordinates: List<LatLng>,
467
- paddingTop: Int,
468
- paddingLeft: Int,
469
- paddingBottom: Int,
470
- paddingRight: Int,
471
- duration: Int
472
- ) {
473
- val map = googleMap ?: return
474
- if (coordinates.isEmpty()) return
475
-
476
- val boundsBuilder = com.google.android.gms.maps.model.LatLngBounds.Builder()
477
- coordinates.forEach { boundsBuilder.include(it) }
478
- val bounds = boundsBuilder.build()
479
-
480
- val top = paddingTop.toFloat().dpToPx().toInt()
481
- val left = paddingLeft.toFloat().dpToPx().toInt()
482
- val bottom = paddingBottom.toFloat().dpToPx().toInt()
483
- val right = paddingRight.toFloat().dpToPx().toInt()
484
-
485
- // Set padding before camera update, then restore after
486
- map.setPadding(
487
- this.paddingLeft + left,
488
- this.paddingTop + top,
489
- this.paddingRight + right,
490
- this.paddingBottom + bottom
491
- )
492
-
493
- val cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, 0)
494
-
495
- when {
496
- duration < 0 -> map.animateCamera(cameraUpdate)
497
- duration > 0 -> map.animateCamera(cameraUpdate, duration, null)
498
- else -> map.moveCamera(cameraUpdate)
499
- }
500
-
501
- // Restore base padding
502
- map.setPadding(this.paddingLeft, this.paddingTop, this.paddingRight, this.paddingBottom)
503
- }
504
-
505
- // endregion
506
-
507
- companion object {
508
- private const val TAG = "Lugg"
509
- const val DEMO_MAP_ID = "DEMO_MAP_ID"
510
- }
511
- }
@@ -1,16 +0,0 @@
1
- #import <MapKit/MapKit.h>
2
- #import <React/RCTViewComponentView.h>
3
- #import <UIKit/UIKit.h>
4
-
5
- NS_ASSUME_NONNULL_BEGIN
6
-
7
- @interface LuggAppleMapViewContent : MKMapView
8
- @end
9
-
10
- @interface LuggAppleMapView : RCTViewComponentView
11
-
12
- - (MKMapView *)mapView;
13
-
14
- @end
15
-
16
- NS_ASSUME_NONNULL_END