Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: VectorSource onPress returning null geometry on Android #555

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import org.maplibre.geojson.FeatureCollection;
import org.maplibre.geojson.Geometry;
import org.maplibre.geojson.GeometryCollection;
import org.maplibre.geojson.MultiLineString;
import org.maplibre.geojson.LineString;
import org.maplibre.geojson.MultiPoint;
import org.maplibre.geojson.Point;
import org.maplibre.geojson.MultiPolygon;
import org.maplibre.geojson.Polygon;
import org.maplibre.android.geometry.LatLng;
import org.maplibre.android.geometry.LatLngBounds;
Expand Down Expand Up @@ -48,6 +50,12 @@ public static WritableMap fromGeometry(Geometry geometry) {
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;
}
Expand All @@ -74,6 +82,27 @@ public static WritableMap fromPolygon(Polygon polygon) {
return map;
}

public static WritableMap fromMultiPoint(MultiPoint multiPoint) {
WritableMap map = Arguments.createMap();
map.putString("type", "MultiPoint");
map.putArray("coordinates", getCoordinates(multiPoint));
return map;
}

public static WritableMap fromMultiLineString(MultiLineString multiLineString) {
WritableMap map = Arguments.createMap();
map.putString("type", "MultiLineString");
map.putArray("coordinates", getCoordinates(multiLineString));
return map;
}

public static WritableMap fromMultiPolygon(MultiPolygon multiPolygon) {
WritableMap map = Arguments.createMap();
map.putString("type", "MultiPolygon");
map.putArray("coordinates", getCoordinates(multiPolygon));
return map;
}

public static WritableArray getCoordinates(Point point) {
return Arguments.fromArray(pointToDoubleArray(point));
}
Expand Down Expand Up @@ -110,6 +139,57 @@ public static WritableArray getCoordinates(Polygon polygon) {
return array;
}

public static WritableArray getCoordinates(MultiPoint multiPoint) {
WritableArray array = Arguments.createArray();

List<Point> points = multiPoint.coordinates();
for (Point point : points) {
array.pushArray(Arguments.fromArray(pointToDoubleArray(point)));
}

return array;
}

public static WritableArray getCoordinates(MultiLineString multiLineString) {
WritableArray array = Arguments.createArray();

List<List<Point>> lines = multiLineString.coordinates();
for (List<Point> line : lines) {
WritableArray lineArray = Arguments.createArray();

for (Point point : line) {
lineArray.pushArray(Arguments.fromArray(pointToDoubleArray(point)));
}

array.pushArray(lineArray);
}

return array;
}

public static WritableArray getCoordinates(MultiPolygon multiPolygon) {
WritableArray array = Arguments.createArray();

List<List<List<Point>>> polygons = multiPolygon.coordinates();
for (List<List<Point>> polygon : polygons) {
WritableArray polygonArray = Arguments.createArray();

for (List<Point> ring : polygon) {
WritableArray ringArray = Arguments.createArray();

for (Point point : ring) {
ringArray.pushArray(Arguments.fromArray(pointToDoubleArray(point)));
}

polygonArray.pushArray(ringArray);
}

array.pushArray(polygonArray);
}

return array;
}

public static WritableMap toPointFeature(LatLng latLng, WritableMap properties) {
WritableMap map = new WritableNativeMap();
map.putString("type", "Feature");
Expand Down
Loading