fromPoly static method
Converts a polygon
or polyline
element into a path
element. If converting a
polyline
, make sure to pass the isPolyline
attribute as true
.
Implementation
static XmlElement fromPoly(
XmlElement polylineTag, {
bool isPolyline = false,
}) {
final filterAttributes = [AttributeName.points];
final points = polylineTag.getAttribute(AttributeName.points);
final pointsArrayRaw = points != null ? points.split(',') : <String>[];
final pointsArray = <String>[];
for (var i = 0; i < pointsArrayRaw.length; i++) {
final split = pointsArrayRaw[i].split(' ');
for (var j = 0; j < split.length; j++) {
if (split[j].isNotEmpty) {
pointsArray.add(split[j]);
}
}
}
if (pointsArray.length.isEven) {
final buffer = StringBuffer();
for (var i = 0; i < pointsArray.length; i += 2) {
buffer
..write(i == 0 ? 'M ' : ' L ')
..write('${_stod(pointsArray[i])} ${_stod(pointsArray[i + 1])}');
}
if (!isPolyline) {
buffer.write(' Z');
}
return _buildPath(
buffer.toString(),
polylineTag,
filterAttributes,
);
} else {
return XmlElement(XmlName(ElementName.g));
}
}