@lugg/maps 0.2.0-alpha.18 → 0.2.0-alpha.19

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 (40) hide show
  1. package/android/src/main/java/com/luggmaps/LuggGoogleMapView.kt +13 -0
  2. package/android/src/main/java/com/luggmaps/LuggMapWrapperView.kt +20 -0
  3. package/android/src/main/java/com/luggmaps/LuggMarkerView.kt +54 -13
  4. package/android/src/main/java/com/luggmaps/LuggMarkerViewManager.kt +10 -0
  5. package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +8 -0
  6. package/ios/LuggAppleMapView.mm +56 -33
  7. package/ios/LuggGoogleMapView.mm +43 -29
  8. package/ios/LuggMarkerView.h +4 -0
  9. package/ios/LuggMarkerView.mm +42 -0
  10. package/ios/core/GMSPolylineAnimator.h +2 -0
  11. package/ios/core/GMSPolylineAnimator.m +8 -0
  12. package/ios/core/MKPolylineAnimator.h +2 -0
  13. package/ios/core/MKPolylineAnimator.m +8 -0
  14. package/lib/module/MapProvider.web.js +5 -2
  15. package/lib/module/MapProvider.web.js.map +1 -1
  16. package/lib/module/MapView.web.js +14 -11
  17. package/lib/module/MapView.web.js.map +1 -1
  18. package/lib/module/components/Marker.js +4 -0
  19. package/lib/module/components/Marker.js.map +1 -1
  20. package/lib/module/components/Marker.web.js +8 -0
  21. package/lib/module/components/Marker.web.js.map +1 -1
  22. package/lib/module/components/Polyline.web.js +15 -4
  23. package/lib/module/components/Polyline.web.js.map +1 -1
  24. package/lib/module/fabric/LuggMarkerViewNativeComponent.ts +2 -0
  25. package/lib/typescript/src/MapProvider.web.d.ts +8 -2
  26. package/lib/typescript/src/MapProvider.web.d.ts.map +1 -1
  27. package/lib/typescript/src/components/Marker.d.ts +11 -0
  28. package/lib/typescript/src/components/Marker.d.ts.map +1 -1
  29. package/lib/typescript/src/components/Marker.web.d.ts +1 -1
  30. package/lib/typescript/src/components/Marker.web.d.ts.map +1 -1
  31. package/lib/typescript/src/components/Polyline.web.d.ts.map +1 -1
  32. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts +2 -0
  33. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts.map +1 -1
  34. package/package.json +1 -1
  35. package/src/MapProvider.web.tsx +5 -2
  36. package/src/MapView.web.tsx +11 -11
  37. package/src/components/Marker.tsx +15 -0
  38. package/src/components/Marker.web.tsx +9 -0
  39. package/src/components/Polyline.web.tsx +13 -4
  40. package/src/fabric/LuggMarkerViewNativeComponent.ts +2 -0
@@ -173,6 +173,9 @@ class LuggGoogleMapView(private val reactContext: ThemedReactContext) :
173
173
 
174
174
  override fun onCameraMoveStarted(reason: Int) {
175
175
  isDragging = reason == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE
176
+ if (isDragging) {
177
+ polylineAnimators.values.forEach { it.pause() }
178
+ }
176
179
  }
177
180
 
178
181
  override fun onCameraMove() {
@@ -185,6 +188,9 @@ class LuggGoogleMapView(private val reactContext: ThemedReactContext) :
185
188
  val map = googleMap ?: return
186
189
  val position = map.cameraPosition
187
190
  eventDelegate?.onCameraIdle(this, position.target.latitude, position.target.longitude, position.zoom, isDragging)
191
+ if (isDragging) {
192
+ polylineAnimators.values.forEach { it.resume() }
193
+ }
188
194
  isDragging = false
189
195
  }
190
196
 
@@ -271,6 +277,12 @@ class LuggGoogleMapView(private val reactContext: ThemedReactContext) :
271
277
  snippet = markerView.description
272
278
  setAnchor(markerView.anchorX, markerView.anchorY)
273
279
  zIndex = markerView.zIndex
280
+ rotation = markerView.rotate
281
+ }
282
+
283
+ if (markerView.hasCustomView && markerView.scaleChanged) {
284
+ markerView.applyScaleToMarker()
285
+ markerView.clearScaleChanged()
274
286
  }
275
287
  }
276
288
 
@@ -297,6 +309,7 @@ class LuggGoogleMapView(private val reactContext: ThemedReactContext) :
297
309
  val marker = map.addMarker(options) as AdvancedMarker
298
310
  marker.setAnchor(markerView.anchorX, markerView.anchorY)
299
311
  marker.zIndex = markerView.zIndex
312
+ marker.rotation = markerView.rotate
300
313
 
301
314
  markerView.marker = marker
302
315
  markerView.applyIconToMarker()
@@ -1,6 +1,7 @@
1
1
  package com.luggmaps
2
2
 
3
3
  import android.annotation.SuppressLint
4
+ import android.util.Log
4
5
  import com.facebook.react.uimanager.ThemedReactContext
5
6
  import com.facebook.react.views.view.ReactViewGroup
6
7
 
@@ -17,4 +18,23 @@ class LuggMapWrapperView(context: ThemedReactContext) : ReactViewGroup(context)
17
18
  it.layout(0, 0, width, height)
18
19
  }
19
20
  }
21
+
22
+ override fun onLayout(
23
+ changed: Boolean,
24
+ left: Int,
25
+ top: Int,
26
+ right: Int,
27
+ bottom: Int
28
+ ) {
29
+ super.onLayout(changed, left, top, right, bottom)
30
+ val w = right - left
31
+ val h = bottom - top
32
+ getChildAt(0)?.let {
33
+ it.measure(
34
+ MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY),
35
+ MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY)
36
+ )
37
+ it.layout(0, 0, w, h)
38
+ }
39
+ }
20
40
  }
@@ -18,6 +18,8 @@ interface LuggMarkerViewDelegate {
18
18
  }
19
19
 
20
20
  class LuggMarkerView(context: Context) : ReactViewGroup(context) {
21
+ private var scaleUpdateRunnable: Runnable? = null
22
+
21
23
  var name: String? = null
22
24
  private set
23
25
 
@@ -42,14 +44,21 @@ class LuggMarkerView(context: Context) : ReactViewGroup(context) {
42
44
  var zIndex: Float = 0f
43
45
  private set
44
46
 
47
+ var rotate: Float = 0f
48
+ private set
49
+
50
+ var scale: Float = 1f
51
+ private set
52
+
53
+ var scaleChanged: Boolean = false
54
+ private set
55
+
45
56
  var rasterize: Boolean = true
46
57
  private set
47
58
 
48
59
  var didLayout: Boolean = false
49
60
  private set
50
61
 
51
- var isPendingUpdate: Boolean = false
52
-
53
62
  val hasCustomView: Boolean
54
63
  get() = iconView.isNotEmpty()
55
64
 
@@ -72,16 +81,26 @@ class LuggMarkerView(context: Context) : ReactViewGroup(context) {
72
81
  val (width, height) = measureIconViewBounds()
73
82
  if (width <= 0 || height <= 0) return null
74
83
 
75
- val bitmap = createBitmap(width, height)
84
+ val scaledWidth = (width * scale).toInt()
85
+ val scaledHeight = (height * scale).toInt()
86
+
87
+ val bitmap = createBitmap(scaledWidth, scaledHeight)
76
88
  val canvas = Canvas(bitmap)
89
+ canvas.scale(scale, scale)
77
90
  iconView.draw(canvas)
78
91
  return BitmapDescriptorFactory.fromBitmap(bitmap)
79
92
  }
80
93
 
81
94
  private fun createIconViewWrapper(): View {
82
95
  val (width, height) = measureIconViewBounds()
96
+ val scaledWidth = (width * scale).toInt()
97
+ val scaledHeight = (height * scale).toInt()
83
98
 
84
99
  (iconView.parent as? ViewGroup)?.removeView(iconView)
100
+ iconView.scaleX = scale
101
+ iconView.scaleY = scale
102
+ iconView.pivotX = 0f
103
+ iconView.pivotY = 0f
85
104
 
86
105
  return object : ReactViewGroup(context) {
87
106
  init {
@@ -89,7 +108,7 @@ class LuggMarkerView(context: Context) : ReactViewGroup(context) {
89
108
  }
90
109
 
91
110
  override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
92
- setMeasuredDimension(width, height)
111
+ setMeasuredDimension(scaledWidth, scaledHeight)
93
112
  }
94
113
  }
95
114
  }
@@ -99,21 +118,31 @@ class LuggMarkerView(context: Context) : ReactViewGroup(context) {
99
118
  if (!hasCustomView) return
100
119
 
101
120
  if (rasterize) {
102
- m.iconView = null
103
121
  createIconBitmap()?.let { m.setIcon(it) }
104
122
  } else {
105
123
  m.iconView = createIconViewWrapper()
106
124
  }
107
125
  }
108
126
 
109
- fun updateIcon(onAddMarker: () -> Unit) {
127
+ fun applyScaleToMarker() {
128
+ val m = marker ?: return
110
129
  if (!hasCustomView) return
111
- if (isPendingUpdate) return
112
- isPendingUpdate = true
113
130
 
131
+ scaleUpdateRunnable?.let { removeCallbacks(it) }
132
+ scaleUpdateRunnable = Runnable {
133
+ if (rasterize) {
134
+ createIconBitmap()?.let { m.setIcon(it) }
135
+ } else {
136
+ m.iconView = createIconViewWrapper()
137
+ }
138
+ }
139
+ post(scaleUpdateRunnable)
140
+ }
141
+
142
+ fun updateIcon(onAddMarker: () -> Unit) {
143
+ if (!hasCustomView) return
114
144
  if (rasterize) {
115
145
  post {
116
- isPendingUpdate = false
117
146
  if (marker == null) {
118
147
  onAddMarker()
119
148
  } else {
@@ -123,10 +152,7 @@ class LuggMarkerView(context: Context) : ReactViewGroup(context) {
123
152
  } else {
124
153
  marker?.remove()
125
154
  marker = null
126
- post {
127
- isPendingUpdate = false
128
- onAddMarker()
129
- }
155
+ post { onAddMarker() }
130
156
  }
131
157
  }
132
158
 
@@ -195,6 +221,19 @@ class LuggMarkerView(context: Context) : ReactViewGroup(context) {
195
221
  this.zIndex = zIndex
196
222
  }
197
223
 
224
+ fun setRotate(rotate: Float) {
225
+ this.rotate = rotate
226
+ }
227
+
228
+ fun setScale(scale: Float) {
229
+ scaleChanged = this.scale != scale
230
+ this.scale = scale
231
+ }
232
+
233
+ fun clearScaleChanged() {
234
+ scaleChanged = false
235
+ }
236
+
198
237
  fun setRasterize(rasterize: Boolean) {
199
238
  this.rasterize = rasterize
200
239
  }
@@ -208,6 +247,8 @@ class LuggMarkerView(context: Context) : ReactViewGroup(context) {
208
247
  }
209
248
 
210
249
  fun onDropViewInstance() {
250
+ scaleUpdateRunnable?.let { removeCallbacks(it) }
251
+ scaleUpdateRunnable = null
211
252
  didLayout = false
212
253
  delegate = null
213
254
  iconView.removeAllViews()
@@ -69,6 +69,16 @@ class LuggMarkerViewManager :
69
69
  view.setZIndex(zIndex)
70
70
  }
71
71
 
72
+ @ReactProp(name = "rotate", defaultDouble = 0.0)
73
+ override fun setRotate(view: LuggMarkerView, value: Double) {
74
+ view.setRotate(value.toFloat())
75
+ }
76
+
77
+ @ReactProp(name = "scale", defaultDouble = 1.0)
78
+ override fun setScale(view: LuggMarkerView, value: Double) {
79
+ view.setScale(value.toFloat())
80
+ }
81
+
72
82
  @ReactProp(name = "rasterize", defaultBoolean = true)
73
83
  override fun setRasterize(view: LuggMarkerView, value: Boolean) {
74
84
  view.setRasterize(value)
@@ -143,6 +143,14 @@ class PolylineAnimator {
143
143
  animator = null
144
144
  }
145
145
 
146
+ fun pause() {
147
+ animator?.pause()
148
+ }
149
+
150
+ fun resume() {
151
+ animator?.resume()
152
+ }
153
+
146
154
  private fun updateAnimatedPolyline() {
147
155
  val poly = polyline ?: return
148
156
  if (coordinates.size < 2 || totalLength <= 0f) {
@@ -103,11 +103,13 @@ using namespace luggmaps::events;
103
103
  (AppleMarkerAnnotation *)markerView.marker;
104
104
 
105
105
  if (annotation) {
106
+ annotation.annotationView.transform = CGAffineTransformIdentity;
106
107
  annotation.markerView = nil;
107
108
  annotation.annotationView = nil;
108
109
  [_mapView removeAnnotation:annotation];
109
110
  markerView.marker = nil;
110
111
  }
112
+ [markerView resetIconViewTransform];
111
113
  } else if ([childComponentView isKindOfClass:[LuggPolylineView class]]) {
112
114
  LuggPolylineView *polylineView = (LuggPolylineView *)childComponentView;
113
115
  polylineView.delegate = nil;
@@ -256,6 +258,38 @@ using namespace luggmaps::events;
256
258
 
257
259
  #pragma mark - Annotation Helpers
258
260
 
261
+ - (void)applyMarkerStyle:(LuggMarkerView *)markerView
262
+ annotationView:(MKAnnotationView *)annotationView {
263
+ annotationView.transform = CGAffineTransformIdentity;
264
+
265
+ UIView *iconView = markerView.iconView;
266
+ CGRect frame = iconView.frame;
267
+ if (frame.size.width <= 0 || frame.size.height <= 0)
268
+ return;
269
+
270
+ CGFloat scale = markerView.scale;
271
+ CGPoint anchor = markerView.anchor;
272
+
273
+ if (markerView.rasterize) {
274
+ annotationView.image = [markerView createScaledIconImage];
275
+ } else {
276
+ iconView.layer.anchorPoint = anchor;
277
+ iconView.transform = CGAffineTransformMakeScale(scale, scale);
278
+ iconView.frame =
279
+ CGRectMake(frame.size.width * (0.5 - anchor.x) * (scale - 1),
280
+ frame.size.height * (0.5 - anchor.y) * (scale - 1),
281
+ frame.size.width, frame.size.height);
282
+ }
283
+
284
+ annotationView.bounds =
285
+ CGRectMake(0, 0, frame.size.width * scale, frame.size.height * scale);
286
+ annotationView.centerOffset =
287
+ CGPointMake(frame.size.width * scale * (anchor.x - 0.5),
288
+ -frame.size.height * scale * (anchor.y - 0.5));
289
+ annotationView.transform =
290
+ CGAffineTransformMakeRotation(markerView.rotate * M_PI / 180.0);
291
+ }
292
+
259
293
  - (void)updateAnnotationViewFrame:(AppleMarkerAnnotation *)annotation {
260
294
  MKAnnotationView *annotationView = annotation.annotationView;
261
295
  LuggMarkerView *markerView = annotation.markerView;
@@ -264,22 +298,7 @@ using namespace luggmaps::events;
264
298
  return;
265
299
  }
266
300
 
267
- UIView *iconView = markerView.iconView;
268
- CGRect frame = iconView.frame;
269
- if (frame.size.width > 0 && frame.size.height > 0) {
270
- if (markerView.rasterize) {
271
- annotationView.image = [markerView createIconImage];
272
- annotationView.frame =
273
- CGRectMake(0, 0, frame.size.width, frame.size.height);
274
- } else {
275
- annotationView.frame = frame;
276
- }
277
-
278
- CGPoint anchor = markerView.anchor;
279
- annotationView.centerOffset =
280
- CGPointMake(frame.size.width * (anchor.x - 0.5),
281
- -frame.size.height * (anchor.y - 0.5));
282
- }
301
+ [self applyMarkerStyle:markerView annotationView:annotationView];
283
302
  }
284
303
 
285
304
  #pragma mark - PolylineViewDelegate
@@ -433,6 +452,15 @@ using namespace luggmaps::events;
433
452
 
434
453
  - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated {
435
454
  _isDragging = [self isUserInteracting:mapView];
455
+ if (_isDragging) {
456
+ for (UIView *subview in self.subviews) {
457
+ if ([subview isKindOfClass:[LuggPolylineView class]]) {
458
+ MKPolylineAnimator *renderer =
459
+ (MKPolylineAnimator *)((LuggPolylineView *)subview).renderer;
460
+ [renderer pause];
461
+ }
462
+ }
463
+ }
436
464
  }
437
465
 
438
466
  - (BOOL)isUserInteracting:(MKMapView *)mapView {
@@ -456,6 +484,15 @@ using namespace luggmaps::events;
456
484
  - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
457
485
  BOOL wasDragging = _isDragging;
458
486
  _isDragging = NO;
487
+ if (wasDragging) {
488
+ for (UIView *subview in self.subviews) {
489
+ if ([subview isKindOfClass:[LuggPolylineView class]]) {
490
+ MKPolylineAnimator *renderer =
491
+ (MKPolylineAnimator *)((LuggPolylineView *)subview).renderer;
492
+ [renderer resume];
493
+ }
494
+ }
495
+ }
459
496
  CameraIdleEvent{mapView.centerCoordinate.latitude,
460
497
  mapView.centerCoordinate.longitude, mapView.zoomLevel,
461
498
  static_cast<bool>(wasDragging)}
@@ -483,27 +520,13 @@ using namespace luggmaps::events;
483
520
  annotationView.layer.zPosition = markerView.zIndex;
484
521
  annotationView.zPriority = markerView.zIndex;
485
522
 
486
- UIView *iconView = markerView.iconView;
487
- CGRect frame = iconView.frame;
488
-
489
- if (markerView.rasterize) {
490
- annotationView.image = [markerView createIconImage];
491
- } else {
523
+ if (!markerView.rasterize) {
524
+ UIView *iconView = markerView.iconView;
492
525
  [iconView removeFromSuperview];
493
526
  [annotationView addSubview:iconView];
494
- iconView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
495
- }
496
-
497
- if (frame.size.width > 0 && frame.size.height > 0) {
498
- annotationView.frame =
499
- CGRectMake(0, 0, frame.size.width, frame.size.height);
500
-
501
- CGPoint anchor = markerView.anchor;
502
- annotationView.centerOffset =
503
- CGPointMake(frame.size.width * (anchor.x - 0.5),
504
- -frame.size.height * (anchor.y - 0.5));
505
527
  }
506
528
 
529
+ [self applyMarkerStyle:markerView annotationView:annotationView];
507
530
  markerAnnotation.annotationView = annotationView;
508
531
 
509
532
  return annotationView;
@@ -89,6 +89,7 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
89
89
  marker.map = nil;
90
90
  markerView.marker = nil;
91
91
  }
92
+ [markerView resetIconViewTransform];
92
93
  } else if ([childComponentView isKindOfClass:[LuggPolylineView class]]) {
93
94
  LuggPolylineView *polylineView = (LuggPolylineView *)childComponentView;
94
95
  [_polylineAnimators removeObjectForKey:polylineView];
@@ -189,6 +190,11 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
189
190
 
190
191
  - (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture {
191
192
  _isDragging = gesture;
193
+ if (_isDragging) {
194
+ for (GMSPolylineAnimator *animator in _polylineAnimators.objectEnumerator) {
195
+ [animator pause];
196
+ }
197
+ }
192
198
  }
193
199
 
194
200
  - (void)mapView:(GMSMapView *)mapView
@@ -202,6 +208,11 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
202
208
  idleAtCameraPosition:(GMSCameraPosition *)position {
203
209
  BOOL wasDragging = _isDragging;
204
210
  _isDragging = NO;
211
+ if (wasDragging) {
212
+ for (GMSPolylineAnimator *animator in _polylineAnimators.objectEnumerator) {
213
+ [animator resume];
214
+ }
215
+ }
205
216
  CameraIdleEvent{position.target.latitude, position.target.longitude,
206
217
  position.zoom, static_cast<bool>(wasDragging)}
207
218
  .emit<LuggGoogleMapViewEventEmitter>(_eventEmitter);
@@ -225,6 +236,35 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
225
236
 
226
237
  #pragma mark - Marker Management
227
238
 
239
+ - (void)applyMarkerStyle:(LuggMarkerView *)markerView
240
+ marker:(GMSAdvancedMarker *)marker {
241
+ if (markerView.hasCustomView) {
242
+ if (markerView.rasterize) {
243
+ marker.iconView = nil;
244
+ marker.icon = [markerView createScaledIconImage];
245
+ marker.rotation = markerView.rotate;
246
+ } else {
247
+ UIView *iconView = markerView.iconView;
248
+ if (marker.iconView != iconView) {
249
+ [iconView removeFromSuperview];
250
+ marker.iconView = iconView;
251
+ }
252
+ CGFloat scale = markerView.scale;
253
+ CGFloat radians = markerView.rotate * M_PI / 180.0;
254
+ iconView.transform =
255
+ CGAffineTransformConcat(CGAffineTransformMakeScale(scale, scale),
256
+ CGAffineTransformMakeRotation(radians));
257
+ marker.rotation = 0;
258
+ }
259
+ marker.groundAnchor = markerView.anchor;
260
+ } else {
261
+ marker.iconView = nil;
262
+ marker.icon = nil;
263
+ marker.rotation = markerView.rotate;
264
+ marker.groundAnchor = CGPointMake(0.5, 1);
265
+ }
266
+ }
267
+
228
268
  - (void)syncMarkerView:(LuggMarkerView *)markerView caller:(NSString *)caller {
229
269
  if (!_mapView) {
230
270
  if (![_pendingMarkerViews containsObject:markerView]) {
@@ -243,23 +283,7 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
243
283
  marker.title = markerView.title;
244
284
  marker.snippet = markerView.markerDescription;
245
285
  marker.zIndex = (int)markerView.zIndex;
246
- if (markerView.hasCustomView) {
247
- if (markerView.rasterize) {
248
- marker.iconView = nil;
249
- marker.icon = [markerView createIconImage];
250
- } else {
251
- UIView *iconView = markerView.iconView;
252
- if (marker.iconView != iconView) {
253
- [iconView removeFromSuperview];
254
- marker.iconView = iconView;
255
- }
256
- }
257
- marker.groundAnchor = markerView.anchor;
258
- } else {
259
- marker.iconView = nil;
260
- marker.icon = nil;
261
- marker.groundAnchor = CGPointMake(0.5, 1);
262
- }
286
+ [self applyMarkerStyle:markerView marker:marker];
263
287
  }
264
288
 
265
289
  - (void)processPendingMarkers {
@@ -283,21 +307,11 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
283
307
  marker.position = markerView.coordinate;
284
308
  marker.title = markerView.title;
285
309
  marker.snippet = markerView.markerDescription;
310
+ marker.zIndex = (int)markerView.zIndex;
286
311
 
287
- if (markerView.hasCustomView) {
288
- if (markerView.rasterize) {
289
- marker.icon = [markerView createIconImage];
290
- } else {
291
- UIView *iconView = markerView.iconView;
292
- [iconView removeFromSuperview];
293
- marker.iconView = iconView;
294
- }
295
- marker.groundAnchor = markerView.anchor;
296
- }
312
+ [self applyMarkerStyle:markerView marker:marker];
297
313
 
298
- marker.zIndex = (int)markerView.zIndex;
299
314
  marker.map = _mapView;
300
-
301
315
  markerView.marker = marker;
302
316
  }
303
317
 
@@ -20,6 +20,8 @@ NS_ASSUME_NONNULL_BEGIN
20
20
  @property(nonatomic, readonly, nullable) NSString *markerDescription;
21
21
  @property(nonatomic, readonly) CGPoint anchor;
22
22
  @property(nonatomic, readonly) NSInteger zIndex;
23
+ @property(nonatomic, readonly) CLLocationDegrees rotate;
24
+ @property(nonatomic, readonly) CGFloat scale;
23
25
  @property(nonatomic, readonly) BOOL rasterize;
24
26
  @property(nonatomic, readonly) BOOL hasCustomView;
25
27
  @property(nonatomic, readonly) BOOL didLayout;
@@ -28,6 +30,8 @@ NS_ASSUME_NONNULL_BEGIN
28
30
  @property(nonatomic, strong, nullable) NSObject *marker;
29
31
 
30
32
  - (nullable UIImage *)createIconImage;
33
+ - (nullable UIImage *)createScaledIconImage;
34
+ - (void)resetIconViewTransform;
31
35
 
32
36
  @end
33
37
 
@@ -19,6 +19,8 @@ using namespace facebook::react;
19
19
  NSString *_markerDescription;
20
20
  CGPoint _anchor;
21
21
  NSInteger _zIndex;
22
+ CLLocationDegrees _rotate;
23
+ CGFloat _scale;
22
24
  BOOL _rasterize;
23
25
  BOOL _didLayout;
24
26
  UIView *_iconView;
@@ -38,6 +40,8 @@ using namespace facebook::react;
38
40
  _coordinate = CLLocationCoordinate2DMake(0, 0);
39
41
  _anchor = CGPointMake(0.5, 1.0);
40
42
  _zIndex = 0;
43
+ _rotate = 0;
44
+ _scale = 1;
41
45
  _rasterize = YES;
42
46
  _didLayout = NO;
43
47
 
@@ -65,6 +69,8 @@ using namespace facebook::react;
65
69
  [NSString stringWithUTF8String:newViewProps.description.c_str()];
66
70
  _anchor = CGPointMake(newViewProps.anchor.x, newViewProps.anchor.y);
67
71
  _zIndex = newViewProps.zIndex.value_or(0);
72
+ _rotate = newViewProps.rotate;
73
+ _scale = newViewProps.scale;
68
74
  _rasterize = newViewProps.rasterize;
69
75
  }
70
76
 
@@ -141,6 +147,14 @@ using namespace facebook::react;
141
147
  return _zIndex;
142
148
  }
143
149
 
150
+ - (CLLocationDegrees)rotate {
151
+ return _rotate;
152
+ }
153
+
154
+ - (CGFloat)scale {
155
+ return _scale;
156
+ }
157
+
144
158
  - (BOOL)rasterize {
145
159
  return _rasterize;
146
160
  }
@@ -174,11 +188,39 @@ using namespace facebook::react;
174
188
  }];
175
189
  }
176
190
 
191
+ - (UIImage *)createScaledIconImage {
192
+ CGSize size = _iconView.bounds.size;
193
+ if (size.width <= 0 || size.height <= 0) {
194
+ return nil;
195
+ }
196
+
197
+ CGSize scaledSize = CGSizeMake(size.width * _scale, size.height * _scale);
198
+
199
+ UIGraphicsImageRendererFormat *format =
200
+ [UIGraphicsImageRendererFormat defaultFormat];
201
+ format.scale = [UIScreen mainScreen].scale;
202
+ UIGraphicsImageRenderer *renderer =
203
+ [[UIGraphicsImageRenderer alloc] initWithSize:scaledSize format:format];
204
+
205
+ return [renderer imageWithActions:^(UIGraphicsImageRendererContext *context) {
206
+ CGContextScaleCTM(context.CGContext, self->_scale, self->_scale);
207
+ [self->_iconView.layer renderInContext:context.CGContext];
208
+ }];
209
+ }
210
+
211
+ - (void)resetIconViewTransform {
212
+ _iconView.transform = CGAffineTransformIdentity;
213
+ _iconView.layer.anchorPoint = CGPointMake(0.5, 0.5);
214
+ _iconView.frame = CGRectMake(0, 0, _iconView.bounds.size.width,
215
+ _iconView.bounds.size.height);
216
+ }
217
+
177
218
  - (void)prepareForRecycle {
178
219
  [super prepareForRecycle];
179
220
  _didLayout = NO;
180
221
  self.marker = nil;
181
222
  self.delegate = nil;
223
+ [self resetIconViewTransform];
182
224
  for (UIView *subview in _iconView.subviews) {
183
225
  [subview removeFromSuperview];
184
226
  }
@@ -7,5 +7,7 @@
7
7
  @property(nonatomic, assign) BOOL animated;
8
8
 
9
9
  - (void)update;
10
+ - (void)pause;
11
+ - (void)resume;
10
12
 
11
13
  @end
@@ -92,6 +92,14 @@
92
92
  _displayLinkProxy = nil;
93
93
  }
94
94
 
95
+ - (void)pause {
96
+ _displayLink.paused = YES;
97
+ }
98
+
99
+ - (void)resume {
100
+ _displayLink.paused = NO;
101
+ }
102
+
95
103
  - (void)animationTick:(CADisplayLink *)displayLink {
96
104
  CGFloat speed = displayLink.duration / 1.0;
97
105
  _animationProgress += speed;
@@ -8,5 +8,7 @@
8
8
  @property(nonatomic, assign) BOOL animated;
9
9
 
10
10
  - (void)updatePolyline:(MKPolyline *)polyline;
11
+ - (void)pause;
12
+ - (void)resume;
11
13
 
12
14
  @end
@@ -101,6 +101,14 @@
101
101
  _displayLinkProxy = nil;
102
102
  }
103
103
 
104
+ - (void)pause {
105
+ _displayLink.paused = YES;
106
+ }
107
+
108
+ - (void)resume {
109
+ _displayLink.paused = NO;
110
+ }
111
+
104
112
  - (NSUInteger)indexForDistance:(CGFloat)distance {
105
113
  NSUInteger left = 0;
106
114
  NSUInteger right = _cumulativeDistances.count - 1;
@@ -3,8 +3,11 @@
3
3
  import { createContext, useContext } from 'react';
4
4
  import { APIProvider } from '@vis.gl/react-google-maps';
5
5
  import { jsx as _jsx } from "react/jsx-runtime";
6
- export const MapIdContext = /*#__PURE__*/createContext(null);
7
- export const useMapId = () => useContext(MapIdContext);
6
+ export const MapContext = /*#__PURE__*/createContext({
7
+ map: null,
8
+ isDragging: false
9
+ });
10
+ export const useMapContext = () => useContext(MapContext);
8
11
  export function MapProvider({
9
12
  apiKey = '',
10
13
  children
@@ -1 +1 @@
1
- {"version":3,"names":["createContext","useContext","APIProvider","jsx","_jsx","MapIdContext","useMapId","MapProvider","apiKey","children"],"sourceRoot":"../../src","sources":["MapProvider.web.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,UAAU,QAAQ,OAAO;AACjD,SAASC,WAAW,QAAQ,2BAA2B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAGxD,OAAO,MAAMC,YAAY,gBAAGL,aAAa,CAAgB,IAAI,CAAC;AAE9D,OAAO,MAAMM,QAAQ,GAAGA,CAAA,KAAML,UAAU,CAACI,YAAY,CAAC;AAEtD,OAAO,SAASE,WAAWA,CAAC;EAAEC,MAAM,GAAG,EAAE;EAAEC;AAA2B,CAAC,EAAE;EACvE,oBAAOL,IAAA,CAACF,WAAW;IAACM,MAAM,EAAEA,MAAO;IAAAC,QAAA,EAAEA;EAAQ,CAAc,CAAC;AAC9D","ignoreList":[]}
1
+ {"version":3,"names":["createContext","useContext","APIProvider","jsx","_jsx","MapContext","map","isDragging","useMapContext","MapProvider","apiKey","children"],"sourceRoot":"../../src","sources":["MapProvider.web.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,UAAU,QAAQ,OAAO;AACjD,SAASC,WAAW,QAAQ,2BAA2B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAGxD,OAAO,MAAMC,UAAU,gBAAGL,aAAa,CAGpC;EAAEM,GAAG,EAAE,IAAI;EAAEC,UAAU,EAAE;AAAM,CAAC,CAAC;AAEpC,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAMP,UAAU,CAACI,UAAU,CAAC;AAEzD,OAAO,SAASI,WAAWA,CAAC;EAAEC,MAAM,GAAG,EAAE;EAAEC;AAA2B,CAAC,EAAE;EACvE,oBAAOP,IAAA,CAACF,WAAW;IAACQ,MAAM,EAAEA,MAAO;IAAAC,QAAA,EAAEA;EAAQ,CAAc,CAAC;AAC9D","ignoreList":[]}