decodePolygon method
Decode polygon geometry
@docs: https://github.com/mapbox/vector-tile-spec/tree/master/2.1#4344-polygon-geometry-type
Implementation
List<List<List<List<int>>>> decodePolygon() {
int length = 0;
int commandId = 0;
int x = 0;
int y = 0;
bool isX = true;
List<List<List<List<int>>>> polygons = [];
List<List<List<int>>> coords = [];
List<List<int>> ring = [];
this.geometryList!.forEach((commandInt) {
if (length <= 0 || commandId == CommandID.ClosePath) {
Command command = Command.CommandInteger(command: commandInt);
commandId = command.id;
length = command.count;
if (commandId == CommandID.ClosePath) {
coords.add(ring.reversed.toList(growable: false));
ring = [];
}
} else if (commandId != CommandID.ClosePath) {
if (isX) {
x += Command.zigZagDecode(commandInt);
isX = false;
} else {
y += Command.zigZagDecode(commandInt);
ring.add([x, y]);
length -= 1;
isX = true;
}
}
if (length <= 0 && commandId == CommandID.LineTo) {
if (coords.isNotEmpty && this._isCCW(ring: ring)) {
polygons.add(coords);
coords = [];
}
}
});
polygons.add(coords);
return polygons;
}