@maplibre/maplibre-react-native 10.0.0-beta.14 → 10.0.0-beta.15

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.
@@ -6,6 +6,8 @@ import com.facebook.react.bridge.WritableArray;
6
6
  import com.facebook.react.bridge.WritableMap;
7
7
  import com.facebook.react.bridge.WritableNativeArray;
8
8
  import com.facebook.react.bridge.WritableNativeMap;
9
+ import com.google.gson.JsonObject;
10
+
9
11
  import org.maplibre.geojson.Feature;
10
12
  import org.maplibre.geojson.FeatureCollection;
11
13
  import org.maplibre.geojson.Geometry;
@@ -19,23 +21,34 @@ import org.maplibre.geojson.Polygon;
19
21
  import org.maplibre.android.geometry.LatLng;
20
22
  import org.maplibre.android.geometry.LatLngBounds;
21
23
  import org.maplibre.android.geometry.LatLngQuad;
22
- import org.maplibre.android.style.light.Position;
24
+ import org.maplibre.android.log.Logger;
23
25
  import org.maplibre.turf.TurfMeasurement;
24
26
 
25
27
  import java.util.ArrayList;
26
28
  import java.util.List;
29
+ import java.util.stream.Collectors;
27
30
 
28
31
  public class GeoJSONUtils {
32
+ public static final String LOG_TAG = "GeoJSONUtils";
33
+
29
34
  public static WritableMap fromFeature(Feature feature) {
30
35
  WritableMap map = Arguments.createMap();
31
36
  map.putString("type", "Feature");
32
37
  map.putString("id", feature.id());
33
38
 
34
- WritableMap geometry = fromGeometry(feature.geometry());
35
- map.putMap("geometry", geometry);
39
+ Geometry geometry = feature.geometry();
40
+ if (geometry == null) {
41
+ map.putNull("geometry");
42
+ } else {
43
+ map.putMap("geometry", fromGeometry(geometry));
44
+ }
36
45
 
37
- WritableMap properties = ConvertUtils.toWritableMap(feature.properties());
38
- map.putMap("properties", properties);
46
+ JsonObject properties = feature.properties();
47
+ if(properties == null) {
48
+ map.putNull("properties");
49
+ } else {
50
+ map.putMap("properties", ConvertUtils.toWritableMap(properties));
51
+ }
39
52
 
40
53
  return map;
41
54
  }
@@ -43,22 +56,20 @@ public class GeoJSONUtils {
43
56
  public static WritableMap fromGeometry(Geometry geometry) {
44
57
  final String type = geometry.type();
45
58
 
46
- switch (type) {
47
- case "Point":
48
- return fromPoint((Point) geometry);
49
- case "LineString":
50
- return fromLineString((LineString) geometry);
51
- case "Polygon":
52
- return fromPolygon((Polygon) geometry);
53
- case "MultiPoint":
54
- return fromMultiPoint((MultiPoint) geometry);
55
- case "MultiLineString":
56
- return fromMultiLineString((MultiLineString) geometry);
57
- case "MultiPolygon":
58
- return fromMultiPolygon((MultiPolygon) geometry);
59
- default:
60
- return null;
61
- }
59
+ return switch (type) {
60
+ case "Point" -> fromPoint((Point) geometry);
61
+ case "LineString" -> fromLineString((LineString) geometry);
62
+ case "Polygon" -> fromPolygon((Polygon) geometry);
63
+ case "MultiPoint" -> fromMultiPoint((MultiPoint) geometry);
64
+ case "MultiLineString" -> fromMultiLineString((MultiLineString) geometry);
65
+ case "MultiPolygon" -> fromMultiPolygon((MultiPolygon) geometry);
66
+ case "GeometryCollection" -> fromGeometryCollection((GeometryCollection) geometry);
67
+ default -> {
68
+ Logger.w(LOG_TAG, "GeoJSONUtils.fromGeometry unsupported type: \"" + type + "\"");
69
+
70
+ yield null;
71
+ }
72
+ };
62
73
  }
63
74
 
64
75
  public static WritableMap fromPoint(Point point) {
@@ -103,6 +114,23 @@ public class GeoJSONUtils {
103
114
  return map;
104
115
  }
105
116
 
117
+ public static WritableMap fromGeometryCollection(GeometryCollection geometryCollection) {
118
+ WritableMap map = Arguments.createMap();
119
+ map.putString("type", "GeometryCollection");
120
+
121
+ map.putArray("geometries",
122
+ Arguments.fromList(
123
+ geometryCollection
124
+ .geometries()
125
+ .stream()
126
+ .map(GeoJSONUtils::fromGeometry)
127
+ .collect(Collectors.toList())
128
+ )
129
+ );
130
+
131
+ return map;
132
+ }
133
+
106
134
  public static WritableArray getCoordinates(Point point) {
107
135
  return Arguments.fromArray(pointToDoubleArray(point));
108
136
  }
@@ -122,9 +150,6 @@ public class GeoJSONUtils {
122
150
  WritableArray array = Arguments.createArray();
123
151
 
124
152
  List<List<Point>> points = polygon.coordinates();
125
- if (points == null) {
126
- return array;
127
- }
128
153
 
129
154
  for (List<Point> curPoint : points) {
130
155
  WritableArray innerArray = Arguments.createArray();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maplibre/maplibre-react-native",
3
3
  "description": "React Native library for creating maps with MapLibre Native for Android & iOS",
4
- "version": "10.0.0-beta.14",
4
+ "version": "10.0.0-beta.15",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": true