Skip to content

Commit

Permalink
fix: improve nullable checks in GeoJSONUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
KiwiKilian committed Dec 15, 2024
1 parent b1f53fd commit 926029f
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap;
import com.google.gson.JsonObject;

import org.maplibre.geojson.Feature;
import org.maplibre.geojson.FeatureCollection;
import org.maplibre.geojson.Geometry;
Expand Down Expand Up @@ -34,11 +36,19 @@ public static WritableMap fromFeature(Feature feature) {
map.putString("type", "Feature");
map.putString("id", feature.id());

WritableMap geometry = fromGeometry(feature.geometry());
map.putMap("geometry", geometry);
Geometry geometry = feature.geometry();
if (geometry == null) {
map.putNull("geometry");
} else {
map.putMap("geometry", fromGeometry(geometry));
}

WritableMap properties = ConvertUtils.toWritableMap(feature.properties());
map.putMap("properties", properties);
JsonObject properties = feature.properties();
if(properties == null) {
map.putNull("properties");
} else {
map.putMap("properties", ConvertUtils.toWritableMap(properties));
}

return map;
}
Expand Down Expand Up @@ -140,9 +150,6 @@ public static WritableArray getCoordinates(Polygon polygon) {
WritableArray array = Arguments.createArray();

List<List<Point>> points = polygon.coordinates();
if (points == null) {
return array;
}

for (List<Point> curPoint : points) {
WritableArray innerArray = Arguments.createArray();
Expand Down

0 comments on commit 926029f

Please sign in to comment.