polygonToLine function
Converts a Polygon to LineString or MultiLineString or a MultiPolygon to a FeatureCollection of LineString or MultiLineString. Returns FeatureCollection or Feature<LineString> or Feature<MultiLinestring> example:
var poly = Polygon(coordinates:
[
[
Position.of([125, -30]),
Position.of([145, -30]),
Position.of([145, -20]),
Position.of([125, -20]),
Position.of([125, -30])
]
]);
var line = polygonToLine(poly);
//addToMap
var addToMap = [line];
Implementation
GeoJSONObject polygonToLine(GeoJSONObject poly,
{Map<String, dynamic>? properties}) {
var geom = getGeom(poly);
properties =
properties ?? ((poly is Feature) ? poly.properties : <String, dynamic>{});
if (geom is Polygon) {
return _polygonToLine(geom, properties: properties);
} else if (geom is MultiPolygon) {
return _multiPolygonToLine(geom, properties: properties);
} else {
throw Exception("invalid poly");
}
}