@exterio/react-native-yamap-lite 1.0.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 (141) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +510 -0
  3. package/YamapLite.podspec +21 -0
  4. package/android/build.gradle +101 -0
  5. package/android/gradle.properties +14 -0
  6. package/android/settings.gradle +1 -0
  7. package/android/src/main/AndroidManifest.xml +2 -0
  8. package/android/src/main/java/com/yamaplite/ClusteredYamapLiteViewManager.kt +181 -0
  9. package/android/src/main/java/com/yamaplite/Components/ClusteredYamapLiteView.kt +169 -0
  10. package/android/src/main/java/com/yamaplite/Components/YamapLiteCircleView.kt +145 -0
  11. package/android/src/main/java/com/yamaplite/Components/YamapLiteMarkerView.kt +214 -0
  12. package/android/src/main/java/com/yamaplite/Components/YamapLitePolygon.kt +149 -0
  13. package/android/src/main/java/com/yamaplite/Components/YamapLitePolyline.kt +171 -0
  14. package/android/src/main/java/com/yamaplite/Components/YamapLiteView.kt +678 -0
  15. package/android/src/main/java/com/yamaplite/Events/CameraPositionChangeEvent.kt +38 -0
  16. package/android/src/main/java/com/yamaplite/Events/MapLoadEvent.kt +34 -0
  17. package/android/src/main/java/com/yamaplite/Events/PressEvent.kt +24 -0
  18. package/android/src/main/java/com/yamaplite/Utils/ImageCache.kt +45 -0
  19. package/android/src/main/java/com/yamaplite/Utils/PointParser.kt +39 -0
  20. package/android/src/main/java/com/yamaplite/Utils/ResolveImageHelper.kt +122 -0
  21. package/android/src/main/java/com/yamaplite/Utils/YamapUtils.kt +169 -0
  22. package/android/src/main/java/com/yamaplite/YamapLiteCircleViewManager.kt +67 -0
  23. package/android/src/main/java/com/yamaplite/YamapLiteMarkerViewManager.kt +82 -0
  24. package/android/src/main/java/com/yamaplite/YamapLitePackage.kt +41 -0
  25. package/android/src/main/java/com/yamaplite/YamapLitePolygonViewManager.kt +61 -0
  26. package/android/src/main/java/com/yamaplite/YamapLitePolylineViewManager.kt +75 -0
  27. package/android/src/main/java/com/yamaplite/YamapLiteViewManager.kt +176 -0
  28. package/ios/ClusteredYamapLiteView.h +15 -0
  29. package/ios/ClusteredYamapLiteView.mm +325 -0
  30. package/ios/ClusteredYamapLiteViewManager.mm +17 -0
  31. package/ios/Components/Circle.swift +108 -0
  32. package/ios/Components/ClusteredYamap.swift +190 -0
  33. package/ios/Components/Marker.swift +187 -0
  34. package/ios/Components/Polygon.swift +108 -0
  35. package/ios/Components/Polyline.swift +125 -0
  36. package/ios/Components/Yamap.swift +585 -0
  37. package/ios/Listeners/CameraListener.swift +54 -0
  38. package/ios/Listeners/ClusterListener.swift +38 -0
  39. package/ios/Listeners/MapInputListener.swift +35 -0
  40. package/ios/Listeners/MapLoadListener.swift +35 -0
  41. package/ios/Listeners/MapObjectTap.swift +12 -0
  42. package/ios/Listeners/UserLocationObjectListener.swift +29 -0
  43. package/ios/Models/YamapModels.swift +77 -0
  44. package/ios/Utils/ImageCache.swift +20 -0
  45. package/ios/Utils/PointsEqual.h +45 -0
  46. package/ios/Utils/ResolveImageHelper.swift +142 -0
  47. package/ios/YamapLiteCircleView.h +15 -0
  48. package/ios/YamapLiteCircleView.mm +102 -0
  49. package/ios/YamapLiteMarkerView.h +15 -0
  50. package/ios/YamapLiteMarkerView.mm +102 -0
  51. package/ios/YamapLitePolygonView.h +15 -0
  52. package/ios/YamapLitePolygonView.mm +120 -0
  53. package/ios/YamapLitePolylineView.h +15 -0
  54. package/ios/YamapLitePolylineView.mm +115 -0
  55. package/ios/YamapLiteView.h +15 -0
  56. package/ios/YamapLiteView.mm +361 -0
  57. package/ios/YamapLiteViewManager.mm +17 -0
  58. package/ios/YamapUtils.h +5 -0
  59. package/ios/YamapUtils.mm +205 -0
  60. package/lib/module/@types/index.js +8 -0
  61. package/lib/module/@types/index.js.map +1 -0
  62. package/lib/module/ClusteredYamapLiteViewNativeComponent.ts +98 -0
  63. package/lib/module/Components/Circle.js +20 -0
  64. package/lib/module/Components/Circle.js.map +1 -0
  65. package/lib/module/Components/ClusteredYamap.js +133 -0
  66. package/lib/module/Components/ClusteredYamap.js.map +1 -0
  67. package/lib/module/Components/Marker.js +40 -0
  68. package/lib/module/Components/Marker.js.map +1 -0
  69. package/lib/module/Components/Polygon.js +25 -0
  70. package/lib/module/Components/Polygon.js.map +1 -0
  71. package/lib/module/Components/Polyline.js +25 -0
  72. package/lib/module/Components/Polyline.js.map +1 -0
  73. package/lib/module/Components/Yamap.js +124 -0
  74. package/lib/module/Components/Yamap.js.map +1 -0
  75. package/lib/module/Components/index.js +9 -0
  76. package/lib/module/Components/index.js.map +1 -0
  77. package/lib/module/NativeYamapUtils.js +5 -0
  78. package/lib/module/NativeYamapUtils.js.map +1 -0
  79. package/lib/module/Utils/YamapUtils.js +14 -0
  80. package/lib/module/Utils/YamapUtils.js.map +1 -0
  81. package/lib/module/YamapCircleViewNativeComponent.ts +28 -0
  82. package/lib/module/YamapLiteViewNativeComponent.ts +93 -0
  83. package/lib/module/YamapMarkerViewNativeComponent.ts +32 -0
  84. package/lib/module/YamapPolygonViewNativeComponent.ts +28 -0
  85. package/lib/module/YamapPolylineViewNativeComponent.ts +31 -0
  86. package/lib/module/index.js +7 -0
  87. package/lib/module/index.js.map +1 -0
  88. package/lib/module/package.json +1 -0
  89. package/lib/typescript/package.json +1 -0
  90. package/lib/typescript/src/@types/index.d.ts +257 -0
  91. package/lib/typescript/src/@types/index.d.ts.map +1 -0
  92. package/lib/typescript/src/ClusteredYamapLiteViewNativeComponent.d.ts +82 -0
  93. package/lib/typescript/src/ClusteredYamapLiteViewNativeComponent.d.ts.map +1 -0
  94. package/lib/typescript/src/Components/Circle.d.ts +4 -0
  95. package/lib/typescript/src/Components/Circle.d.ts.map +1 -0
  96. package/lib/typescript/src/Components/ClusteredYamap.d.ts +3 -0
  97. package/lib/typescript/src/Components/ClusteredYamap.d.ts.map +1 -0
  98. package/lib/typescript/src/Components/Marker.d.ts +3 -0
  99. package/lib/typescript/src/Components/Marker.d.ts.map +1 -0
  100. package/lib/typescript/src/Components/Polygon.d.ts +4 -0
  101. package/lib/typescript/src/Components/Polygon.d.ts.map +1 -0
  102. package/lib/typescript/src/Components/Polyline.d.ts +4 -0
  103. package/lib/typescript/src/Components/Polyline.d.ts.map +1 -0
  104. package/lib/typescript/src/Components/Yamap.d.ts +3 -0
  105. package/lib/typescript/src/Components/Yamap.d.ts.map +1 -0
  106. package/lib/typescript/src/Components/index.d.ts +7 -0
  107. package/lib/typescript/src/Components/index.d.ts.map +1 -0
  108. package/lib/typescript/src/NativeYamapUtils.d.ts +30 -0
  109. package/lib/typescript/src/NativeYamapUtils.d.ts.map +1 -0
  110. package/lib/typescript/src/Utils/YamapUtils.d.ts +27 -0
  111. package/lib/typescript/src/Utils/YamapUtils.d.ts.map +1 -0
  112. package/lib/typescript/src/YamapCircleViewNativeComponent.d.ts +20 -0
  113. package/lib/typescript/src/YamapCircleViewNativeComponent.d.ts.map +1 -0
  114. package/lib/typescript/src/YamapLiteViewNativeComponent.d.ts +80 -0
  115. package/lib/typescript/src/YamapLiteViewNativeComponent.d.ts.map +1 -0
  116. package/lib/typescript/src/YamapMarkerViewNativeComponent.d.ts +25 -0
  117. package/lib/typescript/src/YamapMarkerViewNativeComponent.d.ts.map +1 -0
  118. package/lib/typescript/src/YamapPolygonViewNativeComponent.d.ts +20 -0
  119. package/lib/typescript/src/YamapPolygonViewNativeComponent.d.ts.map +1 -0
  120. package/lib/typescript/src/YamapPolylineViewNativeComponent.d.ts +23 -0
  121. package/lib/typescript/src/YamapPolylineViewNativeComponent.d.ts.map +1 -0
  122. package/lib/typescript/src/index.d.ts +5 -0
  123. package/lib/typescript/src/index.d.ts.map +1 -0
  124. package/package.json +189 -0
  125. package/src/@types/index.ts +314 -0
  126. package/src/ClusteredYamapLiteViewNativeComponent.ts +98 -0
  127. package/src/Components/Circle.tsx +22 -0
  128. package/src/Components/ClusteredYamap.tsx +194 -0
  129. package/src/Components/Marker.tsx +50 -0
  130. package/src/Components/Polygon.tsx +27 -0
  131. package/src/Components/Polyline.tsx +27 -0
  132. package/src/Components/Yamap.tsx +176 -0
  133. package/src/Components/index.ts +6 -0
  134. package/src/NativeYamapUtils.ts +47 -0
  135. package/src/Utils/YamapUtils.ts +63 -0
  136. package/src/YamapCircleViewNativeComponent.ts +28 -0
  137. package/src/YamapLiteViewNativeComponent.ts +93 -0
  138. package/src/YamapMarkerViewNativeComponent.ts +32 -0
  139. package/src/YamapPolygonViewNativeComponent.ts +28 -0
  140. package/src/YamapPolylineViewNativeComponent.ts +31 -0
  141. package/src/index.tsx +5 -0
@@ -0,0 +1,149 @@
1
+ package com.yamaplite.components
2
+
3
+ import android.content.Context
4
+ import android.graphics.Color
5
+ import android.view.ViewGroup
6
+ import com.facebook.react.bridge.ReactContext
7
+ import com.facebook.react.uimanager.UIManagerHelper
8
+ import com.yamaplite.events.PressEvent
9
+ import com.yandex.mapkit.geometry.LinearRing
10
+ import com.yandex.mapkit.geometry.Point
11
+ import com.yandex.mapkit.geometry.Polygon
12
+ import com.yandex.mapkit.map.MapObject
13
+ import com.yandex.mapkit.map.MapObjectTapListener
14
+ import com.yandex.mapkit.map.PolygonMapObject
15
+ import com.yandex.mapkit.mapview.MapView
16
+
17
+ class YamapPolygon(context: Context?) : ViewGroup(context), MapObjectTapListener {
18
+ var polygon = Polygon()
19
+
20
+ var rnMapObject: MapObject? = null
21
+
22
+ private var mapView: MapView? = null
23
+
24
+ private var fillColor = Color.BLACK
25
+
26
+ private var strokeColor = Color.BLACK
27
+
28
+ private var strokeWidth = 1f
29
+
30
+ private var zIndex = 1f
31
+
32
+ private var points: ArrayList<Point> = ArrayList()
33
+
34
+ private var innerRings: ArrayList<ArrayList<Point>>? = ArrayList()
35
+
36
+ private var handled = true
37
+
38
+ init {
39
+ polygon = Polygon(LinearRing(points), emptyList())
40
+ }
41
+
42
+ fun setFillColor(_color: Int) {
43
+ fillColor = _color
44
+ updatePolygon()
45
+ }
46
+
47
+ fun setStrokeColor(_color: Int) {
48
+ strokeColor = _color
49
+ updatePolygon()
50
+ }
51
+
52
+ fun setStrokeWidth(_width: Float) {
53
+ strokeWidth = _width
54
+ updatePolygon()
55
+ }
56
+
57
+ fun setZIndex(_zIndex: Float) {
58
+ zIndex = _zIndex
59
+ updatePolygon()
60
+ }
61
+
62
+ fun setPoints(_points: ArrayList<Point>) {
63
+ points = _points
64
+ updateGeometry()
65
+ if (rnMapObject == null && mapView != null && isGeometryValid()) {
66
+ addToMap(mapView!!)
67
+ } else {
68
+ updatePolygon()
69
+ }
70
+ }
71
+
72
+ fun setInnerRings(_innerRings: ArrayList<ArrayList<Point>>) {
73
+ innerRings = _innerRings
74
+ updateGeometry()
75
+ updatePolygon()
76
+ }
77
+
78
+ private fun List<Point>.isValidRing(): Boolean =
79
+ size >= 3 && all { it.latitude.isFinite() && it.longitude.isFinite() }
80
+
81
+ private fun isGeometryValid(): Boolean = points.isValidRing()
82
+
83
+ fun setHandled(_handled: Boolean) {
84
+ handled = _handled
85
+ }
86
+
87
+ override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {}
88
+
89
+ private fun updatePolygon() {
90
+ if (rnMapObject != null) {
91
+ val polygonMapObject = rnMapObject as PolygonMapObject
92
+ polygonMapObject.geometry = polygon
93
+ polygonMapObject.zIndex = zIndex
94
+ polygonMapObject.fillColor = fillColor
95
+ polygonMapObject.strokeColor = strokeColor
96
+ polygonMapObject.strokeWidth = strokeWidth
97
+ }
98
+ }
99
+ private fun updateGeometry() {
100
+ if (!isGeometryValid()) return
101
+ val ring = LinearRing(points)
102
+ val unwrappedInnerRings =
103
+ (innerRings ?: ArrayList()).filter { it.isValidRing() }.map { LinearRing(it) }
104
+ polygon = Polygon(ring, unwrappedInnerRings)
105
+ }
106
+
107
+ override fun onMapObjectTap(mapObject: MapObject, point: Point): Boolean {
108
+ val reactContext = context as? ReactContext
109
+ if (reactContext == null) {
110
+ return false
111
+ }
112
+ val viewId = getId()
113
+ val surfaceId = UIManagerHelper.getSurfaceId(reactContext)
114
+ val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, viewId)
115
+ if (eventDispatcher != null) {
116
+ val event = PressEvent(surfaceId, viewId, "onPolygonPress", point)
117
+ eventDispatcher.dispatchEvent(event)
118
+ }
119
+ return handled
120
+ }
121
+
122
+ fun setMapObject(obj: MapObject) {
123
+ if (obj is PolygonMapObject) {
124
+ rnMapObject = obj
125
+ rnMapObject!!.addTapListener(this)
126
+ updatePolygon()
127
+ }
128
+ }
129
+
130
+ fun addToMap(mapView: MapView) {
131
+ this.mapView = mapView
132
+ if (!isGeometryValid()) {
133
+ return
134
+ }
135
+ val polygonObject = mapView.mapWindow.map.mapObjects.addPolygon(polygon)
136
+ rnMapObject = polygonObject
137
+ polygonObject.addTapListener(this)
138
+ updatePolygon()
139
+ }
140
+
141
+ fun removeFromMap(mapView: MapView) {
142
+ rnMapObject?.let {
143
+ if (it.isValid) {
144
+ mapView.mapWindow.map.mapObjects.remove(it)
145
+ }
146
+ }
147
+ rnMapObject = null
148
+ }
149
+ }
@@ -0,0 +1,171 @@
1
+ package com.yamaplite.components
2
+
3
+ import android.content.Context
4
+ import android.graphics.Color
5
+ import android.view.ViewGroup
6
+ import com.facebook.react.bridge.ReactContext
7
+ import com.facebook.react.uimanager.UIManagerHelper
8
+ import com.yamaplite.events.PressEvent
9
+ import com.yandex.mapkit.geometry.Point
10
+ import com.yandex.mapkit.geometry.Polyline
11
+ import com.yandex.mapkit.map.MapObject
12
+ import com.yandex.mapkit.map.MapObjectTapListener
13
+ import com.yandex.mapkit.map.PolylineMapObject
14
+ import com.yandex.mapkit.mapview.MapView
15
+
16
+ class YamapPolyline(context: Context?) : ViewGroup(context), MapObjectTapListener {
17
+ var polyline: Polyline
18
+
19
+ var rnMapObject: MapObject? = null
20
+
21
+ private var mapView: MapView? = null
22
+
23
+ private var strokeColor = Color.BLACK
24
+
25
+ private var strokeWidth = 1f
26
+
27
+ private var outlineColor = Color.BLACK
28
+
29
+ private var zIndex = 1f
30
+
31
+ private var dashLength = 1f
32
+
33
+ private var gapLength = 0f
34
+
35
+ private var outlineWidth = 0f
36
+
37
+ private var dashOffset = 0f
38
+
39
+ private var points: ArrayList<Point> = ArrayList()
40
+
41
+ private var handled = true
42
+
43
+ init {
44
+ polyline = Polyline(points)
45
+ }
46
+
47
+ override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {}
48
+
49
+ fun setStrokeColor(_color: Int) {
50
+ strokeColor = _color
51
+ updatePolyline()
52
+ }
53
+
54
+ fun setStrokeWidth(_width: Float) {
55
+ strokeWidth = _width
56
+ updatePolyline()
57
+ }
58
+
59
+ fun setOutlineColor(_color: Int) {
60
+ outlineColor = _color
61
+ updatePolyline()
62
+ }
63
+
64
+ fun setZIndex(_zIndex: Float) {
65
+ zIndex = _zIndex
66
+ updatePolyline()
67
+ }
68
+
69
+ fun setDashLength(_dashLength: Float) {
70
+ dashLength = _dashLength
71
+ updatePolyline()
72
+ }
73
+
74
+ fun setGapLength(_gapLength: Float) {
75
+ gapLength = _gapLength
76
+ updatePolyline()
77
+ }
78
+
79
+ fun setOutlineWidth(_outlineWidth: Float) {
80
+ outlineWidth = _outlineWidth
81
+ updatePolyline()
82
+ }
83
+
84
+ fun setDashOffset(_dashOffset: Float) {
85
+ dashOffset = _dashOffset
86
+ updatePolyline()
87
+ }
88
+
89
+ fun setPoints(_points: ArrayList<Point>) {
90
+ points = _points
91
+ updateGeometry()
92
+ if (rnMapObject == null && mapView != null && isGeometryValid()) {
93
+ addToMap(mapView!!)
94
+ } else {
95
+ updatePolyline()
96
+ }
97
+ }
98
+
99
+ private fun isGeometryValid(): Boolean =
100
+ points.size >= 2 && points.all { it.latitude.isFinite() && it.longitude.isFinite() }
101
+
102
+ fun setHandled(_handled: Boolean) {
103
+ handled = _handled
104
+ }
105
+
106
+ private fun updatePolyline() {
107
+ if (rnMapObject != null) {
108
+ val polylineMapObject = rnMapObject as PolylineMapObject
109
+ polylineMapObject.geometry = polyline
110
+ polylineMapObject.zIndex = zIndex
111
+ polylineMapObject.setStrokeColor(strokeColor)
112
+ polylineMapObject.strokeWidth = strokeWidth
113
+ polylineMapObject.dashLength = dashLength
114
+ polylineMapObject.gapLength = gapLength
115
+ polylineMapObject.dashOffset = dashOffset
116
+ polylineMapObject.outlineWidth = outlineWidth
117
+ if (outlineWidth > 0) {
118
+ polylineMapObject.outlineColor = outlineColor
119
+ }
120
+ }
121
+ }
122
+
123
+ private fun updateGeometry() {
124
+ if (isGeometryValid()) {
125
+ polyline = Polyline(points)
126
+ }
127
+ }
128
+
129
+ fun setMapObject(obj: MapObject) {
130
+ if (obj is PolylineMapObject) {
131
+ rnMapObject = obj
132
+ rnMapObject!!.addTapListener(this)
133
+ updatePolyline()
134
+ }
135
+ }
136
+
137
+ override fun onMapObjectTap(mapObject: MapObject, point: Point): Boolean {
138
+ val reactContext = context as? ReactContext
139
+ if (reactContext == null) {
140
+ return false
141
+ }
142
+ val viewId = getId()
143
+ val surfaceId = UIManagerHelper.getSurfaceId(reactContext)
144
+ val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, viewId)
145
+ if (eventDispatcher != null) {
146
+ val event = PressEvent(surfaceId, viewId, "onPolylinePress", point)
147
+ eventDispatcher.dispatchEvent(event)
148
+ }
149
+ return handled
150
+ }
151
+
152
+ fun addToMap(mapView: MapView) {
153
+ this.mapView = mapView
154
+ if (!isGeometryValid()) {
155
+ return
156
+ }
157
+ val polylineObject = mapView.mapWindow.map.mapObjects.addPolyline(polyline)
158
+ rnMapObject = polylineObject
159
+ polylineObject.addTapListener(this)
160
+ updatePolyline()
161
+ }
162
+
163
+ fun removeFromMap(mapView: MapView) {
164
+ rnMapObject?.let {
165
+ if (it.isValid) {
166
+ mapView.mapWindow.map.mapObjects.remove(it)
167
+ }
168
+ }
169
+ rnMapObject = null
170
+ }
171
+ }