@maplibre/maplibre-react-native 11.0.0-alpha.26 → 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 (243) hide show
  1. package/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +16 -1
  2. package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.kt +20 -32
  3. package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNRasterSource.java +1 -1
  4. package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNSource.kt +228 -0
  5. package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNTileSource.java +0 -1
  6. package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNVectorSourceManager.java +2 -2
  7. package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/ClusterPropertyEntry.kt +5 -0
  8. package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/MLRNShapeSource.kt +232 -0
  9. package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/MLRNShapeSourceManager.kt +183 -0
  10. package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/MLRNShapeSourceModule.kt +65 -0
  11. package/android/src/main/java/org/maplibre/reactnative/events/MapPressEvent.kt +1 -1
  12. package/android/src/main/java/org/maplibre/reactnative/events/MapPressEventWithFeatures.kt +24 -0
  13. package/android/src/main/java/org/maplibre/reactnative/utils/ConvertUtils.kt +203 -0
  14. package/android/src/main/java/org/maplibre/reactnative/utils/ExpressionParser.kt +70 -0
  15. package/android/src/main/java/org/maplibre/reactnative/utils/GeoJSONUtils.kt +37 -20
  16. package/ios/components/camera/MLRNCameraModule.mm +10 -20
  17. package/ios/components/map-view/MLRNMapViewModule.mm +10 -20
  18. package/ios/components/sources/MLRNSource.h +3 -0
  19. package/ios/components/sources/{MLRNShapeSource.h → shape-source/MLRNShapeSource.h} +3 -5
  20. package/ios/components/sources/{MLRNShapeSource.m → shape-source/MLRNShapeSource.m} +4 -12
  21. package/ios/components/sources/shape-source/MLRNShapeSourceComponentView.h +11 -0
  22. package/ios/components/sources/shape-source/MLRNShapeSourceComponentView.mm +163 -0
  23. package/ios/components/sources/shape-source/MLRNShapeSourceModule.h +5 -0
  24. package/ios/components/sources/shape-source/MLRNShapeSourceModule.mm +136 -0
  25. package/ios/utils/MLRNViewModuleUtils.h +35 -0
  26. package/ios/utils/MLRNViewModuleUtils.m +39 -0
  27. package/lib/commonjs/components/annotations/Annotation.js +1 -1
  28. package/lib/commonjs/components/annotations/Annotation.js.map +1 -1
  29. package/lib/commonjs/components/layers/BackgroundLayer.js.map +1 -1
  30. package/lib/commonjs/components/layers/CircleLayer.js.map +1 -1
  31. package/lib/commonjs/components/layers/FillExtrusionLayer.js.map +1 -1
  32. package/lib/commonjs/components/layers/HeatmapLayer.js.map +1 -1
  33. package/lib/commonjs/components/layers/RasterLayer.js.map +1 -1
  34. package/lib/commonjs/components/layers/SymbolLayer.js.map +1 -1
  35. package/lib/commonjs/components/map-view/MapView.js +16 -22
  36. package/lib/commonjs/components/map-view/MapView.js.map +1 -1
  37. package/lib/commonjs/components/sources/VectorSource.js +2 -2
  38. package/lib/commonjs/components/sources/VectorSource.js.map +1 -1
  39. package/lib/commonjs/components/sources/shape-source/NativeShapeSourceModule.js +9 -0
  40. package/lib/commonjs/components/sources/shape-source/NativeShapeSourceModule.js.map +1 -0
  41. package/lib/commonjs/components/sources/shape-source/ShapeSource.js +51 -0
  42. package/lib/commonjs/components/sources/shape-source/ShapeSource.js.map +1 -0
  43. package/lib/commonjs/components/sources/shape-source/ShapeSourceNativeComponent.ts +48 -0
  44. package/lib/commonjs/hooks/useAbstractLayer.js +2 -2
  45. package/lib/commonjs/hooks/useAbstractLayer.js.map +1 -1
  46. package/lib/commonjs/hooks/useFrozenId.js +16 -0
  47. package/lib/commonjs/hooks/useFrozenId.js.map +1 -0
  48. package/lib/commonjs/index.js +1 -1
  49. package/lib/commonjs/index.js.map +1 -1
  50. package/lib/commonjs/modules/snapshot/SnapshotOptions.js.map +1 -1
  51. package/lib/commonjs/types/PressEventWithFeatures.js +6 -0
  52. package/lib/commonjs/types/PressEventWithFeatures.js.map +1 -0
  53. package/lib/commonjs/utils/animated/AbstractAnimatedCoordinates.js +0 -6
  54. package/lib/commonjs/utils/animated/AbstractAnimatedCoordinates.js.map +1 -1
  55. package/lib/commonjs/utils/animated/Animated.js +4 -4
  56. package/lib/commonjs/utils/animated/Animated.js.map +1 -1
  57. package/lib/commonjs/utils/animated/AnimatedExtractCoordinateFromArray.js +0 -6
  58. package/lib/commonjs/utils/animated/AnimatedExtractCoordinateFromArray.js.map +1 -1
  59. package/lib/commonjs/utils/animated/AnimatedPoint.js +0 -2
  60. package/lib/commonjs/utils/animated/AnimatedPoint.js.map +1 -1
  61. package/lib/commonjs/utils/animated/AnimatedShape.js +3 -16
  62. package/lib/commonjs/utils/animated/AnimatedShape.js.map +1 -1
  63. package/lib/commonjs/utils/findNodeHandle.js +16 -0
  64. package/lib/commonjs/utils/findNodeHandle.js.map +1 -0
  65. package/lib/commonjs/utils/{filterUtils.js → getFilter.js} +2 -2
  66. package/lib/commonjs/utils/getFilter.js.map +1 -0
  67. package/lib/commonjs/utils/index.js +3 -8
  68. package/lib/commonjs/utils/index.js.map +1 -1
  69. package/lib/module/components/annotations/Annotation.js +1 -1
  70. package/lib/module/components/annotations/Annotation.js.map +1 -1
  71. package/lib/module/components/layers/BackgroundLayer.js.map +1 -1
  72. package/lib/module/components/layers/CircleLayer.js.map +1 -1
  73. package/lib/module/components/layers/FillExtrusionLayer.js.map +1 -1
  74. package/lib/module/components/layers/HeatmapLayer.js.map +1 -1
  75. package/lib/module/components/layers/RasterLayer.js.map +1 -1
  76. package/lib/module/components/layers/SymbolLayer.js.map +1 -1
  77. package/lib/module/components/map-view/MapView.js +3 -9
  78. package/lib/module/components/map-view/MapView.js.map +1 -1
  79. package/lib/module/components/sources/VectorSource.js +1 -1
  80. package/lib/module/components/sources/VectorSource.js.map +1 -1
  81. package/lib/module/components/sources/shape-source/NativeShapeSourceModule.js +5 -0
  82. package/lib/module/components/sources/shape-source/NativeShapeSourceModule.js.map +1 -0
  83. package/lib/module/components/sources/shape-source/ShapeSource.js +46 -0
  84. package/lib/module/components/sources/shape-source/ShapeSource.js.map +1 -0
  85. package/lib/module/components/sources/shape-source/ShapeSourceNativeComponent.ts +48 -0
  86. package/lib/module/hooks/useAbstractLayer.js +1 -1
  87. package/lib/module/hooks/useAbstractLayer.js.map +1 -1
  88. package/lib/module/hooks/useFrozenId.js +12 -0
  89. package/lib/module/hooks/useFrozenId.js.map +1 -0
  90. package/lib/module/index.js +1 -1
  91. package/lib/module/index.js.map +1 -1
  92. package/lib/module/modules/snapshot/SnapshotOptions.js.map +1 -1
  93. package/lib/module/types/PressEventWithFeatures.js +4 -0
  94. package/lib/module/types/PressEventWithFeatures.js.map +1 -0
  95. package/lib/module/utils/animated/AbstractAnimatedCoordinates.js +0 -7
  96. package/lib/module/utils/animated/AbstractAnimatedCoordinates.js.map +1 -1
  97. package/lib/module/utils/animated/Animated.js +4 -4
  98. package/lib/module/utils/animated/Animated.js.map +1 -1
  99. package/lib/module/utils/animated/AnimatedExtractCoordinateFromArray.js +0 -6
  100. package/lib/module/utils/animated/AnimatedExtractCoordinateFromArray.js.map +1 -1
  101. package/lib/module/utils/animated/AnimatedPoint.js +0 -3
  102. package/lib/module/utils/animated/AnimatedPoint.js.map +1 -1
  103. package/lib/module/utils/animated/AnimatedShape.js +3 -16
  104. package/lib/module/utils/animated/AnimatedShape.js.map +1 -1
  105. package/lib/module/utils/findNodeHandle.js +11 -0
  106. package/lib/module/utils/findNodeHandle.js.map +1 -0
  107. package/lib/module/utils/getFilter.js +9 -0
  108. package/lib/module/utils/getFilter.js.map +1 -0
  109. package/lib/module/utils/index.js +3 -8
  110. package/lib/module/utils/index.js.map +1 -1
  111. package/lib/typescript/commonjs/src/components/annotations/Annotation.d.ts +1 -1
  112. package/lib/typescript/commonjs/src/components/annotations/Annotation.d.ts.map +1 -1
  113. package/lib/typescript/commonjs/src/components/layers/BackgroundLayer.d.ts.map +1 -1
  114. package/lib/typescript/commonjs/src/components/layers/CircleLayer.d.ts.map +1 -1
  115. package/lib/typescript/commonjs/src/components/layers/FillExtrusionLayer.d.ts.map +1 -1
  116. package/lib/typescript/commonjs/src/components/layers/HeatmapLayer.d.ts.map +1 -1
  117. package/lib/typescript/commonjs/src/components/layers/RasterLayer.d.ts.map +1 -1
  118. package/lib/typescript/commonjs/src/components/layers/SymbolLayer.d.ts.map +1 -1
  119. package/lib/typescript/commonjs/src/components/map-view/MapView.d.ts.map +1 -1
  120. package/lib/typescript/commonjs/src/components/sources/VectorSource.d.ts +1 -1
  121. package/lib/typescript/commonjs/src/components/sources/VectorSource.d.ts.map +1 -1
  122. package/lib/typescript/commonjs/src/components/sources/shape-source/NativeShapeSourceModule.d.ts +10 -0
  123. package/lib/typescript/commonjs/src/components/sources/shape-source/NativeShapeSourceModule.d.ts.map +1 -0
  124. package/lib/typescript/{module/src/components/sources → commonjs/src/components/sources/shape-source}/ShapeSource.d.ts +60 -41
  125. package/lib/typescript/commonjs/src/components/sources/shape-source/ShapeSource.d.ts.map +1 -0
  126. package/lib/typescript/commonjs/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts +35 -0
  127. package/lib/typescript/commonjs/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts.map +1 -0
  128. package/lib/typescript/commonjs/src/hooks/useFrozenId.d.ts +2 -0
  129. package/lib/typescript/commonjs/src/hooks/useFrozenId.d.ts.map +1 -0
  130. package/lib/typescript/commonjs/src/index.d.ts +4 -3
  131. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  132. package/lib/typescript/commonjs/src/modules/snapshot/SnapshotOptions.d.ts.map +1 -1
  133. package/lib/typescript/commonjs/src/types/MapLibreRNStyles.d.ts +1 -1
  134. package/lib/typescript/commonjs/src/types/MapLibreRNStyles.d.ts.map +1 -1
  135. package/lib/typescript/commonjs/src/types/PressEvent.d.ts +0 -3
  136. package/lib/typescript/commonjs/src/types/PressEvent.d.ts.map +1 -1
  137. package/lib/typescript/commonjs/src/types/PressEventWithFeatures.d.ts +5 -0
  138. package/lib/typescript/commonjs/src/types/PressEventWithFeatures.d.ts.map +1 -0
  139. package/lib/typescript/commonjs/src/utils/animated/AbstractAnimatedCoordinates.d.ts.map +1 -1
  140. package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts +4 -1
  141. package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts.map +1 -1
  142. package/lib/typescript/commonjs/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts.map +1 -1
  143. package/lib/typescript/commonjs/src/utils/animated/AnimatedPoint.d.ts.map +1 -1
  144. package/lib/typescript/commonjs/src/utils/animated/AnimatedRouteCoordinatesArray.d.ts.map +1 -1
  145. package/lib/typescript/commonjs/src/utils/animated/AnimatedShape.d.ts +2 -2
  146. package/lib/typescript/commonjs/src/utils/animated/AnimatedShape.d.ts.map +1 -1
  147. package/lib/typescript/commonjs/src/utils/findNodeHandle.d.ts +3 -0
  148. package/lib/typescript/commonjs/src/utils/findNodeHandle.d.ts.map +1 -0
  149. package/lib/typescript/commonjs/src/utils/{filterUtils.d.ts → getFilter.d.ts} +2 -2
  150. package/lib/typescript/commonjs/src/utils/getFilter.d.ts.map +1 -0
  151. package/lib/typescript/commonjs/src/utils/index.d.ts +3 -3
  152. package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
  153. package/lib/typescript/module/src/components/annotations/Annotation.d.ts +1 -1
  154. package/lib/typescript/module/src/components/annotations/Annotation.d.ts.map +1 -1
  155. package/lib/typescript/module/src/components/layers/BackgroundLayer.d.ts.map +1 -1
  156. package/lib/typescript/module/src/components/layers/CircleLayer.d.ts.map +1 -1
  157. package/lib/typescript/module/src/components/layers/FillExtrusionLayer.d.ts.map +1 -1
  158. package/lib/typescript/module/src/components/layers/HeatmapLayer.d.ts.map +1 -1
  159. package/lib/typescript/module/src/components/layers/RasterLayer.d.ts.map +1 -1
  160. package/lib/typescript/module/src/components/layers/SymbolLayer.d.ts.map +1 -1
  161. package/lib/typescript/module/src/components/map-view/MapView.d.ts.map +1 -1
  162. package/lib/typescript/module/src/components/sources/VectorSource.d.ts +1 -1
  163. package/lib/typescript/module/src/components/sources/VectorSource.d.ts.map +1 -1
  164. package/lib/typescript/module/src/components/sources/shape-source/NativeShapeSourceModule.d.ts +10 -0
  165. package/lib/typescript/module/src/components/sources/shape-source/NativeShapeSourceModule.d.ts.map +1 -0
  166. package/lib/typescript/{commonjs/src/components/sources → module/src/components/sources/shape-source}/ShapeSource.d.ts +60 -41
  167. package/lib/typescript/module/src/components/sources/shape-source/ShapeSource.d.ts.map +1 -0
  168. package/lib/typescript/module/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts +35 -0
  169. package/lib/typescript/module/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts.map +1 -0
  170. package/lib/typescript/module/src/hooks/useFrozenId.d.ts +2 -0
  171. package/lib/typescript/module/src/hooks/useFrozenId.d.ts.map +1 -0
  172. package/lib/typescript/module/src/index.d.ts +4 -3
  173. package/lib/typescript/module/src/index.d.ts.map +1 -1
  174. package/lib/typescript/module/src/modules/snapshot/SnapshotOptions.d.ts.map +1 -1
  175. package/lib/typescript/module/src/types/MapLibreRNStyles.d.ts +1 -1
  176. package/lib/typescript/module/src/types/MapLibreRNStyles.d.ts.map +1 -1
  177. package/lib/typescript/module/src/types/PressEvent.d.ts +0 -3
  178. package/lib/typescript/module/src/types/PressEvent.d.ts.map +1 -1
  179. package/lib/typescript/module/src/types/PressEventWithFeatures.d.ts +5 -0
  180. package/lib/typescript/module/src/types/PressEventWithFeatures.d.ts.map +1 -0
  181. package/lib/typescript/module/src/utils/animated/AbstractAnimatedCoordinates.d.ts.map +1 -1
  182. package/lib/typescript/module/src/utils/animated/Animated.d.ts +4 -1
  183. package/lib/typescript/module/src/utils/animated/Animated.d.ts.map +1 -1
  184. package/lib/typescript/module/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts.map +1 -1
  185. package/lib/typescript/module/src/utils/animated/AnimatedPoint.d.ts.map +1 -1
  186. package/lib/typescript/module/src/utils/animated/AnimatedRouteCoordinatesArray.d.ts.map +1 -1
  187. package/lib/typescript/module/src/utils/animated/AnimatedShape.d.ts +2 -2
  188. package/lib/typescript/module/src/utils/animated/AnimatedShape.d.ts.map +1 -1
  189. package/lib/typescript/module/src/utils/findNodeHandle.d.ts +3 -0
  190. package/lib/typescript/module/src/utils/findNodeHandle.d.ts.map +1 -0
  191. package/lib/typescript/module/src/utils/{filterUtils.d.ts → getFilter.d.ts} +2 -2
  192. package/lib/typescript/module/src/utils/getFilter.d.ts.map +1 -0
  193. package/lib/typescript/module/src/utils/index.d.ts +3 -3
  194. package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
  195. package/package.json +7 -6
  196. package/src/components/annotations/Annotation.tsx +2 -2
  197. package/src/components/layers/BackgroundLayer.tsx +1 -2
  198. package/src/components/layers/CircleLayer.tsx +1 -2
  199. package/src/components/layers/FillExtrusionLayer.tsx +1 -2
  200. package/src/components/layers/HeatmapLayer.tsx +1 -2
  201. package/src/components/layers/RasterLayer.tsx +1 -2
  202. package/src/components/layers/SymbolLayer.tsx +1 -2
  203. package/src/components/map-view/MapView.tsx +2 -14
  204. package/src/components/sources/VectorSource.tsx +2 -2
  205. package/src/components/sources/shape-source/NativeShapeSourceModule.ts +31 -0
  206. package/src/components/sources/shape-source/ShapeSource.tsx +235 -0
  207. package/src/components/sources/shape-source/ShapeSourceNativeComponent.ts +48 -0
  208. package/src/hooks/useAbstractLayer.ts +1 -1
  209. package/src/hooks/useFrozenId.ts +13 -0
  210. package/src/index.ts +4 -3
  211. package/src/modules/snapshot/SnapshotOptions.ts +3 -2
  212. package/src/types/MapLibreRNStyles.ts +1 -1
  213. package/src/types/PressEvent.ts +0 -4
  214. package/src/types/PressEventWithFeatures.ts +5 -0
  215. package/src/utils/animated/AbstractAnimatedCoordinates.ts +0 -9
  216. package/src/utils/animated/Animated.ts +12 -5
  217. package/src/utils/animated/AnimatedExtractCoordinateFromArray.ts +0 -9
  218. package/src/utils/animated/AnimatedPoint.ts +0 -2
  219. package/src/utils/animated/AnimatedRouteCoordinatesArray.ts +3 -3
  220. package/src/utils/animated/AnimatedShape.ts +7 -18
  221. package/src/utils/findNodeHandle.ts +14 -0
  222. package/src/utils/{filterUtils.ts → getFilter.ts} +2 -2
  223. package/src/utils/index.ts +12 -12
  224. package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNShapeSource.java +0 -248
  225. package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNShapeSourceManager.java +0 -216
  226. package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNSource.java +0 -240
  227. package/android/src/main/java/org/maplibre/reactnative/utils/ClusterPropertyEntry.java +0 -13
  228. package/android/src/main/java/org/maplibre/reactnative/utils/ConvertUtils.java +0 -246
  229. package/android/src/main/java/org/maplibre/reactnative/utils/ExpressionParser.java +0 -74
  230. package/ios/components/sources/MLRNShapeSourceManager.h +0 -6
  231. package/ios/components/sources/MLRNShapeSourceManager.m +0 -128
  232. package/lib/commonjs/components/sources/ShapeSource.js +0 -153
  233. package/lib/commonjs/components/sources/ShapeSource.js.map +0 -1
  234. package/lib/commonjs/utils/filterUtils.js.map +0 -1
  235. package/lib/module/components/sources/ShapeSource.js +0 -149
  236. package/lib/module/components/sources/ShapeSource.js.map +0 -1
  237. package/lib/module/utils/filterUtils.js +0 -9
  238. package/lib/module/utils/filterUtils.js.map +0 -1
  239. package/lib/typescript/commonjs/src/components/sources/ShapeSource.d.ts.map +0 -1
  240. package/lib/typescript/commonjs/src/utils/filterUtils.d.ts.map +0 -1
  241. package/lib/typescript/module/src/components/sources/ShapeSource.d.ts.map +0 -1
  242. package/lib/typescript/module/src/utils/filterUtils.d.ts.map +0 -1
  243. package/src/components/sources/ShapeSource.tsx +0 -366
@@ -1,248 +0,0 @@
1
- package org.maplibre.reactnative.components.sources;
2
-
3
- import android.content.Context;
4
- import android.graphics.Bitmap;
5
- import android.graphics.drawable.BitmapDrawable;
6
- import androidx.annotation.NonNull;
7
- import androidx.annotation.Nullable;
8
-
9
- import com.facebook.react.bridge.WritableMap;
10
- import com.facebook.react.bridge.WritableNativeMap;
11
- import org.maplibre.geojson.Feature;
12
- import org.maplibre.geojson.FeatureCollection;
13
- import org.maplibre.android.maps.MapLibreMap;
14
- import org.maplibre.android.maps.Style;
15
- import org.maplibre.android.style.expressions.Expression;
16
- import org.maplibre.android.style.sources.GeoJsonOptions;
17
- import org.maplibre.android.style.sources.GeoJsonSource;
18
- import org.maplibre.reactnative.components.mapview.MLRNMapView;
19
- import org.maplibre.reactnative.events.AndroidCallbackEvent;
20
- import org.maplibre.reactnative.events.FeatureClickEvent;
21
- import org.maplibre.reactnative.utils.ClusterPropertyEntry;
22
- import org.maplibre.reactnative.utils.ImageEntry;
23
-
24
- import java.net.URL;
25
- import java.util.List;
26
- import java.util.Map;
27
-
28
- public class MLRNShapeSource extends MLRNSource<GeoJsonSource> {
29
- private URL mURL;
30
- private MLRNShapeSourceManager mManager;
31
-
32
- private String mShape;
33
-
34
- private Boolean mCluster;
35
- private Integer mClusterRadius;
36
- private Integer mClusterMinPoints;
37
- private Integer mClusterMaxZoom;
38
- private List<Map.Entry<String, ClusterPropertyEntry>> mClusterProperties;
39
-
40
- private Integer mMaxZoom;
41
- private Integer mBuffer;
42
- private Double mTolerance;
43
- private Boolean mLineMetrics;
44
-
45
- private static Bitmap mImagePlaceholder;
46
- private List<Map.Entry<String, ImageEntry>> mImages;
47
- private List<Map.Entry<String, BitmapDrawable>> mNativeImages;
48
-
49
- public MLRNShapeSource(Context context, MLRNShapeSourceManager manager) {
50
- super(context);
51
- mManager = manager;
52
- }
53
-
54
- @Override
55
- public void addToMap(final MLRNMapView mapView) {
56
- // Wait for style before adding the source to the map
57
- mapView.getMapLibreMap().getStyle(new Style.OnStyleLoaded() {
58
- @Override
59
- public void onStyleLoaded(@NonNull Style style) {
60
- MapLibreMap map = mapView.getMapLibreMap();
61
- MLRNShapeSource.super.addToMap(mapView);
62
- }
63
- });
64
- }
65
-
66
- @Override
67
- public GeoJsonSource makeSource() {
68
- GeoJsonOptions options = getOptions();
69
-
70
- if (mShape != null) {
71
- return new GeoJsonSource(mID, mShape, options);
72
- }
73
-
74
- return new GeoJsonSource(mID, mURL, options);
75
- }
76
-
77
- public void setURL(URL url) {
78
- mURL = url;
79
-
80
- if (mSource != null && mMapView != null && !mMapView.isDestroyed() ) {
81
- mSource.setUrl(mURL);
82
- }
83
- }
84
-
85
- public void setShape(String geoJSONStr) {
86
- mShape = geoJSONStr;
87
-
88
- if (mSource != null && mMapView != null && !mMapView.isDestroyed() ) {
89
- mSource.setGeoJson(mShape);
90
- }
91
- }
92
-
93
- public void setCluster(boolean cluster) {
94
- mCluster = cluster;
95
- }
96
-
97
- public void setClusterRadius(int clusterRadius) {
98
- mClusterRadius = clusterRadius;
99
- }
100
-
101
- public void setClusterMinPoints(int clusterMinPoints) {
102
- mClusterMinPoints = clusterMinPoints;
103
- }
104
-
105
- public void setClusterMaxZoom(int clusterMaxZoom) {
106
- mClusterMaxZoom = clusterMaxZoom;
107
- }
108
-
109
- public void setClusterProperties(List<Map.Entry<String, ClusterPropertyEntry>> clusterProperties) {
110
- mClusterProperties = clusterProperties;
111
- }
112
-
113
- public void setMaxZoom(int maxZoom) {
114
- mMaxZoom = maxZoom;
115
- }
116
-
117
- public void setBuffer(int buffer) {
118
- mBuffer = buffer;
119
- }
120
-
121
- public void setTolerance(double tolerance) {
122
- mTolerance = tolerance;
123
- }
124
-
125
- public void setLineMetrics(boolean lineMetrics) {
126
- mLineMetrics = lineMetrics;
127
- }
128
-
129
- public void onPress(OnPressEvent event) {
130
- mManager.handleEvent(FeatureClickEvent.makeShapeSourceEvent(this, event));
131
- }
132
-
133
- private GeoJsonOptions getOptions() {
134
- GeoJsonOptions options = new GeoJsonOptions();
135
-
136
- if (mCluster != null) {
137
- options.withCluster(mCluster);
138
- }
139
-
140
- if (mClusterRadius != null) {
141
- options.withClusterRadius(mClusterRadius);
142
- }
143
-
144
- if (mClusterMinPoints != null) {
145
- options.withClusterMinPoints(mClusterMinPoints);
146
- }
147
-
148
- if (mClusterMaxZoom != null) {
149
- options.withClusterMaxZoom(mClusterMaxZoom);
150
- }
151
-
152
- if (mClusterProperties != null) {
153
- for (Map.Entry<String, ClusterPropertyEntry> entry : mClusterProperties) {
154
- ClusterPropertyEntry property = entry.getValue();
155
-
156
- options.withClusterProperty(entry.getKey(), property.operator, property.mapping);
157
- }
158
- }
159
-
160
- if (mMaxZoom != null) {
161
- options.withMaxZoom(mMaxZoom);
162
- }
163
-
164
- if (mBuffer != null) {
165
- options.withBuffer(mBuffer);
166
- }
167
-
168
- if (mTolerance != null) {
169
- options.withTolerance(mTolerance.floatValue());
170
- }
171
-
172
- if (mLineMetrics != null) {
173
- options.withLineMetrics(mLineMetrics);
174
- }
175
-
176
- return options;
177
- }
178
-
179
- public void querySourceFeatures(String callbackID,
180
- @Nullable Expression filter) {
181
- if (mSource == null) {
182
- WritableMap payload = new WritableNativeMap();
183
- payload.putString("error", "source is not yet loaded");
184
- AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
185
- mManager.handleEvent(event);
186
- return;
187
- }
188
- List<Feature> features = mSource.querySourceFeatures(filter);
189
- WritableMap payload = new WritableNativeMap();
190
- payload.putString("data", FeatureCollection.fromFeatures(features).toJson());
191
-
192
- AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
193
- mManager.handleEvent(event);
194
- }
195
-
196
- public void getClusterExpansionZoom(String callbackID, String featureJSON) {
197
- if (mSource == null) {
198
- WritableMap payload = new WritableNativeMap();
199
- payload.putString("error", "source is not yet loaded");
200
- AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
201
- mManager.handleEvent(event);
202
- return;
203
- }
204
- Feature feature = Feature.fromJson(featureJSON);
205
-
206
- int zoom = mSource.getClusterExpansionZoom(feature);
207
-
208
- WritableMap payload = new WritableNativeMap();
209
- payload.putInt("data", zoom);
210
-
211
- AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
212
- mManager.handleEvent(event);
213
- }
214
-
215
- public void getClusterLeaves(String callbackID, String featureJSON, int number, int offset) {
216
- if (mSource == null) {
217
- WritableMap payload = new WritableNativeMap();
218
- payload.putString("error", "source is not yet loaded");
219
- AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
220
- mManager.handleEvent(event);
221
- return;
222
- }
223
- Feature clusterFeature = Feature.fromJson(featureJSON);
224
- FeatureCollection leaves = mSource.getClusterLeaves(clusterFeature, number, offset);
225
- WritableMap payload = new WritableNativeMap();
226
- payload.putString("data", leaves.toJson());
227
-
228
- AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
229
- mManager.handleEvent(event);
230
- }
231
-
232
- public void getClusterChildren(String callbackID, String featureJSON) {
233
- if (mSource == null) {
234
- WritableMap payload = new WritableNativeMap();
235
- payload.putString("error", "source is not yet loaded");
236
- AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
237
- mManager.handleEvent(event);
238
- return;
239
- }
240
- Feature clusterFeature = Feature.fromJson(featureJSON);
241
- FeatureCollection leaves = mSource.getClusterChildren(clusterFeature);
242
- WritableMap payload = new WritableNativeMap();
243
- payload.putString("data", leaves.toJson());
244
-
245
- AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
246
- mManager.handleEvent(event);
247
- }
248
- }
@@ -1,216 +0,0 @@
1
- package org.maplibre.reactnative.components.sources;
2
-
3
- import android.util.Log;
4
- import android.view.View;
5
-
6
- import androidx.annotation.Nullable;
7
-
8
- import com.facebook.react.bridge.ReactApplicationContext;
9
- import com.facebook.react.bridge.ReadableArray;
10
- import com.facebook.react.bridge.ReadableMap;
11
- import com.facebook.react.bridge.ReadableMapKeySetIterator;
12
- import com.facebook.react.bridge.ReadableType;
13
- import com.facebook.react.common.MapBuilder;
14
- import com.facebook.react.uimanager.ThemedReactContext;
15
- import com.facebook.react.uimanager.annotations.ReactProp;
16
- import org.maplibre.android.style.expressions.Expression;
17
- import org.maplibre.reactnative.components.AbstractEventEmitter;
18
- import org.maplibre.reactnative.events.constants.EventKeys;
19
- import org.maplibre.reactnative.utils.ClusterPropertyEntry;
20
- import org.maplibre.reactnative.utils.ExpressionParser;
21
-
22
- import java.net.MalformedURLException;
23
- import java.net.URL;
24
- import java.util.AbstractMap;
25
- import java.util.ArrayList;
26
- import java.util.List;
27
- import java.util.Map;
28
-
29
- public class MLRNShapeSourceManager extends AbstractEventEmitter<MLRNShapeSource> {
30
- public static final String LOG_TAG = "MLRNShapeSourceManager";
31
- public static final String REACT_CLASS = "MLRNShapeSource";
32
-
33
- private ReactApplicationContext mContext;
34
-
35
- public MLRNShapeSourceManager(ReactApplicationContext context) {
36
- super(context);
37
- mContext = context;
38
- }
39
-
40
- @Override
41
- public String getName() {
42
- return REACT_CLASS;
43
- }
44
-
45
- @Override
46
- protected MLRNShapeSource createViewInstance(ThemedReactContext reactContext) {
47
- return new MLRNShapeSource(reactContext, this);
48
- }
49
-
50
- @Override
51
- public View getChildAt(MLRNShapeSource source, int childPosition) {
52
- return source.getLayerAt(childPosition);
53
- }
54
-
55
- @Override
56
- public int getChildCount(MLRNShapeSource source) {
57
- return source.getLayerCount();
58
- }
59
-
60
- @Override
61
- public void addView(MLRNShapeSource source, View childView, int childPosition) {
62
- source.addLayer(childView, getChildCount(source));
63
- }
64
-
65
- @Override
66
- public void removeViewAt(MLRNShapeSource source, int childPosition) {
67
- source.removeLayer(childPosition);
68
- }
69
-
70
- @ReactProp(name = "id")
71
- public void setId(MLRNShapeSource source, String id) {
72
- source.setID(id);
73
- }
74
-
75
- @ReactProp(name = "url")
76
- public void setURL(MLRNShapeSource source, String urlStr) {
77
- try {
78
- source.setURL(new URL(urlStr));
79
- } catch (MalformedURLException e) {
80
- Log.w(LOG_TAG, e.getLocalizedMessage());
81
- }
82
- }
83
-
84
- @ReactProp(name = "shape")
85
- public void setGeometry(MLRNShapeSource source, String geoJSONStr) {
86
- source.setShape(geoJSONStr);
87
- }
88
-
89
- @ReactProp(name = "cluster")
90
- public void setCluster(MLRNShapeSource source, int cluster) {
91
- source.setCluster(cluster == 1);
92
- }
93
-
94
- @ReactProp(name = "clusterRadius")
95
- public void setClusterRadius(MLRNShapeSource source, int radius) {
96
- source.setClusterRadius(radius);
97
- }
98
-
99
- @ReactProp(name = "clusterMinPoints")
100
- public void setClusterMinPoints(MLRNShapeSource source, int minPoints) {
101
- source.setClusterMinPoints(minPoints);
102
- }
103
-
104
- @ReactProp(name = "clusterMaxZoomLevel")
105
- public void setClusterMaxZoomLevel(MLRNShapeSource source, int clusterMaxZoom) {
106
- source.setClusterMaxZoom(clusterMaxZoom);
107
- }
108
-
109
- @ReactProp(name = "clusterProperties")
110
- public void setClusterProperties(MLRNShapeSource source, ReadableMap map) {
111
- List<Map.Entry<String, ClusterPropertyEntry>> properties = new ArrayList<>();
112
-
113
- ReadableMapKeySetIterator iterator = map.keySetIterator();
114
- while (iterator.hasNextKey()) {
115
- String name = iterator.nextKey();
116
- ReadableArray expressions = map.getArray(name);
117
-
118
- Expression operator;
119
- if (expressions.getType(0) == ReadableType.Array) {
120
- operator = ExpressionParser.from(expressions.getArray(0));
121
- } else {
122
- operator = Expression.literal(expressions.getString(0));
123
- }
124
-
125
- Expression mapping = ExpressionParser.from(expressions.getArray(1));
126
-
127
- properties.add(new AbstractMap.SimpleEntry<>(name, new ClusterPropertyEntry(operator, mapping)));
128
- }
129
-
130
- source.setClusterProperties(properties);
131
- }
132
-
133
- @ReactProp(name = "maxZoomLevel")
134
- public void setMaxZoomLevel(MLRNShapeSource source, int maxZoom) {
135
- source.setMaxZoom(maxZoom);
136
- }
137
-
138
- @ReactProp(name = "buffer")
139
- public void setBuffer(MLRNShapeSource source, int buffer) {
140
- source.setBuffer(buffer);
141
- }
142
-
143
- @ReactProp(name = "tolerance")
144
- public void setTolerance(MLRNShapeSource source, double tolerance) {
145
- source.setTolerance(tolerance);
146
- }
147
-
148
- @ReactProp(name = "lineMetrics")
149
- public void setLineMetrics(MLRNShapeSource source, boolean lineMetrics) {
150
- source.setLineMetrics(lineMetrics);
151
- }
152
-
153
- @ReactProp(name = "hasPressListener")
154
- public void setHasPressListener(MLRNShapeSource source, boolean hasPressListener) {
155
- source.setHasPressListener(hasPressListener);
156
- }
157
-
158
- @ReactProp(name="hitbox")
159
- public void setHitbox(MLRNShapeSource source, ReadableMap map) {
160
- source.setHitbox(map);
161
- }
162
-
163
- @Override
164
- public Map<String, String> customEvents() {
165
- return MapBuilder.<String, String>builder()
166
- .put(EventKeys.SHAPE_SOURCE_LAYER_CLICK, "onMapboxShapeSourcePress")
167
- .put(EventKeys.MAP_ANDROID_CALLBACK, "onAndroidCallback")
168
- .build();
169
- }
170
-
171
- //region React Methods
172
- public static final int METHOD_FEATURES = 103;
173
- public static final int METHOD_GET_CLUSTER_EXPANSION_ZOOM = 104;
174
- public static final int METHOD_GET_CLUSTER_LEAVES = 105;
175
- public static final int METHOD_GET_CLUSTER_CHILDREN = 106;
176
-
177
- @Nullable
178
- @Override
179
- public Map<String, Integer> getCommandsMap() {
180
- return MapBuilder.<String, Integer>builder()
181
- .put("features", METHOD_FEATURES)
182
- .put("getClusterExpansionZoom", METHOD_GET_CLUSTER_EXPANSION_ZOOM)
183
- .put("getClusterLeaves", METHOD_GET_CLUSTER_LEAVES)
184
- .put("getClusterChildren", METHOD_GET_CLUSTER_CHILDREN)
185
- .build();
186
- }
187
-
188
- @Override
189
- public void receiveCommand(MLRNShapeSource source, int commandID, @Nullable ReadableArray args) {
190
- switch (commandID) {
191
- case METHOD_FEATURES:
192
- source.querySourceFeatures(
193
- args.getString(0),
194
- ExpressionParser.from(args.getArray(1))
195
- );
196
- break;
197
- case METHOD_GET_CLUSTER_EXPANSION_ZOOM:
198
- source.getClusterExpansionZoom(args.getString(0), args.getString(1));
199
- break;
200
- case METHOD_GET_CLUSTER_LEAVES:
201
- source.getClusterLeaves(
202
- args.getString(0),
203
- args.getString(1),
204
- args.getInt(2),
205
- args.getInt((3))
206
- );
207
- break;
208
- case METHOD_GET_CLUSTER_CHILDREN:
209
- source.getClusterChildren(
210
- args.getString(0),
211
- args.getString(1)
212
- );
213
- break;
214
- }
215
- }
216
- }
@@ -1,240 +0,0 @@
1
- package org.maplibre.reactnative.components.sources;
2
-
3
- import android.content.Context;
4
- import androidx.annotation.NonNull;
5
-
6
- import android.graphics.PointF;
7
- import android.view.View;
8
-
9
- import com.facebook.react.bridge.ReadableMap;
10
- import com.facebook.react.common.MapBuilder;
11
- import org.maplibre.geojson.Feature;
12
- import org.maplibre.android.geometry.LatLng;
13
- import org.maplibre.android.log.Logger;
14
- import org.maplibre.android.maps.MapLibreMap;
15
- import org.maplibre.android.maps.Style;
16
- import org.maplibre.android.style.sources.Source;
17
- import org.maplibre.reactnative.components.AbstractMapFeature;
18
- import org.maplibre.reactnative.components.mapview.MLRNMapView;
19
- import org.maplibre.reactnative.components.layers.MLRNLayer;
20
-
21
- import java.util.ArrayList;
22
- import java.util.HashMap;
23
- import java.util.List;
24
- import java.util.Map;
25
-
26
- public abstract class MLRNSource<T extends Source> extends AbstractMapFeature {
27
- public static final String DEFAULT_ID = "composite";
28
- public static final String LOG_TAG = "MLRNSource";
29
-
30
- public static final double DEFAULT_HITBOX_WIDTH = 44.0;
31
- public static final double DEFAULT_HITBOX_HEIGHT = 44.0;
32
-
33
- protected MLRNMapView mMapView;
34
- protected MapLibreMap mMap;
35
-
36
- protected String mID;
37
- protected T mSource;
38
- protected boolean mHasPressListener;
39
- protected Map<String, Double> mTouchHitbox;
40
-
41
- protected List<MLRNLayer> mLayers;
42
- private List<MLRNLayer> mQueuedLayers;
43
-
44
- public MLRNSource(Context context) {
45
- super(context);
46
- mLayers = new ArrayList<>();
47
- mQueuedLayers = new ArrayList<>();
48
- }
49
-
50
- public String getID() {
51
- return mID;
52
- }
53
-
54
- public String[] getLayerIDs() {
55
- List<String> layerIDs = new ArrayList<>();
56
-
57
- for (int i = 0; i < mLayers.size(); i++) {
58
- MLRNLayer layer = mLayers.get(i);
59
- layerIDs.add(layer.getID());
60
- }
61
-
62
- return layerIDs.toArray(new String[layerIDs.size()]);
63
- }
64
-
65
- public boolean hasPressListener() {
66
- return mHasPressListener;
67
- }
68
-
69
- public void setHasPressListener (boolean hasPressListener) {
70
- mHasPressListener = hasPressListener;
71
- }
72
-
73
- public void setHitbox(ReadableMap map) {
74
- Map<String, Double> hitbox = new HashMap<>();
75
- hitbox.put("width", map.getDouble("width"));
76
- hitbox.put("height", map.getDouble("height"));
77
- mTouchHitbox = hitbox;
78
- }
79
-
80
- public void setID(String id) {
81
- mID = id;
82
- }
83
-
84
- public void setSource(T source) {
85
- mSource = source;
86
- }
87
-
88
- public Map<String, Double> getTouchHitbox() {
89
- if (!hasPressListener()) {
90
- return null;
91
- }
92
-
93
- if (mTouchHitbox == null) {
94
- return MapBuilder.<String, Double>builder()
95
- .put("width", DEFAULT_HITBOX_WIDTH)
96
- .put("height", DEFAULT_HITBOX_HEIGHT)
97
- .build();
98
- }
99
-
100
- return mTouchHitbox;
101
- }
102
-
103
- public int getLayerCount () {
104
- int totalCount = 0;
105
-
106
- if (mQueuedLayers != null) {
107
- totalCount = mQueuedLayers.size();
108
- }
109
-
110
- totalCount += mLayers.size();
111
- return totalCount;
112
- }
113
-
114
- @Override
115
- public void addToMap(MLRNMapView mapView) {
116
- mMapView = mapView;
117
- mMap = mapView.getMapLibreMap();
118
- mMap.getStyle(new Style.OnStyleLoaded() {
119
- public void onStyleLoaded(@NonNull Style style) {
120
- T existingSource = style.getSourceAs(mID);
121
- if (existingSource != null) {
122
- mSource = existingSource;
123
- } else {
124
- mSource = makeSource();
125
- style.addSource(mSource);
126
- }
127
-
128
- if (mQueuedLayers != null && mQueuedLayers.size() > 0) { // first load
129
- for (int i = 0; i < mQueuedLayers.size(); i++) {
130
- addLayerToMap(mQueuedLayers.get(i), i);
131
- }
132
- mQueuedLayers = null;
133
- } else if (mLayers.size() > 0) { // handles the case of switching style url, but keeping layers on map
134
- for (int i = 0; i < mLayers.size(); i++) {
135
- addLayerToMap(mLayers.get(i), i);
136
- }
137
- }
138
- }
139
- });
140
-
141
-
142
- }
143
-
144
- @Override
145
- public void removeFromMap(MLRNMapView mapView) {
146
- if (mLayers.size() > 0) {
147
- for (int i = 0; i < mLayers.size(); i++) {
148
- MLRNLayer layer = mLayers.get(i);
149
- layer.removeFromMap(mMapView);
150
- }
151
- }
152
- if (mQueuedLayers != null) {
153
- mQueuedLayers.clear();
154
- }
155
- if (mMap != null && mSource != null && mMap.getStyle() != null) {
156
- try {
157
- mMap.getStyle().removeSource(mSource);
158
- } catch (Throwable ex) {
159
- Logger.w(LOG_TAG, String.format("MLRNSource.removeFromMap: %s - %s", mSource, ex.getMessage()), ex);
160
- }
161
- }
162
- }
163
-
164
- public void addLayer(View childView, int childPosition) {
165
- if (!(childView instanceof MLRNLayer)) {
166
- return;
167
- }
168
-
169
- MLRNLayer layer = (MLRNLayer) childView;
170
- if (mMap == null) {
171
- mQueuedLayers.add(childPosition, layer);
172
- } else {
173
- addLayerToMap(layer, childPosition);
174
- }
175
- }
176
-
177
- public void removeLayer(int childPosition) {
178
- MLRNLayer layer;
179
- if (mQueuedLayers != null && mQueuedLayers.size() > 0) {
180
- layer = mQueuedLayers.get(childPosition);
181
- } else {
182
- layer = mLayers.get(childPosition);
183
- }
184
- removeLayerFromMap(layer, childPosition);
185
- }
186
-
187
- public MLRNLayer getLayerAt(int childPosition) {
188
- if (mQueuedLayers != null && mQueuedLayers.size() > 0) {
189
- return mQueuedLayers.get(childPosition);
190
- }
191
- return mLayers.get(childPosition);
192
- }
193
-
194
- protected void addLayerToMap(MLRNLayer layer, int childPosition) {
195
- if (mMapView == null || layer == null) {
196
- return;
197
- }
198
-
199
- layer.addToMap(mMapView);
200
- if (!mLayers.contains(layer)) {
201
- mLayers.add(childPosition, layer);
202
- }
203
- }
204
-
205
- protected void removeLayerFromMap(MLRNLayer layer, int childPosition) {
206
- if (mMapView != null && layer != null) {
207
- layer.removeFromMap(mMapView);
208
- }
209
- if (mQueuedLayers != null && mQueuedLayers.size() > 0) {
210
- mQueuedLayers.remove(childPosition);
211
- } else {
212
- mLayers.remove(childPosition);
213
- }
214
- }
215
-
216
- public Style getStyle() {
217
- if (mMap == null) return null;
218
- return mMap.getStyle();
219
- }
220
-
221
- public abstract T makeSource();
222
-
223
- static public class OnPressEvent {
224
- public List<Feature> features;
225
- public LatLng latLng;
226
- public PointF screenPoint;
227
-
228
- public OnPressEvent(@NonNull List<Feature> features, @NonNull LatLng latLng, @NonNull PointF screenPoint) {
229
- this.features = features;
230
- this.latLng = latLng;
231
- this.screenPoint = screenPoint;
232
- }
233
- }
234
-
235
- public abstract void onPress(OnPressEvent event);
236
-
237
- public static boolean isDefaultSource(String sourceID) {
238
- return DEFAULT_ID.equals(sourceID);
239
- }
240
- }