@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,144 @@
|
|
|
1
|
+
package com.luggmaps
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableArray
|
|
4
|
+
import com.facebook.react.bridge.ReadableMap
|
|
5
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
6
|
+
import com.facebook.react.uimanager.PixelUtil.dpToPx
|
|
7
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
8
|
+
import com.facebook.react.uimanager.UIManagerHelper
|
|
9
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
10
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
11
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
12
|
+
import com.facebook.react.viewmanagers.LuggMapsGoogleMapViewManagerDelegate
|
|
13
|
+
import com.facebook.react.viewmanagers.LuggMapsGoogleMapViewManagerInterface
|
|
14
|
+
import com.google.android.gms.maps.model.LatLng
|
|
15
|
+
import com.luggmaps.events.CameraIdleEvent
|
|
16
|
+
import com.luggmaps.events.CameraMoveEvent
|
|
17
|
+
|
|
18
|
+
@ReactModule(name = LuggMapsGoogleMapViewManager.NAME)
|
|
19
|
+
class LuggMapsGoogleMapViewManager :
|
|
20
|
+
ViewGroupManager<LuggMapsGoogleMapView>(),
|
|
21
|
+
LuggMapsGoogleMapViewManagerInterface<LuggMapsGoogleMapView>,
|
|
22
|
+
LuggMapsGoogleMapViewEventDelegate {
|
|
23
|
+
private val delegate: ViewManagerDelegate<LuggMapsGoogleMapView> = LuggMapsGoogleMapViewManagerDelegate(this)
|
|
24
|
+
|
|
25
|
+
override fun getDelegate(): ViewManagerDelegate<LuggMapsGoogleMapView> = delegate
|
|
26
|
+
|
|
27
|
+
override fun getName(): String = NAME
|
|
28
|
+
|
|
29
|
+
override fun createViewInstance(context: ThemedReactContext): LuggMapsGoogleMapView {
|
|
30
|
+
val view = LuggMapsGoogleMapView(context)
|
|
31
|
+
view.eventDelegate = this
|
|
32
|
+
return view
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> =
|
|
36
|
+
mapOf(
|
|
37
|
+
"topCameraMove" to mapOf("registrationName" to "onCameraMove"),
|
|
38
|
+
"topCameraIdle" to mapOf("registrationName" to "onCameraIdle")
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
override fun onCameraMove(
|
|
42
|
+
view: LuggMapsGoogleMapView,
|
|
43
|
+
latitude: Double,
|
|
44
|
+
longitude: Double,
|
|
45
|
+
zoom: Float,
|
|
46
|
+
dragging: Boolean
|
|
47
|
+
) {
|
|
48
|
+
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(
|
|
49
|
+
view.context as ThemedReactContext,
|
|
50
|
+
view.id
|
|
51
|
+
)
|
|
52
|
+
eventDispatcher?.dispatchEvent(CameraMoveEvent(UIManagerHelper.getSurfaceId(view), view.id, latitude, longitude, zoom, dragging))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override fun onCameraIdle(view: LuggMapsGoogleMapView, latitude: Double, longitude: Double, zoom: Float) {
|
|
56
|
+
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(
|
|
57
|
+
view.context as ThemedReactContext,
|
|
58
|
+
view.id
|
|
59
|
+
)
|
|
60
|
+
eventDispatcher?.dispatchEvent(CameraIdleEvent(UIManagerHelper.getSurfaceId(view), view.id, latitude, longitude, zoom))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@ReactProp(name = "mapId")
|
|
64
|
+
override fun setMapId(view: LuggMapsGoogleMapView, value: String?) {
|
|
65
|
+
view.setMapId(value)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@ReactProp(name = "initialCoordinate")
|
|
69
|
+
override fun setInitialCoordinate(view: LuggMapsGoogleMapView, value: ReadableMap?) {
|
|
70
|
+
value?.let {
|
|
71
|
+
val latitude = if (it.hasKey("latitude")) it.getDouble("latitude") else 0.0
|
|
72
|
+
val longitude = if (it.hasKey("longitude")) it.getDouble("longitude") else 0.0
|
|
73
|
+
view.setInitialCoordinate(latitude, longitude)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@ReactProp(name = "initialZoom", defaultDouble = 10.0)
|
|
78
|
+
override fun setInitialZoom(view: LuggMapsGoogleMapView, value: Double) {
|
|
79
|
+
view.setInitialZoom(value)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@ReactProp(name = "zoomEnabled", defaultBoolean = true)
|
|
83
|
+
override fun setZoomEnabled(view: LuggMapsGoogleMapView, value: Boolean) {
|
|
84
|
+
view.setZoomEnabled(value)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@ReactProp(name = "scrollEnabled", defaultBoolean = true)
|
|
88
|
+
override fun setScrollEnabled(view: LuggMapsGoogleMapView, value: Boolean) {
|
|
89
|
+
view.setScrollEnabled(value)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@ReactProp(name = "rotateEnabled", defaultBoolean = true)
|
|
93
|
+
override fun setRotateEnabled(view: LuggMapsGoogleMapView, value: Boolean) {
|
|
94
|
+
view.setRotateEnabled(value)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@ReactProp(name = "pitchEnabled", defaultBoolean = true)
|
|
98
|
+
override fun setPitchEnabled(view: LuggMapsGoogleMapView, value: Boolean) {
|
|
99
|
+
view.setPitchEnabled(value)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@ReactProp(name = "padding")
|
|
103
|
+
override fun setPadding(view: LuggMapsGoogleMapView, value: ReadableMap?) {
|
|
104
|
+
value?.let {
|
|
105
|
+
val top = if (it.hasKey("top")) it.getDouble("top").toFloat().dpToPx().toInt() else 0
|
|
106
|
+
val left = if (it.hasKey("left")) it.getDouble("left").toFloat().dpToPx().toInt() else 0
|
|
107
|
+
val bottom = if (it.hasKey("bottom")) it.getDouble("bottom").toFloat().dpToPx().toInt() else 0
|
|
108
|
+
val right = if (it.hasKey("right")) it.getDouble("right").toFloat().dpToPx().toInt() else 0
|
|
109
|
+
view.setMapPadding(top, left, bottom, right)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
override fun onDropViewInstance(view: LuggMapsGoogleMapView) {
|
|
114
|
+
super.onDropViewInstance(view)
|
|
115
|
+
view.onDropViewInstance()
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
override fun moveCamera(
|
|
119
|
+
view: LuggMapsGoogleMapView,
|
|
120
|
+
latitude: Double,
|
|
121
|
+
longitude: Double,
|
|
122
|
+
zoom: Double,
|
|
123
|
+
duration: Double
|
|
124
|
+
) {
|
|
125
|
+
view.moveCamera(latitude, longitude, zoom, duration.toInt())
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
override fun fitCoordinates(view: LuggMapsGoogleMapView, coordinates: ReadableArray?, padding: Double, duration: Double) {
|
|
129
|
+
val coords = mutableListOf<LatLng>()
|
|
130
|
+
coordinates?.let {
|
|
131
|
+
for (i in 0 until it.size()) {
|
|
132
|
+
val coord = it.getMap(i)
|
|
133
|
+
val lat = coord?.getDouble("latitude") ?: 0.0
|
|
134
|
+
val lng = coord?.getDouble("longitude") ?: 0.0
|
|
135
|
+
coords.add(LatLng(lat, lng))
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
view.fitCoordinates(coords, padding.toInt(), duration.toInt())
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
companion object {
|
|
142
|
+
const val NAME = "LuggMapsGoogleMapView"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
package com.luggmaps
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import android.view.View
|
|
6
|
+
import androidx.core.view.isNotEmpty
|
|
7
|
+
import com.facebook.react.views.view.ReactViewGroup
|
|
8
|
+
import com.google.android.gms.maps.model.AdvancedMarker
|
|
9
|
+
|
|
10
|
+
interface LuggMapsMarkerViewDelegate {
|
|
11
|
+
fun markerViewDidUpdate(markerView: LuggMapsMarkerView)
|
|
12
|
+
fun markerViewDidLayout(markerView: LuggMapsMarkerView)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class LuggMapsMarkerView(context: Context) : ReactViewGroup(context) {
|
|
16
|
+
var name: String? = null
|
|
17
|
+
private set
|
|
18
|
+
|
|
19
|
+
var latitude: Double = 0.0
|
|
20
|
+
private set
|
|
21
|
+
var longitude: Double = 0.0
|
|
22
|
+
private set
|
|
23
|
+
|
|
24
|
+
var title: String? = null
|
|
25
|
+
private set
|
|
26
|
+
var description: String? = null
|
|
27
|
+
private set
|
|
28
|
+
|
|
29
|
+
var delegate: LuggMapsMarkerViewDelegate? = null
|
|
30
|
+
var marker: AdvancedMarker? = null
|
|
31
|
+
|
|
32
|
+
var anchorX: Float = 0.5f
|
|
33
|
+
private set
|
|
34
|
+
var anchorY: Float = 1.0f
|
|
35
|
+
private set
|
|
36
|
+
|
|
37
|
+
var didLayout: Boolean = false
|
|
38
|
+
private set
|
|
39
|
+
|
|
40
|
+
val hasCustomView: Boolean
|
|
41
|
+
get() = iconView.isNotEmpty()
|
|
42
|
+
|
|
43
|
+
val iconView: ReactViewGroup = object : ReactViewGroup(context) {
|
|
44
|
+
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
|
45
|
+
var maxWidth = 0
|
|
46
|
+
var maxHeight = 0
|
|
47
|
+
for (i in 0 until childCount) {
|
|
48
|
+
val child = getChildAt(i)
|
|
49
|
+
if (child.width > maxWidth) maxWidth = child.width
|
|
50
|
+
if (child.height > maxHeight) maxHeight = child.height
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
setMeasuredDimension(maxWidth, maxHeight)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
init {
|
|
58
|
+
visibility = GONE
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
override fun addView(child: View, index: Int) {
|
|
62
|
+
iconView.addView(child, index)
|
|
63
|
+
didLayout = false
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override fun removeView(child: View) {
|
|
67
|
+
iconView.removeView(child)
|
|
68
|
+
didLayout = false
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
override fun removeViewAt(index: Int) {
|
|
72
|
+
iconView.removeViewAt(index)
|
|
73
|
+
didLayout = false
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
override fun getChildCount(): Int = iconView.childCount
|
|
77
|
+
|
|
78
|
+
override fun getChildAt(index: Int): View? = iconView.getChildAt(index)
|
|
79
|
+
|
|
80
|
+
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
|
81
|
+
super.onSizeChanged(w, h, oldw, oldh)
|
|
82
|
+
didLayout = false
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
override fun onLayout(
|
|
86
|
+
changed: Boolean,
|
|
87
|
+
left: Int,
|
|
88
|
+
top: Int,
|
|
89
|
+
right: Int,
|
|
90
|
+
bottom: Int
|
|
91
|
+
) {
|
|
92
|
+
super.onLayout(changed, left, top, right, bottom)
|
|
93
|
+
if (changed && !didLayout) {
|
|
94
|
+
didLayout = true
|
|
95
|
+
delegate?.markerViewDidLayout(this)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fun setCoordinate(latitude: Double, longitude: Double) {
|
|
100
|
+
this.latitude = latitude
|
|
101
|
+
this.longitude = longitude
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
fun setTitle(title: String?) {
|
|
105
|
+
this.title = title
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
fun setDescription(description: String?) {
|
|
109
|
+
this.description = description
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
fun setAnchor(x: Double, y: Double) {
|
|
113
|
+
anchorX = x.toFloat()
|
|
114
|
+
anchorY = y.toFloat()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
fun setName(name: String?) {
|
|
118
|
+
this.name = name
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
fun onAfterUpdateTransaction() {
|
|
122
|
+
delegate?.markerViewDidUpdate(this)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
fun onDropViewInstance() {
|
|
126
|
+
didLayout = false
|
|
127
|
+
delegate = null
|
|
128
|
+
iconView.removeAllViews()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
companion object {
|
|
132
|
+
private const val TAG = "LuggMaps"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
package com.luggmaps
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.facebook.react.bridge.ReadableMap
|
|
5
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
6
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
7
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
8
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
9
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
10
|
+
import com.facebook.react.viewmanagers.LuggMapsMarkerViewManagerDelegate
|
|
11
|
+
import com.facebook.react.viewmanagers.LuggMapsMarkerViewManagerInterface
|
|
12
|
+
|
|
13
|
+
@ReactModule(name = LuggMapsMarkerViewManager.NAME)
|
|
14
|
+
class LuggMapsMarkerViewManager :
|
|
15
|
+
ViewGroupManager<LuggMapsMarkerView>(),
|
|
16
|
+
LuggMapsMarkerViewManagerInterface<LuggMapsMarkerView> {
|
|
17
|
+
private val delegate: ViewManagerDelegate<LuggMapsMarkerView> = LuggMapsMarkerViewManagerDelegate(this)
|
|
18
|
+
|
|
19
|
+
override fun getDelegate(): ViewManagerDelegate<LuggMapsMarkerView> = delegate
|
|
20
|
+
override fun getName(): String = NAME
|
|
21
|
+
override fun createViewInstance(context: ThemedReactContext): LuggMapsMarkerView = LuggMapsMarkerView(context)
|
|
22
|
+
|
|
23
|
+
override fun onDropViewInstance(view: LuggMapsMarkerView) {
|
|
24
|
+
super.onDropViewInstance(view)
|
|
25
|
+
view.onDropViewInstance()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override fun onAfterUpdateTransaction(view: LuggMapsMarkerView) {
|
|
29
|
+
super.onAfterUpdateTransaction(view)
|
|
30
|
+
view.onAfterUpdateTransaction()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@ReactProp(name = "coordinate")
|
|
34
|
+
override fun setCoordinate(view: LuggMapsMarkerView, value: ReadableMap?) {
|
|
35
|
+
value?.let {
|
|
36
|
+
val latitude = if (it.hasKey("latitude")) it.getDouble("latitude") else 0.0
|
|
37
|
+
val longitude = if (it.hasKey("longitude")) it.getDouble("longitude") else 0.0
|
|
38
|
+
view.setCoordinate(latitude, longitude)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@ReactProp(name = "name")
|
|
43
|
+
override fun setName(view: LuggMapsMarkerView, value: String?) {
|
|
44
|
+
view.setName(value)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@ReactProp(name = "title")
|
|
48
|
+
override fun setTitle(view: LuggMapsMarkerView, value: String?) {
|
|
49
|
+
view.setTitle(value)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@ReactProp(name = "description")
|
|
53
|
+
override fun setDescription(view: LuggMapsMarkerView, value: String?) {
|
|
54
|
+
view.setDescription(value)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@ReactProp(name = "anchor")
|
|
58
|
+
override fun setAnchor(view: LuggMapsMarkerView, value: ReadableMap?) {
|
|
59
|
+
value?.let {
|
|
60
|
+
val x = if (it.hasKey("x")) it.getDouble("x") else 0.5
|
|
61
|
+
val y = if (it.hasKey("y")) it.getDouble("y") else 1.0
|
|
62
|
+
view.setAnchor(x, y)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
companion object {
|
|
67
|
+
const val NAME = "LuggMapsMarkerView"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
package com.luggmaps
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
class LuggMapsPackage : ReactPackage {
|
|
9
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> =
|
|
10
|
+
listOf(LuggMapsGoogleMapViewManager(), LuggMapsMarkerViewManager(), LuggMapsWrapperViewManager(), LuggMapsPolylineViewManager())
|
|
11
|
+
|
|
12
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> = emptyList()
|
|
13
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
package com.luggmaps
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.graphics.Color
|
|
5
|
+
import com.facebook.react.views.view.ReactViewGroup
|
|
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
|
+
|
|
11
|
+
interface LuggMapsPolylineViewDelegate {
|
|
12
|
+
fun polylineViewDidUpdate(polylineView: LuggMapsPolylineView)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class LuggMapsPolylineView(context: Context) : ReactViewGroup(context) {
|
|
16
|
+
var coordinates: List<LatLng> = emptyList()
|
|
17
|
+
private set
|
|
18
|
+
|
|
19
|
+
var strokeColors: List<Int> = listOf(Color.BLACK)
|
|
20
|
+
private set
|
|
21
|
+
|
|
22
|
+
var strokeWidth: Float = 1f
|
|
23
|
+
private set
|
|
24
|
+
|
|
25
|
+
var animated: Boolean = false
|
|
26
|
+
private set
|
|
27
|
+
|
|
28
|
+
var cachedSpans: List<StyleSpan>? = null
|
|
29
|
+
private set
|
|
30
|
+
|
|
31
|
+
var delegate: LuggMapsPolylineViewDelegate? = null
|
|
32
|
+
var polyline: Polyline? = null
|
|
33
|
+
|
|
34
|
+
init {
|
|
35
|
+
visibility = GONE
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fun setCoordinates(coords: List<LatLng>) {
|
|
39
|
+
coordinates = coords
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fun setStrokeColors(colors: List<Int>) {
|
|
43
|
+
val newColors = colors.ifEmpty { listOf(Color.BLACK) }
|
|
44
|
+
if (newColors != strokeColors) {
|
|
45
|
+
strokeColors = newColors
|
|
46
|
+
cachedSpans = null
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fun setStrokeWidth(width: Float) {
|
|
51
|
+
strokeWidth = width
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fun setAnimated(value: Boolean) {
|
|
55
|
+
animated = value
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
fun getOrCreateSpans(): List<StyleSpan> {
|
|
59
|
+
cachedSpans?.let { return it }
|
|
60
|
+
|
|
61
|
+
val segmentCount = coordinates.size - 1
|
|
62
|
+
val spans = (0 until segmentCount).map { i ->
|
|
63
|
+
val color = strokeColors[i % strokeColors.size]
|
|
64
|
+
StyleSpan(StrokeStyle.colorBuilder(color).build())
|
|
65
|
+
}
|
|
66
|
+
cachedSpans = spans
|
|
67
|
+
return spans
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
fun onAfterUpdateTransaction() {
|
|
71
|
+
delegate?.polylineViewDidUpdate(this)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
fun onDropViewInstance() {
|
|
75
|
+
delegate = null
|
|
76
|
+
polyline?.remove()
|
|
77
|
+
polyline = null
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
package com.luggmaps
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableArray
|
|
4
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
5
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
7
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
8
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
9
|
+
import com.facebook.react.viewmanagers.LuggMapsPolylineViewManagerDelegate
|
|
10
|
+
import com.facebook.react.viewmanagers.LuggMapsPolylineViewManagerInterface
|
|
11
|
+
import com.google.android.gms.maps.model.LatLng
|
|
12
|
+
|
|
13
|
+
@ReactModule(name = LuggMapsPolylineViewManager.NAME)
|
|
14
|
+
class LuggMapsPolylineViewManager :
|
|
15
|
+
ViewGroupManager<LuggMapsPolylineView>(),
|
|
16
|
+
LuggMapsPolylineViewManagerInterface<LuggMapsPolylineView> {
|
|
17
|
+
private val delegate: ViewManagerDelegate<LuggMapsPolylineView> = LuggMapsPolylineViewManagerDelegate(this)
|
|
18
|
+
|
|
19
|
+
override fun getDelegate(): ViewManagerDelegate<LuggMapsPolylineView> = delegate
|
|
20
|
+
override fun getName(): String = NAME
|
|
21
|
+
override fun createViewInstance(context: ThemedReactContext): LuggMapsPolylineView = LuggMapsPolylineView(context)
|
|
22
|
+
|
|
23
|
+
override fun onDropViewInstance(view: LuggMapsPolylineView) {
|
|
24
|
+
super.onDropViewInstance(view)
|
|
25
|
+
view.onDropViewInstance()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override fun onAfterUpdateTransaction(view: LuggMapsPolylineView) {
|
|
29
|
+
super.onAfterUpdateTransaction(view)
|
|
30
|
+
view.onAfterUpdateTransaction()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@ReactProp(name = "coordinates")
|
|
34
|
+
override fun setCoordinates(view: LuggMapsPolylineView, value: ReadableArray?) {
|
|
35
|
+
value?.let { array ->
|
|
36
|
+
val coords = mutableListOf<LatLng>()
|
|
37
|
+
for (i in 0 until array.size()) {
|
|
38
|
+
val coord = array.getMap(i)
|
|
39
|
+
val lat = coord?.getDouble("latitude") ?: 0.0
|
|
40
|
+
val lng = coord?.getDouble("longitude") ?: 0.0
|
|
41
|
+
coords.add(LatLng(lat, lng))
|
|
42
|
+
}
|
|
43
|
+
view.setCoordinates(coords)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@ReactProp(name = "strokeColors")
|
|
48
|
+
override fun setStrokeColors(view: LuggMapsPolylineView, value: ReadableArray?) {
|
|
49
|
+
val colors = mutableListOf<Int>()
|
|
50
|
+
value?.let { array ->
|
|
51
|
+
for (i in 0 until array.size()) {
|
|
52
|
+
colors.add(array.getInt(i))
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
view.setStrokeColors(colors)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@ReactProp(name = "strokeWidth", defaultDouble = 1.0)
|
|
59
|
+
override fun setStrokeWidth(view: LuggMapsPolylineView, value: Double) {
|
|
60
|
+
view.setStrokeWidth(value.toFloat())
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@ReactProp(name = "animated", defaultBoolean = false)
|
|
64
|
+
override fun setAnimated(view: LuggMapsPolylineView, value: Boolean) {
|
|
65
|
+
view.setAnimated(value)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
companion object {
|
|
69
|
+
const val NAME = "LuggMapsPolylineView"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
package com.luggmaps
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
+
import com.facebook.react.views.view.ReactViewGroup
|
|
6
|
+
|
|
7
|
+
@SuppressLint("ViewConstructor")
|
|
8
|
+
class LuggMapsWrapperView(context: ThemedReactContext) : ReactViewGroup(context) {
|
|
9
|
+
|
|
10
|
+
override fun requestLayout() {
|
|
11
|
+
super.requestLayout()
|
|
12
|
+
getChildAt(0)?.let {
|
|
13
|
+
it.measure(
|
|
14
|
+
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
|
15
|
+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
|
|
16
|
+
)
|
|
17
|
+
it.layout(0, 0, width, height)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
override fun onLayout(
|
|
22
|
+
changed: Boolean,
|
|
23
|
+
left: Int,
|
|
24
|
+
top: Int,
|
|
25
|
+
right: Int,
|
|
26
|
+
bottom: Int
|
|
27
|
+
) {
|
|
28
|
+
super.onLayout(changed, left, top, right, bottom)
|
|
29
|
+
val width = right - left
|
|
30
|
+
val height = bottom - top
|
|
31
|
+
getChildAt(0)?.let {
|
|
32
|
+
it.measure(
|
|
33
|
+
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
|
34
|
+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
|
|
35
|
+
)
|
|
36
|
+
it.layout(0, 0, width, height)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
package com.luggmaps
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
4
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
6
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
7
|
+
import com.facebook.react.viewmanagers.LuggMapsWrapperViewManagerDelegate
|
|
8
|
+
import com.facebook.react.viewmanagers.LuggMapsWrapperViewManagerInterface
|
|
9
|
+
|
|
10
|
+
@ReactModule(name = LuggMapsWrapperViewManager.NAME)
|
|
11
|
+
class LuggMapsWrapperViewManager :
|
|
12
|
+
ViewGroupManager<LuggMapsWrapperView>(),
|
|
13
|
+
LuggMapsWrapperViewManagerInterface<LuggMapsWrapperView> {
|
|
14
|
+
private val delegate: ViewManagerDelegate<LuggMapsWrapperView> = LuggMapsWrapperViewManagerDelegate(this)
|
|
15
|
+
|
|
16
|
+
override fun getDelegate(): ViewManagerDelegate<LuggMapsWrapperView> = delegate
|
|
17
|
+
|
|
18
|
+
override fun getName(): String = NAME
|
|
19
|
+
|
|
20
|
+
override fun createViewInstance(context: ThemedReactContext): LuggMapsWrapperView = LuggMapsWrapperView(context)
|
|
21
|
+
|
|
22
|
+
companion object {
|
|
23
|
+
const val NAME = "LuggMapsWrapperView"
|
|
24
|
+
}
|
|
25
|
+
}
|