@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.
- package/LICENSE +20 -0
- package/LuggMaps.podspec +23 -0
- package/README.md +119 -0
- package/android/build.gradle +78 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/luggmaps/LuggMapsGoogleMapView.kt +438 -0
- package/android/src/main/java/com/luggmaps/LuggMapsGoogleMapViewManager.kt +144 -0
- package/android/src/main/java/com/luggmaps/LuggMapsMarkerView.kt +134 -0
- package/android/src/main/java/com/luggmaps/LuggMapsMarkerViewManager.kt +69 -0
- package/android/src/main/java/com/luggmaps/LuggMapsPackage.kt +13 -0
- package/android/src/main/java/com/luggmaps/LuggMapsPolylineView.kt +79 -0
- package/android/src/main/java/com/luggmaps/LuggMapsPolylineViewManager.kt +71 -0
- package/android/src/main/java/com/luggmaps/LuggMapsWrapperView.kt +39 -0
- package/android/src/main/java/com/luggmaps/LuggMapsWrapperViewManager.kt +25 -0
- package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +180 -0
- package/android/src/main/java/com/luggmaps/events/CameraIdleEvent.kt +21 -0
- package/android/src/main/java/com/luggmaps/events/CameraMoveEvent.kt +28 -0
- package/app.plugin.js +1 -0
- package/ios/LuggMapsAppleMapView.h +16 -0
- package/ios/LuggMapsAppleMapView.mm +544 -0
- package/ios/LuggMapsGoogleMapView.h +13 -0
- package/ios/LuggMapsGoogleMapView.mm +439 -0
- package/ios/LuggMapsMarkerView.h +29 -0
- package/ios/LuggMapsMarkerView.mm +154 -0
- package/ios/LuggMapsPolylineView.h +27 -0
- package/ios/LuggMapsPolylineView.mm +116 -0
- package/ios/LuggMapsWrapperView.h +9 -0
- package/ios/LuggMapsWrapperView.mm +36 -0
- package/ios/core/GMSPolylineAnimator.h +11 -0
- package/ios/core/GMSPolylineAnimator.m +151 -0
- package/ios/core/MKPolylineAnimator.h +12 -0
- package/ios/core/MKPolylineAnimator.m +252 -0
- package/ios/core/PolylineAnimatorBase.h +22 -0
- package/ios/core/PolylineAnimatorBase.m +35 -0
- package/ios/events/CameraIdleEvent.h +24 -0
- package/ios/events/CameraMoveEvent.h +26 -0
- package/ios/extensions/MKMapView+Zoom.h +19 -0
- package/ios/extensions/MKMapView+Zoom.m +45 -0
- package/lib/module/MapView.js +87 -0
- package/lib/module/MapView.js.map +1 -0
- package/lib/module/MapView.types.js +4 -0
- package/lib/module/MapView.types.js.map +1 -0
- package/lib/module/Marker.js +34 -0
- package/lib/module/Marker.js.map +1 -0
- package/lib/module/Marker.types.js +4 -0
- package/lib/module/Marker.types.js.map +1 -0
- package/lib/module/Polyline.js +30 -0
- package/lib/module/Polyline.js.map +1 -0
- package/lib/module/Polyline.types.js +4 -0
- package/lib/module/Polyline.types.js.map +1 -0
- package/lib/module/fabric/LuggMapsAppleMapViewNativeComponent.ts +73 -0
- package/lib/module/fabric/LuggMapsGoogleMapViewNativeComponent.ts +74 -0
- package/lib/module/fabric/LuggMapsMarkerViewNativeComponent.ts +25 -0
- package/lib/module/fabric/LuggMapsPolylineViewNativeComponent.ts +19 -0
- package/lib/module/fabric/LuggMapsWrapperViewNativeComponent.ts +8 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/plugin/src/index.d.ts +16 -0
- package/lib/typescript/plugin/src/index.d.ts.map +1 -0
- package/lib/typescript/plugin/src/withMapsAndroid.d.ts +6 -0
- package/lib/typescript/plugin/src/withMapsAndroid.d.ts.map +1 -0
- package/lib/typescript/plugin/src/withMapsIOS.d.ts +6 -0
- package/lib/typescript/plugin/src/withMapsIOS.d.ts.map +1 -0
- package/lib/typescript/src/MapView.d.ts +12 -0
- package/lib/typescript/src/MapView.d.ts.map +1 -0
- package/lib/typescript/src/MapView.types.d.ts +102 -0
- package/lib/typescript/src/MapView.types.d.ts.map +1 -0
- package/lib/typescript/src/Marker.d.ts +6 -0
- package/lib/typescript/src/Marker.d.ts.map +1 -0
- package/lib/typescript/src/Marker.types.d.ts +32 -0
- package/lib/typescript/src/Marker.types.d.ts.map +1 -0
- package/lib/typescript/src/Polyline.d.ts +6 -0
- package/lib/typescript/src/Polyline.d.ts.map +1 -0
- package/lib/typescript/src/Polyline.types.d.ts +24 -0
- package/lib/typescript/src/Polyline.types.d.ts.map +1 -0
- package/lib/typescript/src/fabric/LuggMapsAppleMapViewNativeComponent.d.ts +47 -0
- package/lib/typescript/src/fabric/LuggMapsAppleMapViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/fabric/LuggMapsGoogleMapViewNativeComponent.d.ts +48 -0
- package/lib/typescript/src/fabric/LuggMapsGoogleMapViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/fabric/LuggMapsMarkerViewNativeComponent.d.ts +20 -0
- package/lib/typescript/src/fabric/LuggMapsMarkerViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/fabric/LuggMapsPolylineViewNativeComponent.d.ts +15 -0
- package/lib/typescript/src/fabric/LuggMapsPolylineViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/fabric/LuggMapsWrapperViewNativeComponent.d.ts +6 -0
- package/lib/typescript/src/fabric/LuggMapsWrapperViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +8 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +28 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/package.json +200 -0
- package/plugin/build/index.d.ts +15 -0
- package/plugin/build/index.js +13 -0
- package/plugin/build/withMapsAndroid.d.ts +5 -0
- package/plugin/build/withMapsAndroid.js +15 -0
- package/plugin/build/withMapsIOS.d.ts +5 -0
- package/plugin/build/withMapsIOS.js +27 -0
- package/src/MapView.tsx +111 -0
- package/src/MapView.types.ts +110 -0
- package/src/Marker.tsx +31 -0
- package/src/Marker.types.ts +32 -0
- package/src/Polyline.tsx +32 -0
- package/src/Polyline.types.ts +24 -0
- package/src/fabric/LuggMapsAppleMapViewNativeComponent.ts +73 -0
- package/src/fabric/LuggMapsGoogleMapViewNativeComponent.ts +74 -0
- package/src/fabric/LuggMapsMarkerViewNativeComponent.ts +25 -0
- package/src/fabric/LuggMapsPolylineViewNativeComponent.ts +19 -0
- package/src/fabric/LuggMapsWrapperViewNativeComponent.ts +8 -0
- package/src/index.ts +13 -0
- 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
|