projectList method
Projects a list of LatLngs into geometry coordinates.
All resulting points gather somehow around the first point, or the
optional referencePoint
if provided.
The typical use-case is when you display the whole world: you don't want
longitudes -179 and 179 to be projected each on one side.
referencePoint
is used for polygon holes: we want the holes to be
displayed close to the polygon, not on the other side of the world.
Implementation
List<Offset> projectList(List<LatLng> points, {LatLng? referencePoint}) {
late double previousX;
final worldWidth = getWorldWidth();
return List<Offset>.generate(
points.length,
(j) {
if (j == 0 && referencePoint != null) {
(previousX, _) = projectXY(referencePoint);
}
var (x, y) = projectXY(points[j]);
if (j > 0 || referencePoint != null) {
if (x - previousX > worldWidth / 2) {
x -= worldWidth;
} else if (x - previousX < -worldWidth / 2) {
x += worldWidth;
}
}
previousX = x;
return Offset(x, y);
},
growable: false,
);
}