@lugg/maps 0.2.0-alpha.0

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 (114) hide show
  1. package/LICENSE +20 -0
  2. package/LuggMaps.podspec +23 -0
  3. package/README.md +119 -0
  4. package/android/build.gradle +78 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/com/luggmaps/LuggMapsGoogleMapView.kt +438 -0
  8. package/android/src/main/java/com/luggmaps/LuggMapsGoogleMapViewManager.kt +144 -0
  9. package/android/src/main/java/com/luggmaps/LuggMapsMarkerView.kt +134 -0
  10. package/android/src/main/java/com/luggmaps/LuggMapsMarkerViewManager.kt +69 -0
  11. package/android/src/main/java/com/luggmaps/LuggMapsPackage.kt +13 -0
  12. package/android/src/main/java/com/luggmaps/LuggMapsPolylineView.kt +79 -0
  13. package/android/src/main/java/com/luggmaps/LuggMapsPolylineViewManager.kt +71 -0
  14. package/android/src/main/java/com/luggmaps/LuggMapsWrapperView.kt +39 -0
  15. package/android/src/main/java/com/luggmaps/LuggMapsWrapperViewManager.kt +25 -0
  16. package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +180 -0
  17. package/android/src/main/java/com/luggmaps/events/CameraIdleEvent.kt +21 -0
  18. package/android/src/main/java/com/luggmaps/events/CameraMoveEvent.kt +28 -0
  19. package/app.plugin.js +1 -0
  20. package/ios/LuggMapsAppleMapView.h +16 -0
  21. package/ios/LuggMapsAppleMapView.mm +544 -0
  22. package/ios/LuggMapsGoogleMapView.h +13 -0
  23. package/ios/LuggMapsGoogleMapView.mm +439 -0
  24. package/ios/LuggMapsMarkerView.h +29 -0
  25. package/ios/LuggMapsMarkerView.mm +154 -0
  26. package/ios/LuggMapsPolylineView.h +27 -0
  27. package/ios/LuggMapsPolylineView.mm +116 -0
  28. package/ios/LuggMapsWrapperView.h +9 -0
  29. package/ios/LuggMapsWrapperView.mm +36 -0
  30. package/ios/core/GMSPolylineAnimator.h +11 -0
  31. package/ios/core/GMSPolylineAnimator.m +151 -0
  32. package/ios/core/MKPolylineAnimator.h +12 -0
  33. package/ios/core/MKPolylineAnimator.m +252 -0
  34. package/ios/core/PolylineAnimatorBase.h +22 -0
  35. package/ios/core/PolylineAnimatorBase.m +35 -0
  36. package/ios/events/CameraIdleEvent.h +24 -0
  37. package/ios/events/CameraMoveEvent.h +26 -0
  38. package/ios/extensions/MKMapView+Zoom.h +19 -0
  39. package/ios/extensions/MKMapView+Zoom.m +45 -0
  40. package/lib/module/MapView.js +87 -0
  41. package/lib/module/MapView.js.map +1 -0
  42. package/lib/module/MapView.types.js +4 -0
  43. package/lib/module/MapView.types.js.map +1 -0
  44. package/lib/module/Marker.js +34 -0
  45. package/lib/module/Marker.js.map +1 -0
  46. package/lib/module/Marker.types.js +4 -0
  47. package/lib/module/Marker.types.js.map +1 -0
  48. package/lib/module/Polyline.js +30 -0
  49. package/lib/module/Polyline.js.map +1 -0
  50. package/lib/module/Polyline.types.js +4 -0
  51. package/lib/module/Polyline.types.js.map +1 -0
  52. package/lib/module/fabric/LuggMapsAppleMapViewNativeComponent.ts +73 -0
  53. package/lib/module/fabric/LuggMapsGoogleMapViewNativeComponent.ts +74 -0
  54. package/lib/module/fabric/LuggMapsMarkerViewNativeComponent.ts +25 -0
  55. package/lib/module/fabric/LuggMapsPolylineViewNativeComponent.ts +19 -0
  56. package/lib/module/fabric/LuggMapsWrapperViewNativeComponent.ts +8 -0
  57. package/lib/module/index.js +6 -0
  58. package/lib/module/index.js.map +1 -0
  59. package/lib/module/package.json +1 -0
  60. package/lib/module/types.js +2 -0
  61. package/lib/module/types.js.map +1 -0
  62. package/lib/typescript/package.json +1 -0
  63. package/lib/typescript/plugin/src/index.d.ts +16 -0
  64. package/lib/typescript/plugin/src/index.d.ts.map +1 -0
  65. package/lib/typescript/plugin/src/withMapsAndroid.d.ts +6 -0
  66. package/lib/typescript/plugin/src/withMapsAndroid.d.ts.map +1 -0
  67. package/lib/typescript/plugin/src/withMapsIOS.d.ts +6 -0
  68. package/lib/typescript/plugin/src/withMapsIOS.d.ts.map +1 -0
  69. package/lib/typescript/src/MapView.d.ts +12 -0
  70. package/lib/typescript/src/MapView.d.ts.map +1 -0
  71. package/lib/typescript/src/MapView.types.d.ts +102 -0
  72. package/lib/typescript/src/MapView.types.d.ts.map +1 -0
  73. package/lib/typescript/src/Marker.d.ts +6 -0
  74. package/lib/typescript/src/Marker.d.ts.map +1 -0
  75. package/lib/typescript/src/Marker.types.d.ts +32 -0
  76. package/lib/typescript/src/Marker.types.d.ts.map +1 -0
  77. package/lib/typescript/src/Polyline.d.ts +6 -0
  78. package/lib/typescript/src/Polyline.d.ts.map +1 -0
  79. package/lib/typescript/src/Polyline.types.d.ts +24 -0
  80. package/lib/typescript/src/Polyline.types.d.ts.map +1 -0
  81. package/lib/typescript/src/fabric/LuggMapsAppleMapViewNativeComponent.d.ts +47 -0
  82. package/lib/typescript/src/fabric/LuggMapsAppleMapViewNativeComponent.d.ts.map +1 -0
  83. package/lib/typescript/src/fabric/LuggMapsGoogleMapViewNativeComponent.d.ts +48 -0
  84. package/lib/typescript/src/fabric/LuggMapsGoogleMapViewNativeComponent.d.ts.map +1 -0
  85. package/lib/typescript/src/fabric/LuggMapsMarkerViewNativeComponent.d.ts +20 -0
  86. package/lib/typescript/src/fabric/LuggMapsMarkerViewNativeComponent.d.ts.map +1 -0
  87. package/lib/typescript/src/fabric/LuggMapsPolylineViewNativeComponent.d.ts +15 -0
  88. package/lib/typescript/src/fabric/LuggMapsPolylineViewNativeComponent.d.ts.map +1 -0
  89. package/lib/typescript/src/fabric/LuggMapsWrapperViewNativeComponent.d.ts +6 -0
  90. package/lib/typescript/src/fabric/LuggMapsWrapperViewNativeComponent.d.ts.map +1 -0
  91. package/lib/typescript/src/index.d.ts +8 -0
  92. package/lib/typescript/src/index.d.ts.map +1 -0
  93. package/lib/typescript/src/types.d.ts +28 -0
  94. package/lib/typescript/src/types.d.ts.map +1 -0
  95. package/package.json +200 -0
  96. package/plugin/build/index.d.ts +15 -0
  97. package/plugin/build/index.js +13 -0
  98. package/plugin/build/withMapsAndroid.d.ts +5 -0
  99. package/plugin/build/withMapsAndroid.js +15 -0
  100. package/plugin/build/withMapsIOS.d.ts +5 -0
  101. package/plugin/build/withMapsIOS.js +27 -0
  102. package/src/MapView.tsx +111 -0
  103. package/src/MapView.types.ts +110 -0
  104. package/src/Marker.tsx +31 -0
  105. package/src/Marker.types.ts +32 -0
  106. package/src/Polyline.tsx +32 -0
  107. package/src/Polyline.types.ts +24 -0
  108. package/src/fabric/LuggMapsAppleMapViewNativeComponent.ts +73 -0
  109. package/src/fabric/LuggMapsGoogleMapViewNativeComponent.ts +74 -0
  110. package/src/fabric/LuggMapsMarkerViewNativeComponent.ts +25 -0
  111. package/src/fabric/LuggMapsPolylineViewNativeComponent.ts +19 -0
  112. package/src/fabric/LuggMapsWrapperViewNativeComponent.ts +8 -0
  113. package/src/index.ts +13 -0
  114. package/src/types.ts +30 -0
@@ -0,0 +1,180 @@
1
+ package com.luggmaps.core
2
+
3
+ import android.animation.ValueAnimator
4
+ import android.graphics.Color
5
+ import android.view.animation.LinearInterpolator
6
+ import com.google.android.gms.maps.model.LatLng
7
+ import com.google.android.gms.maps.model.Polyline
8
+ import com.google.android.gms.maps.model.StrokeStyle
9
+ import com.google.android.gms.maps.model.StyleSpan
10
+ import kotlin.math.floor
11
+ import kotlin.math.max
12
+ import kotlin.math.min
13
+
14
+ class PolylineAnimator {
15
+ var polyline: Polyline? = null
16
+ var coordinates: List<LatLng> = emptyList()
17
+ var strokeColors: List<Int> = listOf(Color.BLACK)
18
+ var strokeWidth: Float = 1f
19
+
20
+ var animated: Boolean = false
21
+ set(value) {
22
+ if (field == value) return
23
+ field = value
24
+ if (value) {
25
+ startAnimation()
26
+ } else {
27
+ stopAnimation()
28
+ update()
29
+ }
30
+ }
31
+
32
+ private var animator: ValueAnimator? = null
33
+ private var animationProgress: Float = 0f
34
+
35
+ fun update() {
36
+ if (animated) return
37
+
38
+ val poly = polyline ?: return
39
+ if (coordinates.size < 2) return
40
+
41
+ poly.points = coordinates
42
+
43
+ if (strokeColors.size > 1) {
44
+ poly.setSpans(createGradientSpans())
45
+ } else {
46
+ poly.color = strokeColors.firstOrNull() ?: Color.BLACK
47
+ }
48
+ }
49
+
50
+ private fun startAnimation() {
51
+ if (animator != null) return
52
+
53
+ animator = ValueAnimator.ofFloat(0f, 2.15f).apply {
54
+ duration = 3650 // ~1.75s per phase * 2 + pause
55
+ repeatCount = ValueAnimator.INFINITE
56
+ interpolator = LinearInterpolator()
57
+ addUpdateListener { animation ->
58
+ animationProgress = animation.animatedValue as Float
59
+ updateAnimatedPolyline()
60
+ }
61
+ start()
62
+ }
63
+ }
64
+
65
+ private fun stopAnimation() {
66
+ animator?.cancel()
67
+ animator = null
68
+ }
69
+
70
+ private fun updateAnimatedPolyline() {
71
+ val poly = polyline ?: return
72
+ if (coordinates.size < 2) {
73
+ poly.points = coordinates
74
+ return
75
+ }
76
+
77
+ val segmentCount = coordinates.size - 1
78
+ val progress = min(animationProgress, 2f)
79
+
80
+ val headPos: Float
81
+ val tailPos: Float
82
+
83
+ if (progress <= 1f) {
84
+ tailPos = 0f
85
+ headPos = progress * segmentCount
86
+ } else {
87
+ val shrinkProgress = progress - 1f
88
+ tailPos = shrinkProgress * segmentCount
89
+ headPos = segmentCount.toFloat()
90
+ }
91
+
92
+ if (headPos <= tailPos || coordinates.isEmpty()) {
93
+ poly.setSpans(emptyList())
94
+ poly.points = listOf(coordinates.firstOrNull() ?: LatLng(0.0, 0.0))
95
+ return
96
+ }
97
+
98
+ val startIndex = floor(tailPos).toInt()
99
+ val endIndex = kotlin.math.ceil(headPos.toDouble()).toInt()
100
+ val visibleLength = headPos - tailPos
101
+
102
+ val points = mutableListOf<LatLng>()
103
+ val spans = mutableListOf<StyleSpan>()
104
+
105
+ for (i in startIndex..minOf(endIndex, coordinates.size - 1)) {
106
+ var coord = coordinates[i]
107
+
108
+ // Interpolate tail
109
+ if (i == startIndex && tailPos > startIndex.toFloat() && i + 1 < coordinates.size) {
110
+ val t = tailPos - startIndex
111
+ val next = coordinates[i + 1]
112
+ coord = LatLng(
113
+ coord.latitude + (next.latitude - coord.latitude) * t,
114
+ coord.longitude + (next.longitude - coord.longitude) * t
115
+ )
116
+ }
117
+
118
+ // Interpolate head
119
+ if (i == endIndex && headPos < endIndex.toFloat() && i > 0) {
120
+ val t = headPos - (endIndex - 1)
121
+ val prev = coordinates[i - 1]
122
+ coord = LatLng(
123
+ prev.latitude + (coordinates[i].latitude - prev.latitude) * t,
124
+ prev.longitude + (coordinates[i].longitude - prev.longitude) * t
125
+ )
126
+ }
127
+
128
+ points.add(coord)
129
+
130
+ if (i < endIndex && i < segmentCount) {
131
+ val segStartPos = max(i.toFloat(), tailPos)
132
+ val segEndPos = min((i + 1).toFloat(), headPos)
133
+ val gradientMid = ((segStartPos + segEndPos) / 2f - tailPos) / visibleLength
134
+ val color = colorAtGradientPosition(gradientMid)
135
+ spans.add(StyleSpan(StrokeStyle.colorBuilder(color).build()))
136
+ }
137
+ }
138
+
139
+ poly.points = points
140
+ if (spans.isNotEmpty()) {
141
+ poly.setSpans(spans)
142
+ }
143
+ }
144
+
145
+ private fun createGradientSpans(): List<StyleSpan> {
146
+ val segmentCount = coordinates.size - 1
147
+ return (0 until segmentCount).map { i ->
148
+ val position = i.toFloat() / segmentCount
149
+ val color = colorAtGradientPosition(position)
150
+ StyleSpan(StrokeStyle.colorBuilder(color).build())
151
+ }
152
+ }
153
+
154
+ private fun colorAtGradientPosition(position: Float): Int {
155
+ if (strokeColors.isEmpty()) return Color.BLACK
156
+ if (strokeColors.size == 1) return strokeColors[0]
157
+
158
+ val pos = position.coerceIn(0f, 1f)
159
+ val scaledPos = pos * (strokeColors.size - 1)
160
+ val index = floor(scaledPos).toInt()
161
+ val t = scaledPos - index
162
+
163
+ if (index >= strokeColors.size - 1) return strokeColors.last()
164
+
165
+ val c1 = strokeColors[index]
166
+ val c2 = strokeColors[index + 1]
167
+
168
+ val r = ((Color.red(c1) + (Color.red(c2) - Color.red(c1)) * t).toInt())
169
+ val g = ((Color.green(c1) + (Color.green(c2) - Color.green(c1)) * t).toInt())
170
+ val b = ((Color.blue(c1) + (Color.blue(c2) - Color.blue(c1)) * t).toInt())
171
+ val a = ((Color.alpha(c1) + (Color.alpha(c2) - Color.alpha(c1)) * t).toInt())
172
+
173
+ return Color.argb(a, r, g, b)
174
+ }
175
+
176
+ fun destroy() {
177
+ stopAnimation()
178
+ polyline = null
179
+ }
180
+ }
@@ -0,0 +1,21 @@
1
+ package com.luggmaps.events
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.uimanager.events.Event
5
+
6
+ class CameraIdleEvent(surfaceId: Int, viewId: Int, private val latitude: Double, private val longitude: Double, private val zoom: Float) :
7
+ Event<CameraIdleEvent>(surfaceId, viewId) {
8
+ override fun getEventName() = "topCameraIdle"
9
+
10
+ override fun getEventData() =
11
+ Arguments.createMap().apply {
12
+ putMap(
13
+ "coordinate",
14
+ Arguments.createMap().apply {
15
+ putDouble("latitude", latitude)
16
+ putDouble("longitude", longitude)
17
+ }
18
+ )
19
+ putDouble("zoom", zoom.toDouble())
20
+ }
21
+ }
@@ -0,0 +1,28 @@
1
+ package com.luggmaps.events
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.uimanager.events.Event
5
+
6
+ class CameraMoveEvent(
7
+ surfaceId: Int,
8
+ viewId: Int,
9
+ private val latitude: Double,
10
+ private val longitude: Double,
11
+ private val zoom: Float,
12
+ private val dragging: Boolean
13
+ ) : Event<CameraMoveEvent>(surfaceId, viewId) {
14
+ override fun getEventName() = "topCameraMove"
15
+
16
+ override fun getEventData() =
17
+ Arguments.createMap().apply {
18
+ putMap(
19
+ "coordinate",
20
+ Arguments.createMap().apply {
21
+ putDouble("latitude", latitude)
22
+ putDouble("longitude", longitude)
23
+ }
24
+ )
25
+ putDouble("zoom", zoom.toDouble())
26
+ putBoolean("dragging", dragging)
27
+ }
28
+ }
package/app.plugin.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./plugin/build');
@@ -0,0 +1,16 @@
1
+ #import <MapKit/MapKit.h>
2
+ #import <React/RCTViewComponentView.h>
3
+ #import <UIKit/UIKit.h>
4
+
5
+ NS_ASSUME_NONNULL_BEGIN
6
+
7
+ @interface LuggMapsAppleMapViewContent : MKMapView
8
+ @end
9
+
10
+ @interface LuggMapsAppleMapView : RCTViewComponentView
11
+
12
+ - (MKMapView *)mapView;
13
+
14
+ @end
15
+
16
+ NS_ASSUME_NONNULL_END