decodeLineString method

List<List<List<int>>> decodeLineString()

Implementation

List<List<List<int>>> decodeLineString() {
  int length = 0;
  int commandId = 0;
  int x = 0;
  int y = 0;
  bool isX = true;
  List<List<List<int>>> coords = [];
  List<List<int>> ring = [];

  this.geometryList!.forEach((commandInt) {
    if (length <= 0) {
      Command command = Command.CommandInteger(command: commandInt);

      commandId = command.id;
      length = command.count;
    } 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) {
      coords.add(ring);
      ring = [];
    }
  });

  return coords;
}