@rnmapbox/maps 10.0.0-rc.5 → 10.0.0-rc.6

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 (24) hide show
  1. package/README.md +1 -1
  2. package/android/rctmgl/build.gradle +1 -1
  3. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLModule.kt +4 -3
  4. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLOfflineModule.kt +474 -405
  5. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/FeatureCollection.kt +10 -0
  6. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/Geometry.kt +22 -0
  7. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/JSONObject.kt +78 -0
  8. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/ReadableArray.kt +1 -1
  9. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/extensions/Value.kt +9 -0
  10. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/writeableMapArrayOf.kt +41 -0
  11. package/ios/RCTMGL-v10/RCTMGLOfflineModule.swift +283 -307
  12. package/lib/commonjs/components/MapView.js +9 -0
  13. package/lib/commonjs/components/MapView.js.map +1 -1
  14. package/lib/commonjs/components/VectorSource.js +2 -0
  15. package/lib/commonjs/components/VectorSource.js.map +1 -1
  16. package/lib/commonjs/modules/location/locationManager.js +4 -0
  17. package/lib/commonjs/modules/location/locationManager.js.map +1 -1
  18. package/lib/module/components/MapView.js +9 -0
  19. package/lib/module/components/MapView.js.map +1 -1
  20. package/lib/module/components/VectorSource.js +3 -0
  21. package/lib/module/components/VectorSource.js.map +1 -1
  22. package/lib/module/modules/location/locationManager.js +4 -0
  23. package/lib/module/modules/location/locationManager.js.map +1 -1
  24. package/package.json +1 -1
@@ -0,0 +1,10 @@
1
+ package com.mapbox.rctmgl.utils.extensions
2
+
3
+ import com.mapbox.geojson.FeatureCollection
4
+ import com.mapbox.geojson.GeometryCollection
5
+
6
+ fun FeatureCollection.toGeometryCollection(): GeometryCollection {
7
+ return GeometryCollection.fromGeometries(
8
+ this.features()!!.map { it.geometry() !! }
9
+ )
10
+ }
@@ -0,0 +1,22 @@
1
+ package com.mapbox.rctmgl.utils.extensions
2
+
3
+ import com.mapbox.geojson.BoundingBox
4
+ import com.mapbox.geojson.Geometry
5
+ import com.mapbox.geojson.Polygon
6
+ import com.mapbox.turf.TurfMeasurement
7
+ import org.json.JSONObject
8
+
9
+ fun Geometry.toJSONObject(): JSONObject? {
10
+ return JSONObject(this.toJson())
11
+ }
12
+
13
+ fun Geometry.calculateBoundingBox(): BoundingBox {
14
+ val storedBBox = bbox()
15
+ if (storedBBox != null) {
16
+ return storedBBox
17
+ }
18
+ val bbox = TurfMeasurement.bbox(this)
19
+ return BoundingBox.fromLngLats(
20
+ bbox[0], bbox[1], bbox[2], bbox[3]
21
+ )
22
+ }
@@ -0,0 +1,78 @@
1
+ package com.mapbox.rctmgl.utils.extensions
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.bridge.ReadableArray
5
+ import com.facebook.react.bridge.ReadableMap
6
+ import com.facebook.react.bridge.WritableMap
7
+ import com.mapbox.bindgen.Value
8
+ import com.mapbox.geojson.Geometry
9
+ import com.mapbox.geojson.Polygon
10
+ import com.mapbox.rctmgl.utils.Logger
11
+ import org.json.JSONArray
12
+ import org.json.JSONObject
13
+
14
+ fun JSONObject.toGeometry(): Geometry? {
15
+ when (this.optString("type")) {
16
+ "polygon" -> return Polygon.fromJson(this.toString())
17
+ else -> {
18
+ Logger.w("JSONObject", "Unexpected geometry: ${this.toString()}")
19
+ return null
20
+ }
21
+ }
22
+ }
23
+
24
+ fun JSONObject.toMapboxValue(): Value {
25
+ return Value.fromJson(this.toString()).value!!
26
+ }
27
+
28
+ fun JSONObject.toWritableMap(): WritableMap? {
29
+ val result = Arguments.createMap()
30
+ val iterator = keys()
31
+ while (iterator.hasNext()) {
32
+ val key = iterator.next()
33
+ val value = get(key)
34
+ if (value is JSONObject) {
35
+ result.putMap(key, value.toReadableMap());
36
+ } else if (value is JSONArray) {
37
+ result.putArray(key, value.toReadableArray());
38
+ } else if (value is Boolean) {
39
+ result.putBoolean(key, value);
40
+ } else if (value is Int) {
41
+ result.putInt(key, value);
42
+ } else if (value is Double) {
43
+ result.putDouble(key, value);
44
+ } else if (value is String) {
45
+ result.putString(key, value);
46
+ } else {
47
+ result.putString(key, value.toString());
48
+ }
49
+ }
50
+ return result
51
+ }
52
+
53
+ fun JSONObject.toReadableMap(): ReadableMap? {
54
+ return toWritableMap()
55
+ }
56
+
57
+ fun JSONArray.toReadableArray(): ReadableArray? {
58
+ val result = Arguments.createArray()
59
+ for (i in 0 until length()) {
60
+ val value: Any = get(i)
61
+ if (value is JSONObject) {
62
+ result.pushMap(value.toReadableMap())
63
+ } else if (value is JSONArray) {
64
+ result.pushArray(value.toReadableArray())
65
+ } else if (value is Boolean) {
66
+ result.pushBoolean(value)
67
+ } else if (value is Int) {
68
+ result.pushInt(value)
69
+ } else if (value is Double) {
70
+ result.pushDouble(value)
71
+ } else if (value is String) {
72
+ result.pushString(value)
73
+ } else {
74
+ result.pushString(value.toString())
75
+ }
76
+ }
77
+ return result
78
+ }
@@ -20,4 +20,4 @@ fun ReadableArray.toScreenCoordinate() : ScreenCoordinate {
20
20
  Logger.e("ReadableArray.toCoordinate","Cannot convert $this to point, 2 coordinates are required")
21
21
  }
22
22
  return ScreenCoordinate(getDouble(0), getDouble(1))
23
- }
23
+ }
@@ -0,0 +1,9 @@
1
+ package com.mapbox.rctmgl.utils.extensions
2
+
3
+ import com.mapbox.bindgen.Value
4
+ import org.json.JSONObject
5
+
6
+ fun Value.toJSONObject(): JSONObject? {
7
+ val jsonString = this.toJson()
8
+ return JSONObject(jsonString)
9
+ }
@@ -0,0 +1,41 @@
1
+ package com.mapbox.rctmgl.utils
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.bridge.WritableArray
5
+ import com.facebook.react.bridge.WritableMap
6
+
7
+ fun writableMapOf(vararg values: Pair<String, *>): WritableMap {
8
+ val map = Arguments.createMap()
9
+ for ((key, value) in values) {
10
+ when (value) {
11
+ null -> map.putNull(key)
12
+ is Boolean -> map.putBoolean(key, value)
13
+ is Double -> map.putDouble(key, value)
14
+ is Int -> map.putInt(key, value)
15
+ is Long -> map.putInt(key, value.toInt())
16
+ is String -> map.putString(key, value)
17
+ is WritableMap -> map.putMap(key, value)
18
+ is WritableArray -> map.putArray(key, value)
19
+ else -> throw IllegalArgumentException("Unsupported value type ${value::class.java.name} for key [$key]")
20
+ }
21
+ }
22
+ return map
23
+ }
24
+
25
+ fun writableArrayOf(vararg values: Any): WritableArray {
26
+ val array = Arguments.createArray()
27
+ for (value in values) {
28
+ when (value) {
29
+ null -> array.pushNull()
30
+ is Boolean -> array.pushBoolean(value)
31
+ is Double -> array.pushDouble(value)
32
+ is Int -> array.pushInt(value)
33
+ is Long -> array.pushInt(value.toInt())
34
+ is String -> array.pushString(value)
35
+ is WritableMap -> array.pushMap(value)
36
+ is WritableArray -> array.pushArray(value)
37
+ else -> throw IllegalArgumentException("Unsupported value type ${value::class.java.name}")
38
+ }
39
+ }
40
+ return array
41
+ }