Skip to content

Commit

Permalink
feat: implement fromGeometryCollection in GeoJSONUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
KiwiKilian committed Dec 15, 2024
1 parent 250ee6f commit b1f53fd
Showing 1 changed file with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
import org.maplibre.android.geometry.LatLng;
import org.maplibre.android.geometry.LatLngBounds;
import org.maplibre.android.geometry.LatLngQuad;
import org.maplibre.android.style.light.Position;
import org.maplibre.android.log.Logger;
import org.maplibre.turf.TurfMeasurement;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class GeoJSONUtils {
public static final String LOG_TAG = "GeoJSONUtils";

public static WritableMap fromFeature(Feature feature) {
WritableMap map = Arguments.createMap();
map.putString("type", "Feature");
Expand All @@ -43,22 +46,20 @@ public static WritableMap fromFeature(Feature feature) {
public static WritableMap fromGeometry(Geometry geometry) {
final String type = geometry.type();

switch (type) {
case "Point":
return fromPoint((Point) geometry);
case "LineString":
return fromLineString((LineString) geometry);
case "Polygon":
return fromPolygon((Polygon) geometry);
case "MultiPoint":
return fromMultiPoint((MultiPoint) geometry);
case "MultiLineString":
return fromMultiLineString((MultiLineString) geometry);
case "MultiPolygon":
return fromMultiPolygon((MultiPolygon) geometry);
default:
return null;
}
return switch (type) {
case "Point" -> fromPoint((Point) geometry);
case "LineString" -> fromLineString((LineString) geometry);
case "Polygon" -> fromPolygon((Polygon) geometry);
case "MultiPoint" -> fromMultiPoint((MultiPoint) geometry);
case "MultiLineString" -> fromMultiLineString((MultiLineString) geometry);
case "MultiPolygon" -> fromMultiPolygon((MultiPolygon) geometry);
case "GeometryCollection" -> fromGeometryCollection((GeometryCollection) geometry);
default -> {
Logger.w(LOG_TAG, "GeoJSONUtils.fromGeometry unsupported type: \"" + type + "\"");

yield null;
}
};
}

public static WritableMap fromPoint(Point point) {
Expand Down Expand Up @@ -103,6 +104,23 @@ public static WritableMap fromMultiPolygon(MultiPolygon multiPolygon) {
return map;
}

public static WritableMap fromGeometryCollection(GeometryCollection geometryCollection) {
WritableMap map = Arguments.createMap();
map.putString("type", "GeometryCollection");

map.putArray("geometries",
Arguments.fromList(
geometryCollection
.geometries()
.stream()
.map(GeoJSONUtils::fromGeometry)
.collect(Collectors.toList())
)
);

return map;
}

public static WritableArray getCoordinates(Point point) {
return Arguments.fromArray(pointToDoubleArray(point));
}
Expand Down

0 comments on commit b1f53fd

Please sign in to comment.