@maplibre/maplibre-react-native 11.0.0-alpha.26 → 11.0.0-alpha.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/org/maplibre/reactnative/MLRNPackage.kt +16 -1
- package/android/src/main/java/org/maplibre/reactnative/components/mapview/MLRNMapView.kt +20 -32
- package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNRasterSource.java +1 -1
- package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNSource.kt +228 -0
- package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNTileSource.java +0 -1
- package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNVectorSourceManager.java +2 -2
- package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/ClusterPropertyEntry.kt +5 -0
- package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/MLRNShapeSource.kt +232 -0
- package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/MLRNShapeSourceManager.kt +183 -0
- package/android/src/main/java/org/maplibre/reactnative/components/sources/shapesource/MLRNShapeSourceModule.kt +65 -0
- package/android/src/main/java/org/maplibre/reactnative/events/MapPressEvent.kt +1 -1
- package/android/src/main/java/org/maplibre/reactnative/events/MapPressEventWithFeatures.kt +24 -0
- package/android/src/main/java/org/maplibre/reactnative/utils/ConvertUtils.kt +203 -0
- package/android/src/main/java/org/maplibre/reactnative/utils/ExpressionParser.kt +70 -0
- package/android/src/main/java/org/maplibre/reactnative/utils/GeoJSONUtils.kt +37 -20
- package/ios/components/camera/MLRNCameraModule.mm +10 -20
- package/ios/components/map-view/MLRNMapViewModule.mm +10 -20
- package/ios/components/sources/MLRNSource.h +3 -0
- package/ios/components/sources/{MLRNShapeSource.h → shape-source/MLRNShapeSource.h} +3 -5
- package/ios/components/sources/{MLRNShapeSource.m → shape-source/MLRNShapeSource.m} +4 -12
- package/ios/components/sources/shape-source/MLRNShapeSourceComponentView.h +11 -0
- package/ios/components/sources/shape-source/MLRNShapeSourceComponentView.mm +163 -0
- package/ios/components/sources/shape-source/MLRNShapeSourceModule.h +5 -0
- package/ios/components/sources/shape-source/MLRNShapeSourceModule.mm +136 -0
- package/ios/utils/MLRNViewModuleUtils.h +35 -0
- package/ios/utils/MLRNViewModuleUtils.m +39 -0
- package/lib/commonjs/components/Images.js +1 -1
- package/lib/commonjs/components/Images.js.map +1 -1
- package/lib/commonjs/components/annotations/Annotation.js +1 -1
- package/lib/commonjs/components/annotations/Annotation.js.map +1 -1
- package/lib/commonjs/components/layers/BackgroundLayer.js.map +1 -1
- package/lib/commonjs/components/layers/CircleLayer.js.map +1 -1
- package/lib/commonjs/components/layers/FillExtrusionLayer.js.map +1 -1
- package/lib/commonjs/components/layers/HeatmapLayer.js.map +1 -1
- package/lib/commonjs/components/layers/RasterLayer.js.map +1 -1
- package/lib/commonjs/components/layers/SymbolLayer.js.map +1 -1
- package/lib/commonjs/components/map-view/MapView.js +16 -22
- package/lib/commonjs/components/map-view/MapView.js.map +1 -1
- package/lib/commonjs/components/sources/VectorSource.js +2 -2
- package/lib/commonjs/components/sources/VectorSource.js.map +1 -1
- package/lib/commonjs/components/sources/shape-source/NativeShapeSourceModule.js +9 -0
- package/lib/commonjs/components/sources/shape-source/NativeShapeSourceModule.js.map +1 -0
- package/lib/commonjs/components/sources/shape-source/ShapeSource.js +51 -0
- package/lib/commonjs/components/sources/shape-source/ShapeSource.js.map +1 -0
- package/lib/commonjs/components/sources/shape-source/ShapeSourceNativeComponent.ts +48 -0
- package/lib/commonjs/hooks/useAbstractLayer.js +2 -2
- package/lib/commonjs/hooks/useAbstractLayer.js.map +1 -1
- package/lib/commonjs/hooks/useFrozenId.js +16 -0
- package/lib/commonjs/hooks/useFrozenId.js.map +1 -0
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/modules/snapshot/SnapshotOptions.js.map +1 -1
- package/lib/commonjs/types/PressEventWithFeatures.js +6 -0
- package/lib/commonjs/types/PressEventWithFeatures.js.map +1 -0
- package/lib/commonjs/utils/animated/AbstractAnimatedCoordinates.js +0 -6
- package/lib/commonjs/utils/animated/AbstractAnimatedCoordinates.js.map +1 -1
- package/lib/commonjs/utils/animated/Animated.js +4 -4
- package/lib/commonjs/utils/animated/Animated.js.map +1 -1
- package/lib/commonjs/utils/animated/AnimatedExtractCoordinateFromArray.js +0 -6
- package/lib/commonjs/utils/animated/AnimatedExtractCoordinateFromArray.js.map +1 -1
- package/lib/commonjs/utils/animated/AnimatedPoint.js +0 -2
- package/lib/commonjs/utils/animated/AnimatedPoint.js.map +1 -1
- package/lib/commonjs/utils/animated/AnimatedShape.js +3 -16
- package/lib/commonjs/utils/animated/AnimatedShape.js.map +1 -1
- package/lib/commonjs/utils/findNodeHandle.js +16 -0
- package/lib/commonjs/utils/findNodeHandle.js.map +1 -0
- package/lib/commonjs/utils/{filterUtils.js → getFilter.js} +2 -2
- package/lib/commonjs/utils/getFilter.js.map +1 -0
- package/lib/commonjs/utils/index.js +3 -8
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/components/Images.js +1 -1
- package/lib/module/components/Images.js.map +1 -1
- package/lib/module/components/annotations/Annotation.js +1 -1
- package/lib/module/components/annotations/Annotation.js.map +1 -1
- package/lib/module/components/layers/BackgroundLayer.js.map +1 -1
- package/lib/module/components/layers/CircleLayer.js.map +1 -1
- package/lib/module/components/layers/FillExtrusionLayer.js.map +1 -1
- package/lib/module/components/layers/HeatmapLayer.js.map +1 -1
- package/lib/module/components/layers/RasterLayer.js.map +1 -1
- package/lib/module/components/layers/SymbolLayer.js.map +1 -1
- package/lib/module/components/map-view/MapView.js +3 -9
- package/lib/module/components/map-view/MapView.js.map +1 -1
- package/lib/module/components/sources/VectorSource.js +1 -1
- package/lib/module/components/sources/VectorSource.js.map +1 -1
- package/lib/module/components/sources/shape-source/NativeShapeSourceModule.js +5 -0
- package/lib/module/components/sources/shape-source/NativeShapeSourceModule.js.map +1 -0
- package/lib/module/components/sources/shape-source/ShapeSource.js +46 -0
- package/lib/module/components/sources/shape-source/ShapeSource.js.map +1 -0
- package/lib/module/components/sources/shape-source/ShapeSourceNativeComponent.ts +48 -0
- package/lib/module/hooks/useAbstractLayer.js +1 -1
- package/lib/module/hooks/useAbstractLayer.js.map +1 -1
- package/lib/module/hooks/useFrozenId.js +12 -0
- package/lib/module/hooks/useFrozenId.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/snapshot/SnapshotOptions.js.map +1 -1
- package/lib/module/types/PressEventWithFeatures.js +4 -0
- package/lib/module/types/PressEventWithFeatures.js.map +1 -0
- package/lib/module/utils/animated/AbstractAnimatedCoordinates.js +0 -7
- package/lib/module/utils/animated/AbstractAnimatedCoordinates.js.map +1 -1
- package/lib/module/utils/animated/Animated.js +4 -4
- package/lib/module/utils/animated/Animated.js.map +1 -1
- package/lib/module/utils/animated/AnimatedExtractCoordinateFromArray.js +0 -6
- package/lib/module/utils/animated/AnimatedExtractCoordinateFromArray.js.map +1 -1
- package/lib/module/utils/animated/AnimatedPoint.js +0 -3
- package/lib/module/utils/animated/AnimatedPoint.js.map +1 -1
- package/lib/module/utils/animated/AnimatedShape.js +3 -16
- package/lib/module/utils/animated/AnimatedShape.js.map +1 -1
- package/lib/module/utils/findNodeHandle.js +11 -0
- package/lib/module/utils/findNodeHandle.js.map +1 -0
- package/lib/module/utils/getFilter.js +9 -0
- package/lib/module/utils/getFilter.js.map +1 -0
- package/lib/module/utils/index.js +3 -8
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/commonjs/src/components/annotations/Annotation.d.ts +1 -1
- package/lib/typescript/commonjs/src/components/annotations/Annotation.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/layers/BackgroundLayer.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/layers/CircleLayer.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/layers/FillExtrusionLayer.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/layers/HeatmapLayer.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/layers/RasterLayer.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/layers/SymbolLayer.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/map-view/MapView.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/sources/VectorSource.d.ts +1 -1
- package/lib/typescript/commonjs/src/components/sources/VectorSource.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/sources/shape-source/NativeShapeSourceModule.d.ts +10 -0
- package/lib/typescript/commonjs/src/components/sources/shape-source/NativeShapeSourceModule.d.ts.map +1 -0
- package/lib/typescript/{module/src/components/sources → commonjs/src/components/sources/shape-source}/ShapeSource.d.ts +60 -41
- package/lib/typescript/commonjs/src/components/sources/shape-source/ShapeSource.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts +35 -0
- package/lib/typescript/commonjs/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/hooks/useFrozenId.d.ts +2 -0
- package/lib/typescript/commonjs/src/hooks/useFrozenId.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +4 -3
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/modules/snapshot/SnapshotOptions.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/MapLibreRNStyles.d.ts +1 -1
- package/lib/typescript/commonjs/src/types/MapLibreRNStyles.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/PressEvent.d.ts +0 -3
- package/lib/typescript/commonjs/src/types/PressEvent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/PressEventWithFeatures.d.ts +5 -0
- package/lib/typescript/commonjs/src/types/PressEventWithFeatures.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/animated/AbstractAnimatedCoordinates.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts +4 -1
- package/lib/typescript/commonjs/src/utils/animated/Animated.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/animated/AnimatedPoint.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/animated/AnimatedRouteCoordinatesArray.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/animated/AnimatedShape.d.ts +2 -2
- package/lib/typescript/commonjs/src/utils/animated/AnimatedShape.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/findNodeHandle.d.ts +3 -0
- package/lib/typescript/commonjs/src/utils/findNodeHandle.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/{filterUtils.d.ts → getFilter.d.ts} +2 -2
- package/lib/typescript/commonjs/src/utils/getFilter.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/index.d.ts +3 -3
- package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/module/src/components/annotations/Annotation.d.ts +1 -1
- package/lib/typescript/module/src/components/annotations/Annotation.d.ts.map +1 -1
- package/lib/typescript/module/src/components/layers/BackgroundLayer.d.ts.map +1 -1
- package/lib/typescript/module/src/components/layers/CircleLayer.d.ts.map +1 -1
- package/lib/typescript/module/src/components/layers/FillExtrusionLayer.d.ts.map +1 -1
- package/lib/typescript/module/src/components/layers/HeatmapLayer.d.ts.map +1 -1
- package/lib/typescript/module/src/components/layers/RasterLayer.d.ts.map +1 -1
- package/lib/typescript/module/src/components/layers/SymbolLayer.d.ts.map +1 -1
- package/lib/typescript/module/src/components/map-view/MapView.d.ts.map +1 -1
- package/lib/typescript/module/src/components/sources/VectorSource.d.ts +1 -1
- package/lib/typescript/module/src/components/sources/VectorSource.d.ts.map +1 -1
- package/lib/typescript/module/src/components/sources/shape-source/NativeShapeSourceModule.d.ts +10 -0
- package/lib/typescript/module/src/components/sources/shape-source/NativeShapeSourceModule.d.ts.map +1 -0
- package/lib/typescript/{commonjs/src/components/sources → module/src/components/sources/shape-source}/ShapeSource.d.ts +60 -41
- package/lib/typescript/module/src/components/sources/shape-source/ShapeSource.d.ts.map +1 -0
- package/lib/typescript/module/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts +35 -0
- package/lib/typescript/module/src/components/sources/shape-source/ShapeSourceNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/hooks/useFrozenId.d.ts +2 -0
- package/lib/typescript/module/src/hooks/useFrozenId.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +4 -3
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/modules/snapshot/SnapshotOptions.d.ts.map +1 -1
- package/lib/typescript/module/src/types/MapLibreRNStyles.d.ts +1 -1
- package/lib/typescript/module/src/types/MapLibreRNStyles.d.ts.map +1 -1
- package/lib/typescript/module/src/types/PressEvent.d.ts +0 -3
- package/lib/typescript/module/src/types/PressEvent.d.ts.map +1 -1
- package/lib/typescript/module/src/types/PressEventWithFeatures.d.ts +5 -0
- package/lib/typescript/module/src/types/PressEventWithFeatures.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/animated/AbstractAnimatedCoordinates.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/animated/Animated.d.ts +4 -1
- package/lib/typescript/module/src/utils/animated/Animated.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/animated/AnimatedPoint.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/animated/AnimatedRouteCoordinatesArray.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/animated/AnimatedShape.d.ts +2 -2
- package/lib/typescript/module/src/utils/animated/AnimatedShape.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/findNodeHandle.d.ts +3 -0
- package/lib/typescript/module/src/utils/findNodeHandle.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/{filterUtils.d.ts → getFilter.d.ts} +2 -2
- package/lib/typescript/module/src/utils/getFilter.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/index.d.ts +3 -3
- package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/components/Images.tsx +2 -2
- package/src/components/annotations/Annotation.tsx +2 -2
- package/src/components/layers/BackgroundLayer.tsx +1 -2
- package/src/components/layers/CircleLayer.tsx +1 -2
- package/src/components/layers/FillExtrusionLayer.tsx +1 -2
- package/src/components/layers/HeatmapLayer.tsx +1 -2
- package/src/components/layers/RasterLayer.tsx +1 -2
- package/src/components/layers/SymbolLayer.tsx +1 -2
- package/src/components/map-view/MapView.tsx +2 -14
- package/src/components/sources/VectorSource.tsx +2 -2
- package/src/components/sources/shape-source/NativeShapeSourceModule.ts +31 -0
- package/src/components/sources/shape-source/ShapeSource.tsx +235 -0
- package/src/components/sources/shape-source/ShapeSourceNativeComponent.ts +48 -0
- package/src/hooks/useAbstractLayer.ts +1 -1
- package/src/hooks/useFrozenId.ts +13 -0
- package/src/index.ts +4 -3
- package/src/modules/snapshot/SnapshotOptions.ts +3 -2
- package/src/types/MapLibreRNStyles.ts +1 -1
- package/src/types/PressEvent.ts +0 -4
- package/src/types/PressEventWithFeatures.ts +5 -0
- package/src/utils/animated/AbstractAnimatedCoordinates.ts +0 -9
- package/src/utils/animated/Animated.ts +12 -5
- package/src/utils/animated/AnimatedExtractCoordinateFromArray.ts +0 -9
- package/src/utils/animated/AnimatedPoint.ts +0 -2
- package/src/utils/animated/AnimatedRouteCoordinatesArray.ts +3 -3
- package/src/utils/animated/AnimatedShape.ts +7 -18
- package/src/utils/findNodeHandle.ts +14 -0
- package/src/utils/{filterUtils.ts → getFilter.ts} +2 -2
- package/src/utils/index.ts +12 -12
- package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNShapeSource.java +0 -248
- package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNShapeSourceManager.java +0 -216
- package/android/src/main/java/org/maplibre/reactnative/components/sources/MLRNSource.java +0 -240
- package/android/src/main/java/org/maplibre/reactnative/utils/ClusterPropertyEntry.java +0 -13
- package/android/src/main/java/org/maplibre/reactnative/utils/ConvertUtils.java +0 -246
- package/android/src/main/java/org/maplibre/reactnative/utils/ExpressionParser.java +0 -74
- package/ios/components/sources/MLRNShapeSourceManager.h +0 -6
- package/ios/components/sources/MLRNShapeSourceManager.m +0 -128
- package/lib/commonjs/components/sources/ShapeSource.js +0 -153
- package/lib/commonjs/components/sources/ShapeSource.js.map +0 -1
- package/lib/commonjs/utils/filterUtils.js.map +0 -1
- package/lib/module/components/sources/ShapeSource.js +0 -149
- package/lib/module/components/sources/ShapeSource.js.map +0 -1
- package/lib/module/utils/filterUtils.js +0 -9
- package/lib/module/utils/filterUtils.js.map +0 -1
- package/lib/typescript/commonjs/src/components/sources/ShapeSource.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/utils/filterUtils.d.ts.map +0 -1
- package/lib/typescript/module/src/components/sources/ShapeSource.d.ts.map +0 -1
- package/lib/typescript/module/src/utils/filterUtils.d.ts.map +0 -1
- 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
|
|
53
|
-
val
|
|
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
|
-
|
|
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 =
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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 =
|
|
222
|
-
|
|
223
|
-
|
|
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 =
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
|
|
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
|