TileLayer.fromJson constructor

TileLayer.fromJson(
  1. Map<String, dynamic> json
)

Implementation

TileLayer.fromJson(Map<String, dynamic> json) {
  height = double.tryParse(json['height'].toString()) ?? 0.0;
  width = double.tryParse(json['width'].toString()) ?? 0.0;
  encoding = json['encoding'];
  compression = json['compression'];

  if (encoding == 'base64') {
    final base64Raw = base64Decode(json['data']);
    switch (compression) {
      case 'zlib':
        data = zlib.decode(base64Raw);
        break;
      case 'gzip':
        data = gzip.decode(base64Raw);
        break;
      default:
        data = [];
        int index = 0;
        base64Raw.forEach((element) {
          if (index % 4 == 0) {
            data?.add(element);
          }
          index++;
        });
    }
  } else {
    data = json['data'].cast<int>();
  }

  setParamsFromJson(json);
}