@maplibre/maplibre-react-native 11.0.0-alpha.25 → 11.0.0-alpha.27

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 (245) hide show
  1. package/MapLibreReactNative.podspec +1 -1
  2. package/android/gradle.properties +1 -1
  3. package/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +16 -1
  4. package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.kt +20 -32
  5. package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNRasterSource.java +1 -1
  6. package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNSource.kt +228 -0
  7. package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNTileSource.java +0 -1
  8. package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNVectorSourceManager.java +2 -2
  9. package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/ClusterPropertyEntry.kt +5 -0
  10. package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/MLRNShapeSource.kt +232 -0
  11. package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/MLRNShapeSourceManager.kt +183 -0
  12. package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/MLRNShapeSourceModule.kt +65 -0
  13. package/android/src/main/java/org/maplibre/reactnative/events/MapPressEvent.kt +1 -1
  14. package/android/src/main/java/org/maplibre/reactnative/events/MapPressEventWithFeatures.kt +24 -0
  15. package/android/src/main/java/org/maplibre/reactnative/utils/ConvertUtils.kt +203 -0
  16. package/android/src/main/java/org/maplibre/reactnative/utils/ExpressionParser.kt +70 -0
  17. package/android/src/main/java/org/maplibre/reactnative/utils/GeoJSONUtils.kt +37 -20
  18. package/ios/components/camera/MLRNCameraModule.mm +10 -20
  19. package/ios/components/map-view/MLRNMapViewModule.mm +10 -20
  20. package/ios/components/sources/MLRNSource.h +3 -0
  21. package/ios/components/sources/{MLRNShapeSource.h → shape-source/MLRNShapeSource.h} +3 -5
  22. package/ios/components/sources/{MLRNShapeSource.m → shape-source/MLRNShapeSource.m} +4 -12
  23. package/ios/components/sources/shape-source/MLRNShapeSourceComponentView.h +11 -0
  24. package/ios/components/sources/shape-source/MLRNShapeSourceComponentView.mm +163 -0
  25. package/ios/components/sources/shape-source/MLRNShapeSourceModule.h +5 -0
  26. package/ios/components/sources/shape-source/MLRNShapeSourceModule.mm +136 -0
  27. package/ios/utils/MLRNViewModuleUtils.h +35 -0
  28. package/ios/utils/MLRNViewModuleUtils.m +39 -0
  29. package/lib/commonjs/components/annotations/Annotation.js +1 -1
  30. package/lib/commonjs/components/annotations/Annotation.js.map +1 -1
  31. package/lib/commonjs/components/layers/BackgroundLayer.js.map +1 -1
  32. package/lib/commonjs/components/layers/CircleLayer.js.map +1 -1
  33. package/lib/commonjs/components/layers/FillExtrusionLayer.js.map +1 -1
  34. package/lib/commonjs/components/layers/HeatmapLayer.js.map +1 -1
  35. package/lib/commonjs/components/layers/RasterLayer.js.map +1 -1
  36. package/lib/commonjs/components/layers/SymbolLayer.js.map +1 -1
  37. package/lib/commonjs/components/map-view/MapView.js +16 -22
  38. package/lib/commonjs/components/map-view/MapView.js.map +1 -1
  39. package/lib/commonjs/components/sources/VectorSource.js +2 -2
  40. package/lib/commonjs/components/sources/VectorSource.js.map +1 -1
  41. package/lib/commonjs/components/sources/shape-source/NativeShapeSourceModule.js +9 -0
  42. package/lib/commonjs/components/sources/shape-source/NativeShapeSourceModule.js.map +1 -0
  43. package/lib/commonjs/components/sources/shape-source/ShapeSource.js +51 -0
  44. package/lib/commonjs/components/sources/shape-source/ShapeSource.js.map +1 -0
  45. package/lib/commonjs/components/sources/shape-source/ShapeSourceNativeComponent.ts +48 -0
  46. package/lib/commonjs/hooks/useAbstractLayer.js +2 -2
  47. package/lib/commonjs/hooks/useAbstractLayer.js.map +1 -1
  48. package/lib/commonjs/hooks/useFrozenId.js +16 -0
  49. package/lib/commonjs/hooks/useFrozenId.js.map +1 -0
  50. package/lib/commonjs/index.js +1 -1
  51. package/lib/commonjs/index.js.map +1 -1
  52. package/lib/commonjs/modules/snapshot/SnapshotOptions.js.map +1 -1
  53. package/lib/commonjs/types/PressEventWithFeatures.js +6 -0
  54. package/lib/commonjs/types/PressEventWithFeatures.js.map +1 -0
  55. package/lib/commonjs/utils/animated/AbstractAnimatedCoordinates.js +0 -6
  56. package/lib/commonjs/utils/animated/AbstractAnimatedCoordinates.js.map +1 -1
  57. package/lib/commonjs/utils/animated/Animated.js +4 -4
  58. package/lib/commonjs/utils/animated/Animated.js.map +1 -1
  59. package/lib/commonjs/utils/animated/AnimatedExtractCoordinateFromArray.js +0 -6
  60. package/lib/commonjs/utils/animated/AnimatedExtractCoordinateFromArray.js.map +1 -1
  61. package/lib/commonjs/utils/animated/AnimatedPoint.js +0 -2
  62. package/lib/commonjs/utils/animated/AnimatedPoint.js.map +1 -1
  63. package/lib/commonjs/utils/animated/AnimatedShape.js +3 -16
  64. package/lib/commonjs/utils/animated/AnimatedShape.js.map +1 -1
  65. package/lib/commonjs/utils/findNodeHandle.js +16 -0
  66. package/lib/commonjs/utils/findNodeHandle.js.map +1 -0
  67. package/lib/commonjs/utils/{filterUtils.js → getFilter.js} +2 -2
  68. package/lib/commonjs/utils/getFilter.js.map +1 -0
  69. package/lib/commonjs/utils/index.js +3 -8
  70. package/lib/commonjs/utils/index.js.map +1 -1
  71. package/lib/module/components/annotations/Annotation.js +1 -1
  72. package/lib/module/components/annotations/Annotation.js.map +1 -1
  73. package/lib/module/components/layers/BackgroundLayer.js.map +1 -1
  74. package/lib/module/components/layers/CircleLayer.js.map +1 -1
  75. package/lib/module/components/layers/FillExtrusionLayer.js.map +1 -1
  76. package/lib/module/components/layers/HeatmapLayer.js.map +1 -1
  77. package/lib/module/components/layers/RasterLayer.js.map +1 -1
  78. package/lib/module/components/layers/SymbolLayer.js.map +1 -1
  79. package/lib/module/components/map-view/MapView.js +3 -9
  80. package/lib/module/components/map-view/MapView.js.map +1 -1
  81. package/lib/module/components/sources/VectorSource.js +1 -1
  82. package/lib/module/components/sources/VectorSource.js.map +1 -1
  83. package/lib/module/components/sources/shape-source/NativeShapeSourceModule.js +5 -0
  84. package/lib/module/components/sources/shape-source/NativeShapeSourceModule.js.map +1 -0
  85. package/lib/module/components/sources/shape-source/ShapeSource.js +46 -0
  86. package/lib/module/components/sources/shape-source/ShapeSource.js.map +1 -0
  87. package/lib/module/components/sources/shape-source/ShapeSourceNativeComponent.ts +48 -0
  88. package/lib/module/hooks/useAbstractLayer.js +1 -1
  89. package/lib/module/hooks/useAbstractLayer.js.map +1 -1
  90. package/lib/module/hooks/useFrozenId.js +12 -0
  91. package/lib/module/hooks/useFrozenId.js.map +1 -0
  92. package/lib/module/index.js +1 -1
  93. package/lib/module/index.js.map +1 -1
  94. package/lib/module/modules/snapshot/SnapshotOptions.js.map +1 -1
  95. package/lib/module/types/PressEventWithFeatures.js +4 -0
  96. package/lib/module/types/PressEventWithFeatures.js.map +1 -0
  97. package/lib/module/utils/animated/AbstractAnimatedCoordinates.js +0 -7
  98. package/lib/module/utils/animated/AbstractAnimatedCoordinates.js.map +1 -1
  99. package/lib/module/utils/animated/Animated.js +4 -4
  100. package/lib/module/utils/animated/Animated.js.map +1 -1
  101. package/lib/module/utils/animated/AnimatedExtractCoordinateFromArray.js +0 -6
  102. package/lib/module/utils/animated/AnimatedExtractCoordinateFromArray.js.map +1 -1
  103. package/lib/module/utils/animated/AnimatedPoint.js +0 -3
  104. package/lib/module/utils/animated/AnimatedPoint.js.map +1 -1
  105. package/lib/module/utils/animated/AnimatedShape.js +3 -16
  106. package/lib/module/utils/animated/AnimatedShape.js.map +1 -1
  107. package/lib/module/utils/findNodeHandle.js +11 -0
  108. package/lib/module/utils/findNodeHandle.js.map +1 -0
  109. package/lib/module/utils/getFilter.js +9 -0
  110. package/lib/module/utils/getFilter.js.map +1 -0
  111. package/lib/module/utils/index.js +3 -8
  112. package/lib/module/utils/index.js.map +1 -1
  113. package/lib/typescript/commonjs/src/components/annotations/Annotation.d.ts +1 -1
  114. package/lib/typescript/commonjs/src/components/annotations/Annotation.d.ts.map +1 -1
  115. package/lib/typescript/commonjs/src/components/layers/BackgroundLayer.d.ts.map +1 -1
  116. package/lib/typescript/commonjs/src/components/layers/CircleLayer.d.ts.map +1 -1
  117. package/lib/typescript/commonjs/src/components/layers/FillExtrusionLayer.d.ts.map +1 -1
  118. package/lib/typescript/commonjs/src/components/layers/HeatmapLayer.d.ts.map +1 -1
  119. package/lib/typescript/commonjs/src/components/layers/RasterLayer.d.ts.map +1 -1
  120. package/lib/typescript/commonjs/src/components/layers/SymbolLayer.d.ts.map +1 -1
  121. package/lib/typescript/commonjs/src/components/map-view/MapView.d.ts.map +1 -1
  122. package/lib/typescript/commonjs/src/components/sources/VectorSource.d.ts +1 -1
  123. package/lib/typescript/commonjs/src/components/sources/VectorSource.d.ts.map +1 -1
  124. package/lib/typescript/commonjs/src/components/sources/shape-source/NativeShapeSourceModule.d.ts +10 -0
  125. package/lib/typescript/commonjs/src/components/sources/shape-source/NativeShapeSourceModule.d.ts.map +1 -0
  126. package/lib/typescript/{module/src/components/sources → commonjs/src/components/sources/shape-source}/ShapeSource.d.ts +60 -41
  127. package/lib/typescript/commonjs/src/components/sources/shape-source/ShapeSource.d.ts.map +1 -0
  128. package/lib/typescript/commonjs/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts +35 -0
  129. package/lib/typescript/commonjs/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts.map +1 -0
  130. package/lib/typescript/commonjs/src/hooks/useFrozenId.d.ts +2 -0
  131. package/lib/typescript/commonjs/src/hooks/useFrozenId.d.ts.map +1 -0
  132. package/lib/typescript/commonjs/src/index.d.ts +4 -3
  133. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  134. package/lib/typescript/commonjs/src/modules/snapshot/SnapshotOptions.d.ts.map +1 -1
  135. package/lib/typescript/commonjs/src/types/MapLibreRNStyles.d.ts +1 -1
  136. package/lib/typescript/commonjs/src/types/MapLibreRNStyles.d.ts.map +1 -1
  137. package/lib/typescript/commonjs/src/types/PressEvent.d.ts +0 -3
  138. package/lib/typescript/commonjs/src/types/PressEvent.d.ts.map +1 -1
  139. package/lib/typescript/commonjs/src/types/PressEventWithFeatures.d.ts +5 -0
  140. package/lib/typescript/commonjs/src/types/PressEventWithFeatures.d.ts.map +1 -0
  141. package/lib/typescript/commonjs/src/utils/animated/AbstractAnimatedCoordinates.d.ts.map +1 -1
  142. package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts +4 -1
  143. package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts.map +1 -1
  144. package/lib/typescript/commonjs/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts.map +1 -1
  145. package/lib/typescript/commonjs/src/utils/animated/AnimatedPoint.d.ts.map +1 -1
  146. package/lib/typescript/commonjs/src/utils/animated/AnimatedRouteCoordinatesArray.d.ts.map +1 -1
  147. package/lib/typescript/commonjs/src/utils/animated/AnimatedShape.d.ts +2 -2
  148. package/lib/typescript/commonjs/src/utils/animated/AnimatedShape.d.ts.map +1 -1
  149. package/lib/typescript/commonjs/src/utils/findNodeHandle.d.ts +3 -0
  150. package/lib/typescript/commonjs/src/utils/findNodeHandle.d.ts.map +1 -0
  151. package/lib/typescript/commonjs/src/utils/{filterUtils.d.ts → getFilter.d.ts} +2 -2
  152. package/lib/typescript/commonjs/src/utils/getFilter.d.ts.map +1 -0
  153. package/lib/typescript/commonjs/src/utils/index.d.ts +3 -3
  154. package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
  155. package/lib/typescript/module/src/components/annotations/Annotation.d.ts +1 -1
  156. package/lib/typescript/module/src/components/annotations/Annotation.d.ts.map +1 -1
  157. package/lib/typescript/module/src/components/layers/BackgroundLayer.d.ts.map +1 -1
  158. package/lib/typescript/module/src/components/layers/CircleLayer.d.ts.map +1 -1
  159. package/lib/typescript/module/src/components/layers/FillExtrusionLayer.d.ts.map +1 -1
  160. package/lib/typescript/module/src/components/layers/HeatmapLayer.d.ts.map +1 -1
  161. package/lib/typescript/module/src/components/layers/RasterLayer.d.ts.map +1 -1
  162. package/lib/typescript/module/src/components/layers/SymbolLayer.d.ts.map +1 -1
  163. package/lib/typescript/module/src/components/map-view/MapView.d.ts.map +1 -1
  164. package/lib/typescript/module/src/components/sources/VectorSource.d.ts +1 -1
  165. package/lib/typescript/module/src/components/sources/VectorSource.d.ts.map +1 -1
  166. package/lib/typescript/module/src/components/sources/shape-source/NativeShapeSourceModule.d.ts +10 -0
  167. package/lib/typescript/module/src/components/sources/shape-source/NativeShapeSourceModule.d.ts.map +1 -0
  168. package/lib/typescript/{commonjs/src/components/sources → module/src/components/sources/shape-source}/ShapeSource.d.ts +60 -41
  169. package/lib/typescript/module/src/components/sources/shape-source/ShapeSource.d.ts.map +1 -0
  170. package/lib/typescript/module/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts +35 -0
  171. package/lib/typescript/module/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts.map +1 -0
  172. package/lib/typescript/module/src/hooks/useFrozenId.d.ts +2 -0
  173. package/lib/typescript/module/src/hooks/useFrozenId.d.ts.map +1 -0
  174. package/lib/typescript/module/src/index.d.ts +4 -3
  175. package/lib/typescript/module/src/index.d.ts.map +1 -1
  176. package/lib/typescript/module/src/modules/snapshot/SnapshotOptions.d.ts.map +1 -1
  177. package/lib/typescript/module/src/types/MapLibreRNStyles.d.ts +1 -1
  178. package/lib/typescript/module/src/types/MapLibreRNStyles.d.ts.map +1 -1
  179. package/lib/typescript/module/src/types/PressEvent.d.ts +0 -3
  180. package/lib/typescript/module/src/types/PressEvent.d.ts.map +1 -1
  181. package/lib/typescript/module/src/types/PressEventWithFeatures.d.ts +5 -0
  182. package/lib/typescript/module/src/types/PressEventWithFeatures.d.ts.map +1 -0
  183. package/lib/typescript/module/src/utils/animated/AbstractAnimatedCoordinates.d.ts.map +1 -1
  184. package/lib/typescript/module/src/utils/animated/Animated.d.ts +4 -1
  185. package/lib/typescript/module/src/utils/animated/Animated.d.ts.map +1 -1
  186. package/lib/typescript/module/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts.map +1 -1
  187. package/lib/typescript/module/src/utils/animated/AnimatedPoint.d.ts.map +1 -1
  188. package/lib/typescript/module/src/utils/animated/AnimatedRouteCoordinatesArray.d.ts.map +1 -1
  189. package/lib/typescript/module/src/utils/animated/AnimatedShape.d.ts +2 -2
  190. package/lib/typescript/module/src/utils/animated/AnimatedShape.d.ts.map +1 -1
  191. package/lib/typescript/module/src/utils/findNodeHandle.d.ts +3 -0
  192. package/lib/typescript/module/src/utils/findNodeHandle.d.ts.map +1 -0
  193. package/lib/typescript/module/src/utils/{filterUtils.d.ts → getFilter.d.ts} +2 -2
  194. package/lib/typescript/module/src/utils/getFilter.d.ts.map +1 -0
  195. package/lib/typescript/module/src/utils/index.d.ts +3 -3
  196. package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
  197. package/package.json +7 -6
  198. package/src/components/annotations/Annotation.tsx +2 -2
  199. package/src/components/layers/BackgroundLayer.tsx +1 -2
  200. package/src/components/layers/CircleLayer.tsx +1 -2
  201. package/src/components/layers/FillExtrusionLayer.tsx +1 -2
  202. package/src/components/layers/HeatmapLayer.tsx +1 -2
  203. package/src/components/layers/RasterLayer.tsx +1 -2
  204. package/src/components/layers/SymbolLayer.tsx +1 -2
  205. package/src/components/map-view/MapView.tsx +2 -14
  206. package/src/components/sources/VectorSource.tsx +2 -2
  207. package/src/components/sources/shape-source/NativeShapeSourceModule.ts +31 -0
  208. package/src/components/sources/shape-source/ShapeSource.tsx +235 -0
  209. package/src/components/sources/shape-source/ShapeSourceNativeComponent.ts +48 -0
  210. package/src/hooks/useAbstractLayer.ts +1 -1
  211. package/src/hooks/useFrozenId.ts +13 -0
  212. package/src/index.ts +4 -3
  213. package/src/modules/snapshot/SnapshotOptions.ts +3 -2
  214. package/src/types/MapLibreRNStyles.ts +1 -1
  215. package/src/types/PressEvent.ts +0 -4
  216. package/src/types/PressEventWithFeatures.ts +5 -0
  217. package/src/utils/animated/AbstractAnimatedCoordinates.ts +0 -9
  218. package/src/utils/animated/Animated.ts +12 -5
  219. package/src/utils/animated/AnimatedExtractCoordinateFromArray.ts +0 -9
  220. package/src/utils/animated/AnimatedPoint.ts +0 -2
  221. package/src/utils/animated/AnimatedRouteCoordinatesArray.ts +3 -3
  222. package/src/utils/animated/AnimatedShape.ts +7 -18
  223. package/src/utils/findNodeHandle.ts +14 -0
  224. package/src/utils/{filterUtils.ts → getFilter.ts} +2 -2
  225. package/src/utils/index.ts +12 -12
  226. package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNShapeSource.java +0 -248
  227. package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNShapeSourceManager.java +0 -216
  228. package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNSource.java +0 -240
  229. package/android/src/main/java/org/maplibre/reactnative/utils/ClusterPropertyEntry.java +0 -13
  230. package/android/src/main/java/org/maplibre/reactnative/utils/ConvertUtils.java +0 -246
  231. package/android/src/main/java/org/maplibre/reactnative/utils/ExpressionParser.java +0 -74
  232. package/ios/components/sources/MLRNShapeSourceManager.h +0 -6
  233. package/ios/components/sources/MLRNShapeSourceManager.m +0 -128
  234. package/lib/commonjs/components/sources/ShapeSource.js +0 -153
  235. package/lib/commonjs/components/sources/ShapeSource.js.map +0 -1
  236. package/lib/commonjs/utils/filterUtils.js.map +0 -1
  237. package/lib/module/components/sources/ShapeSource.js +0 -149
  238. package/lib/module/components/sources/ShapeSource.js.map +0 -1
  239. package/lib/module/utils/filterUtils.js +0 -9
  240. package/lib/module/utils/filterUtils.js.map +0 -1
  241. package/lib/typescript/commonjs/src/components/sources/ShapeSource.d.ts.map +0 -1
  242. package/lib/typescript/commonjs/src/utils/filterUtils.d.ts.map +0 -1
  243. package/lib/typescript/module/src/components/sources/ShapeSource.d.ts.map +0 -1
  244. package/lib/typescript/module/src/utils/filterUtils.d.ts.map +0 -1
  245. package/src/components/sources/ShapeSource.tsx +0 -366
@@ -0,0 +1,183 @@
1
+ package org.maplibre.reactnative.components.sources.shapesource
2
+
3
+ import android.util.Log
4
+ import android.view.View
5
+ import com.facebook.react.bridge.Dynamic
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.bridge.ReadableMap
8
+ import com.facebook.react.bridge.ReadableType
9
+ import com.facebook.react.module.annotations.ReactModule
10
+ import com.facebook.react.uimanager.ThemedReactContext
11
+ import com.facebook.react.uimanager.ViewGroupManager
12
+ import com.facebook.react.uimanager.ViewManagerDelegate
13
+ import com.facebook.react.uimanager.annotations.ReactProp
14
+ import com.facebook.react.viewmanagers.MLRNShapeSourceManagerDelegate
15
+ import com.facebook.react.viewmanagers.MLRNShapeSourceManagerInterface
16
+ import org.json.JSONException
17
+ import org.json.JSONObject
18
+ import org.maplibre.android.style.expressions.Expression
19
+ import org.maplibre.reactnative.utils.ExpressionParser
20
+ import java.net.MalformedURLException
21
+ import java.net.URI
22
+ import java.util.AbstractMap
23
+
24
+ @ReactModule(name = MLRNShapeSourceManager.REACT_CLASS)
25
+ class MLRNShapeSourceManager(context: ReactApplicationContext) :
26
+ ViewGroupManager<MLRNShapeSource>(context), MLRNShapeSourceManagerInterface<MLRNShapeSource> {
27
+
28
+
29
+ private val delegate: MLRNShapeSourceManagerDelegate<MLRNShapeSource, MLRNShapeSourceManager> =
30
+ MLRNShapeSourceManagerDelegate(this)
31
+
32
+ override fun getDelegate(): ViewManagerDelegate<MLRNShapeSource> = delegate
33
+
34
+
35
+ companion object {
36
+ const val REACT_CLASS: String = "MLRNShapeSource"
37
+ const val LOG_TAG: String = "MLRNShapeSourceManager"
38
+ }
39
+
40
+ override fun getName(): String = REACT_CLASS
41
+
42
+ override fun createViewInstance(themedReactContext: ThemedReactContext): MLRNShapeSource {
43
+ return MLRNShapeSource(themedReactContext)
44
+ }
45
+
46
+ override fun getChildAt(parent: MLRNShapeSource, index: Int): View? {
47
+ return parent.getLayerAt(index)
48
+ }
49
+
50
+ override fun getChildCount(parent: MLRNShapeSource): Int {
51
+ return parent.layerCount
52
+ }
53
+
54
+ override fun addView(parent: MLRNShapeSource, child: View, index: Int) {
55
+ parent.addLayer(child, getChildCount(parent))
56
+ }
57
+
58
+ override fun removeViewAt(parent: MLRNShapeSource, index: Int) {
59
+ parent.removeLayer(index)
60
+ }
61
+
62
+ // TODO: Strings are nullable?
63
+ @ReactProp(name = "id")
64
+ override fun setId(source: MLRNShapeSource, id: String?) {
65
+ if (id == null) {
66
+ return
67
+ }
68
+
69
+ source.setID(id)
70
+ }
71
+
72
+ fun isJSONValid(test: String): Boolean {
73
+ try {
74
+ JSONObject(test)
75
+ } catch (_: JSONException) {
76
+ return false
77
+ }
78
+ return true
79
+ }
80
+
81
+
82
+ @ReactProp(name = "data")
83
+ override fun setData(source: MLRNShapeSource, value: String?) {
84
+ if (value != null) {
85
+ if (isJSONValid(value)) {
86
+ source.setGeoJson(value)
87
+ } else {
88
+ try {
89
+ source.setURI(URI(value))
90
+ } catch (error: MalformedURLException) {
91
+ Log.w(LOG_TAG, error.localizedMessage)
92
+ }
93
+ }
94
+ }
95
+ }
96
+
97
+ @ReactProp(name = "maxzoom")
98
+ override fun setMaxzoom(source: MLRNShapeSource, value: Int) {
99
+ source.setMaxZoom(if (value != -1) value else null)
100
+ }
101
+
102
+ @ReactProp(name = "buffer")
103
+ override fun setBuffer(source: MLRNShapeSource, value: Int) {
104
+ source.setBuffer(if (value != -1) value else null)
105
+ }
106
+
107
+ @ReactProp(name = "tolerance")
108
+ override fun setTolerance(source: MLRNShapeSource, value: Double) {
109
+ source.setTolerance(if (value.toInt() != -1) value else null)
110
+ }
111
+
112
+ @ReactProp(name = "lineMetrics")
113
+ override fun setLineMetrics(source: MLRNShapeSource, lineMetrics: Boolean) {
114
+ source.setLineMetrics(lineMetrics)
115
+ }
116
+
117
+
118
+ @ReactProp(name = "cluster")
119
+ override fun setCluster(source: MLRNShapeSource, value: Boolean) {
120
+ source.setCluster(value)
121
+ }
122
+
123
+ @ReactProp(name = "clusterRadius")
124
+ override fun setClusterRadius(source: MLRNShapeSource, value: Int) {
125
+ source.setClusterRadius(if (value != -1) value else null)
126
+ }
127
+
128
+ @ReactProp(name = "clusterMinPoints")
129
+ override fun setClusterMinPoints(source: MLRNShapeSource, value: Int) {
130
+ source.setClusterMinPoints(if (value != -1) value else null)
131
+ }
132
+
133
+ @ReactProp(name = "clusterMaxZoom")
134
+ override fun setClusterMaxZoom(source: MLRNShapeSource, value: Int) {
135
+ source.setClusterMaxZoom(if (value != -1) value else null)
136
+ }
137
+
138
+ @ReactProp(name = "clusterProperties")
139
+ override fun setClusterProperties(source: MLRNShapeSource, value: Dynamic) {
140
+ val map = value.asMap();
141
+ val properties: MutableList<MutableMap.MutableEntry<String, ClusterPropertyEntry>> =
142
+ ArrayList()
143
+
144
+ if (map != null) {
145
+ val iterator = map.keySetIterator()
146
+ while (iterator.hasNextKey()) {
147
+ val name = iterator.nextKey()
148
+ val expressions = map.getArray(name)
149
+
150
+ val operator: Expression? = if (expressions!!.getType(0) == ReadableType.Array) {
151
+ ExpressionParser.from(expressions.getArray(0))
152
+ } else {
153
+ Expression.literal(expressions.getString(0)!!)
154
+ }
155
+
156
+ val mapping = ExpressionParser.from(expressions.getArray(1))
157
+
158
+ // TODO: Throw error instead?
159
+ if (operator != null && mapping != null) {
160
+ properties.add(
161
+ AbstractMap.SimpleEntry<String, ClusterPropertyEntry>(
162
+ name, ClusterPropertyEntry(operator, mapping)
163
+ )
164
+ )
165
+ }
166
+ }
167
+ }
168
+
169
+ source.setClusterProperties(properties)
170
+ }
171
+
172
+ @ReactProp(name = "hitbox")
173
+ override fun setHitbox(
174
+ view: MLRNShapeSource, value: ReadableMap?
175
+ ) {
176
+ view.setReactHitbox(value)
177
+ }
178
+
179
+ @ReactProp(name = "hasOnPress")
180
+ override fun setHasOnPress(view: MLRNShapeSource, value: Boolean) {
181
+ view.setHasOnPress(value)
182
+ }
183
+ }
@@ -0,0 +1,65 @@
1
+ package org.maplibre.reactnative.components.sources.shapesource
2
+
3
+ import com.facebook.react.bridge.Promise
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.bridge.ReadableArray
6
+ import com.facebook.react.module.annotations.ReactModule
7
+ import org.maplibre.reactnative.NativeShapeSourceModuleSpec
8
+ import org.maplibre.reactnative.utils.ExpressionParser
9
+ import org.maplibre.reactnative.utils.ReactTag
10
+ import org.maplibre.reactnative.utils.ReactTagResolver
11
+
12
+ @ReactModule(name = NativeShapeSourceModuleSpec.NAME)
13
+ class MLRNShapeSourceModule(
14
+ reactContext: ReactApplicationContext, private val reactTagResolver: ReactTagResolver
15
+ ) : NativeShapeSourceModuleSpec(reactContext) {
16
+ companion object {
17
+ const val NAME = "MLRNShapeSourceModule"
18
+ }
19
+
20
+ private fun withViewportOnUIThread(
21
+ reactTag: ReactTag, promise: Promise, fn: (MLRNShapeSource) -> Unit
22
+ ) {
23
+ reactTagResolver.withViewResolved(reactTag.toInt(), promise, fn)
24
+ }
25
+
26
+ override fun getData(
27
+ reactTag: Double, filter: ReadableArray?, promise: Promise
28
+ ) {
29
+ withViewportOnUIThread(reactTag, promise) { shapeSource ->
30
+ promise.resolve(
31
+ shapeSource.getData(
32
+ ExpressionParser.from(filter),
33
+ )
34
+ )
35
+ }
36
+ }
37
+
38
+ override fun getClusterExpansionZoom(reactTag: Double, clusterId: Double, promise: Promise) {
39
+ withViewportOnUIThread(reactTag, promise) {
40
+ promise.resolve(it.getClusterExpansionZoom(clusterId.toInt()))
41
+ }
42
+ }
43
+
44
+ override fun getClusterLeaves(
45
+ reactTag: Double,
46
+ clusterId: Double,
47
+ limit: Double,
48
+ offset: Double,
49
+ promise: Promise
50
+ ) {
51
+ withViewportOnUIThread(reactTag, promise) {
52
+ promise.resolve(it.getClusterLeaves(clusterId.toInt(), limit.toInt(), offset.toInt()))
53
+ }
54
+ }
55
+
56
+ override fun getClusterChildren(
57
+ reactTag: Double,
58
+ clusterId: Double,
59
+ promise: Promise
60
+ ) {
61
+ withViewportOnUIThread(reactTag, promise) {
62
+ promise.resolve(it.getClusterChildren(clusterId.toInt()))
63
+ }
64
+ }
65
+ }
@@ -7,7 +7,7 @@ import com.facebook.react.uimanager.events.Event
7
7
  import org.maplibre.android.geometry.LatLng
8
8
  import org.maplibre.reactnative.utils.GeoJSONUtils
9
9
 
10
- class MapPressEvent(
10
+ open class MapPressEvent(
11
11
  surfaceId: Int,
12
12
  viewId: Int,
13
13
  private val internalEventName: String,
@@ -0,0 +1,24 @@
1
+ package org.maplibre.reactnative.events
2
+
3
+ import android.graphics.PointF
4
+ import com.facebook.react.bridge.WritableMap
5
+ import org.maplibre.android.geometry.LatLng
6
+ import org.maplibre.geojson.Feature
7
+ import org.maplibre.reactnative.utils.GeoJSONUtils
8
+
9
+ class MapPressEventWithFeatures(
10
+ surfaceId: Int,
11
+ viewId: Int,
12
+ internalEventName: String,
13
+ latLng: LatLng,
14
+ screenPoint: PointF,
15
+ private val features: List<Feature>
16
+ ) : MapPressEvent(surfaceId, viewId, internalEventName, latLng, screenPoint) {
17
+
18
+ override fun getEventData(): WritableMap {
19
+ return super.getEventData().apply {
20
+ putArray("features", GeoJSONUtils.fromFeatureList(features))
21
+ }
22
+ }
23
+ }
24
+
@@ -0,0 +1,203 @@
1
+ package org.maplibre.reactnative.utils
2
+
3
+ import android.graphics.PointF
4
+ import android.util.Log
5
+ import com.facebook.react.bridge.Arguments
6
+ import com.facebook.react.bridge.NoSuchKeyException
7
+ import com.facebook.react.bridge.ReadableArray
8
+ import com.facebook.react.bridge.ReadableMap
9
+ import com.facebook.react.bridge.ReadableType
10
+ import com.facebook.react.bridge.WritableArray
11
+ import com.facebook.react.bridge.WritableMap
12
+ import com.google.gson.JsonArray
13
+ import com.google.gson.JsonElement
14
+ import com.google.gson.JsonObject
15
+ import com.google.gson.JsonPrimitive
16
+
17
+ object ConvertUtils {
18
+ const val LOG_TAG: String = "ConvertUtils"
19
+
20
+ fun toJsonObject(map: ReadableMap?): JsonObject? {
21
+ if (map == null) return null
22
+ val result = JsonObject()
23
+ val it = map.keySetIterator()
24
+
25
+ while (it.hasNextKey()) {
26
+ val key = it.nextKey()
27
+ when (map.getType(key)) {
28
+ ReadableType.Map -> result.add(key, toJsonObject(map.getMap(key)))
29
+ ReadableType.Array -> result.add(key, toJsonArray(map.getArray(key)))
30
+ ReadableType.Null -> result.add(key, null)
31
+ ReadableType.Number -> result.addProperty(key, map.getDouble(key))
32
+ ReadableType.String -> result.addProperty(key, map.getString(key))
33
+ ReadableType.Boolean -> result.addProperty(key, map.getBoolean(key))
34
+ }
35
+ }
36
+ return result
37
+ }
38
+
39
+ @JvmStatic
40
+ fun toJsonArray(array: ReadableArray?): JsonArray? {
41
+ if (array == null) return null
42
+ val result = JsonArray(array.size())
43
+ for (i in 0..<array.size()) {
44
+ when (array.getType(i)) {
45
+ ReadableType.Map -> result.add(toJsonObject(array.getMap(i)))
46
+ ReadableType.Array -> result.add(toJsonArray(array.getArray(i)))
47
+ ReadableType.Null -> result.add(null as JsonElement?)
48
+ ReadableType.Number -> result.add(array.getDouble(i))
49
+ ReadableType.String -> result.add(array.getString(i))
50
+ ReadableType.Boolean -> result.add(array.getBoolean(i))
51
+ }
52
+ }
53
+ return result
54
+ }
55
+
56
+ @JvmStatic
57
+ fun typedToJsonElement(map: ReadableMap?): JsonElement? {
58
+ if (map == null) return null
59
+
60
+ val type = map.getString("type")
61
+
62
+ when (type) {
63
+ ExpressionParser.TYPE_MAP -> {
64
+ val result = JsonObject()
65
+
66
+ val keyValues = map.getArray("value")
67
+ for (i in 0..<keyValues!!.size()) {
68
+ val keyValue = keyValues.getArray(i)
69
+ val key = keyValue!!.getMap(0)!!.getString("value")
70
+
71
+ result.add(key, typedToJsonElement(keyValue.getMap(1)))
72
+ }
73
+ return result
74
+ }
75
+ ExpressionParser.TYPE_ARRAY -> {
76
+ val arrayValue = map.getArray("value")
77
+ val result = JsonArray(arrayValue!!.size())
78
+ for (i in 0..<arrayValue.size()) {
79
+ result.add(typedToJsonElement(arrayValue.getMap(i)))
80
+ }
81
+ return result
82
+ }
83
+ ExpressionParser.TYPE_BOOL -> {
84
+ return JsonPrimitive(map.getBoolean("value"))
85
+ }
86
+ ExpressionParser.TYPE_NUMBER -> {
87
+ return JsonPrimitive(map.getDouble("value"))
88
+ }
89
+ ExpressionParser.TYPE_STRING -> {
90
+ return JsonPrimitive(map.getString("value"))
91
+ }
92
+ else -> {
93
+ throw RuntimeException(String.format("Unrecognized type {}", map.getString("type")))
94
+ }
95
+ }
96
+ }
97
+
98
+ fun toWritableArray(array: JsonArray): WritableArray {
99
+ val writableArray = Arguments.createArray()
100
+
101
+ for (i in 0..<array.size()) {
102
+ val element = array.get(i)
103
+
104
+ if (element.isJsonArray) {
105
+ writableArray.pushArray(toWritableArray(element.getAsJsonArray()))
106
+ } else if (element.isJsonObject) {
107
+ writableArray.pushMap(toWritableMap(element.getAsJsonObject()))
108
+ } else if (element.isJsonPrimitive) {
109
+ val primitive = element.getAsJsonPrimitive()
110
+
111
+ if (primitive.isBoolean) {
112
+ writableArray.pushBoolean(primitive.getAsBoolean())
113
+ } else if (primitive.isNumber) {
114
+ writableArray.pushDouble(primitive.asDouble)
115
+ } else {
116
+ writableArray.pushString(primitive.getAsString())
117
+ }
118
+ }
119
+ }
120
+
121
+ return writableArray
122
+ }
123
+
124
+ fun toWritableMap(`object`: JsonObject): WritableMap {
125
+ val map = Arguments.createMap()
126
+
127
+ for (entry in `object`.entrySet()) {
128
+ val propName = entry.key
129
+ val jsonElement = entry.value
130
+
131
+ if (jsonElement.isJsonPrimitive) {
132
+ val primitive = jsonElement.getAsJsonPrimitive()
133
+
134
+ if (primitive.isBoolean) {
135
+ map.putBoolean(propName, primitive.getAsBoolean())
136
+ } else if (primitive.isNumber) {
137
+ map.putDouble(propName, primitive.asDouble)
138
+ } else {
139
+ map.putString(propName, primitive.getAsString())
140
+ }
141
+ } else if (jsonElement.isJsonArray) {
142
+ map.putArray(propName, toWritableArray(jsonElement.getAsJsonArray()))
143
+ } else if (jsonElement.isJsonObject) {
144
+ map.putMap(propName, toWritableMap(jsonElement.getAsJsonObject()))
145
+ }
146
+ }
147
+
148
+ return map
149
+ }
150
+
151
+ @JvmStatic
152
+ fun toStringList(array: ReadableArray?): MutableList<String?> {
153
+ val list: MutableList<String?> = ArrayList()
154
+
155
+ if (array == null) {
156
+ return list
157
+ }
158
+
159
+ for (i in 0..<array.size()) {
160
+ list.add(array.getString(i))
161
+ }
162
+
163
+ return list
164
+ }
165
+
166
+ fun toPointF(map: ReadableArray): PointF {
167
+ return PointF(map.getDouble(0).toFloat(), map.getDouble(1).toFloat())
168
+ }
169
+
170
+ @JvmStatic
171
+ fun getDouble(key: String, map: ReadableMap, defaultValue: Double): Double {
172
+ var value = defaultValue
173
+
174
+ try {
175
+ value = map.getDouble(key)
176
+ } catch (_: NoSuchKeyException) {
177
+ // key not found use default value
178
+ Log.d(
179
+ LOG_TAG,
180
+ String.format("No key found for %s, using default value %f", key, defaultValue)
181
+ )
182
+ }
183
+
184
+ return value
185
+ }
186
+
187
+ @JvmStatic
188
+ fun getString(key: String, map: ReadableMap, defaultValue: String?): String? {
189
+ var value = defaultValue
190
+
191
+ try {
192
+ value = map.getString(key)
193
+ } catch (_: NoSuchKeyException) {
194
+ // key not found use default value
195
+ Log.d(
196
+ LOG_TAG,
197
+ String.format("No key found for %s, using default value %s", key, defaultValue)
198
+ )
199
+ }
200
+
201
+ return value
202
+ }
203
+ }
@@ -0,0 +1,70 @@
1
+ package org.maplibre.reactnative.utils
2
+
3
+ import com.facebook.react.bridge.ReadableArray
4
+ import com.facebook.react.bridge.ReadableMap
5
+ import com.google.gson.JsonArray
6
+ import org.maplibre.android.style.expressions.Expression
7
+ import org.maplibre.reactnative.utils.ConvertUtils.toJsonArray
8
+ import org.maplibre.reactnative.utils.ConvertUtils.typedToJsonElement
9
+ import java.util.Locale
10
+
11
+ object ExpressionParser {
12
+ const val TYPE_STRING: String = "string"
13
+ const val TYPE_ARRAY: String = "array"
14
+ const val TYPE_NUMBER: String = "number"
15
+ const val TYPE_MAP: String = "hashmap"
16
+ const val TYPE_BOOL: String = "boolean"
17
+
18
+ @JvmStatic
19
+ fun from(rawExpressions: ReadableArray?): Expression? {
20
+ if (rawExpressions == null || rawExpressions.size() == 0) {
21
+ return null
22
+ }
23
+
24
+ return Expression.Converter.convert(toJsonArray(rawExpressions)!!)
25
+ }
26
+
27
+ @JvmStatic
28
+ fun fromTyped(rawExpressions: ReadableMap?): Expression {
29
+ val array = typedToJsonElement(rawExpressions) as JsonArray?
30
+ return Expression.Converter.convert(array!!)
31
+ }
32
+
33
+
34
+ fun from(rawExpression: ReadableMap): Expression? {
35
+ return Expression.raw("[" + stringExpression(rawExpression) + "]")
36
+ }
37
+
38
+ private fun stringExpression(item: ReadableMap): String {
39
+ var expression = ""
40
+ val type = item.getString("type")
41
+
42
+ if (TYPE_STRING == type) {
43
+ val value = item.getString("value")
44
+ expression = String.format(Locale.ENGLISH, "\"%s\"", value)
45
+ } else if (TYPE_NUMBER == type) {
46
+ val value = item.getDouble("value")
47
+ expression = String.format(Locale.ENGLISH, "%f", value)
48
+ } else if (TYPE_BOOL == type) {
49
+ val value = item.getBoolean("value")
50
+ expression = String.format(Locale.ENGLISH, "%b", value)
51
+ } else if (TYPE_ARRAY == type) {
52
+ val entries = item.getArray("value")
53
+
54
+ expression += "["
55
+
56
+ for (i in 0..<entries!!.size()) {
57
+ val entryExpression = stringExpression(entries.getMap(i)!!)
58
+ expression += entryExpression
59
+
60
+ if (i < entries.size() - 1) {
61
+ expression += ","
62
+ }
63
+ }
64
+
65
+ expression += "]"
66
+ }
67
+
68
+ return expression
69
+ }
70
+ }
@@ -4,8 +4,6 @@ import com.facebook.react.bridge.Arguments
4
4
  import com.facebook.react.bridge.ReadableArray
5
5
  import com.facebook.react.bridge.WritableArray
6
6
  import com.facebook.react.bridge.WritableMap
7
- import com.facebook.react.bridge.WritableNativeArray
8
- import com.facebook.react.bridge.WritableNativeMap
9
7
  import org.maplibre.android.geometry.LatLng
10
8
  import org.maplibre.android.geometry.LatLngBounds
11
9
  import org.maplibre.android.geometry.LatLngQuad
@@ -49,10 +47,26 @@ object GeoJSONUtils {
49
47
  return map
50
48
  }
51
49
 
52
- fun fromGeometry(geometry: Geometry): WritableMap? {
53
- val type = geometry.type()
50
+ fun fromFeatureCollection(featureCollection: FeatureCollection): WritableMap {
51
+ val map = Arguments.createMap()
52
+ map.putString("type", "FeatureCollection")
53
+
54
+ map.putArray("features", fromFeatureList(featureCollection.features() ?: emptyList()))
55
+
56
+ return map
57
+ }
58
+
59
+ fun fromFeatureList(featureList: List<Feature>): WritableArray {
60
+ val featuresArray = Arguments.createArray()
61
+ featureList.forEach { feature ->
62
+ featuresArray.pushMap(fromFeature(feature))
63
+ }
64
+
65
+ return featuresArray
66
+ }
54
67
 
55
- return when (type) {
68
+ fun fromGeometry(geometry: Geometry): WritableMap? {
69
+ return when (val type = geometry.type()) {
56
70
  "Point" -> fromPoint(geometry as Point)
57
71
  "LineString" -> fromLineString(geometry as LineString)
58
72
  "Polygon" -> fromPolygon(geometry as Polygon)
@@ -210,25 +224,30 @@ object GeoJSONUtils {
210
224
 
211
225
  @JvmStatic
212
226
  fun toPointFeature(latLng: LatLng, properties: WritableMap?): WritableMap {
213
- val map: WritableMap = WritableNativeMap()
214
- map.putString("type", "Feature")
215
- map.putMap("geometry", toPointGeometry(latLng))
216
- map.putMap("properties", properties)
227
+ val map: WritableMap = Arguments.createMap().apply {
228
+ putString("type", "Feature")
229
+ putMap("geometry", toPointGeometry(latLng))
230
+ putMap("properties", properties)
231
+ }
232
+
217
233
  return map
218
234
  }
219
235
 
220
236
  fun toPointGeometry(latLng: LatLng): WritableMap {
221
- val geometry: WritableMap = WritableNativeMap()
222
- geometry.putString("type", "Point")
223
- geometry.putArray("coordinates", fromLatLng(latLng))
237
+ val geometry: WritableMap = Arguments.createMap().apply {
238
+ putString("type", "Point")
239
+ putArray("coordinates", fromLatLng(latLng))
240
+ }
241
+
224
242
  return geometry
225
243
  }
226
244
 
227
245
  @JvmStatic
228
246
  fun fromLatLng(latLng: LatLng): WritableArray {
229
- val coordinates: WritableArray = WritableNativeArray()
230
- coordinates.pushDouble(latLng.longitude)
231
- coordinates.pushDouble(latLng.latitude)
247
+ val coordinates: WritableArray = Arguments.createArray().apply {
248
+ pushDouble(latLng.longitude)
249
+ pushDouble(latLng.latitude)
250
+ }
232
251
 
233
252
  return coordinates
234
253
  }
@@ -250,10 +269,8 @@ object GeoJSONUtils {
250
269
 
251
270
  @JvmStatic
252
271
  fun toPointGeometry(featureJSONString: String): Point? {
253
- val feature = Feature.fromJson(featureJSONString)
254
- if (feature == null) {
255
- return null
256
- }
272
+ val feature = Feature.fromJson(featureJSONString) ?: return null
273
+
257
274
  return feature.geometry() as Point?
258
275
  }
259
276
 
@@ -294,7 +311,7 @@ object GeoJSONUtils {
294
311
  )
295
312
  }
296
313
 
297
- return null;
314
+ return null
298
315
  }
299
316
 
300
317
  @JvmStatic