GroupLayer.fromJson constructor

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

Implementation

GroupLayer.fromJson(Map<String, dynamic> json) {
  id = json['id'];
  name = json['name'];
  offsetX = double.tryParse(json['offsetx'].toString()) ?? 0.0;
  offsetY = double.tryParse(json['offsety'].toString()) ?? 0.0;
  type = json['type'].toString().getTypeLayer();
  visible = json['visible'];
  opacity = double.tryParse(json['opacity'].toString()) ?? 0.0;
  x = double.tryParse(json['x'].toString()) ?? 0.0;
  y = double.tryParse(json['y'].toString()) ?? 0.0;

  if (json['layers'] != null) {
    layers = <MapLayer>[];
    json['layers'].forEach((v) {
      if (v['type'] == TypeLayer.tilelayer.getName()) {
        layers?.add(TileLayer.fromJson(v));
      } else if (v['type'] == TypeLayer.objectgroup.getName()) {
        layers?.add(ObjectLayer.fromJson(v));
      } else if (v['type'] == TypeLayer.imagelayer.getName()) {
        layers?.add(ImageLayer.fromJson(v));
      } else if (v['type'] == TypeLayer.group.getName()) {
        layers?.add(GroupLayer.fromJson(v));
      } else {
        layers?.add(MapLayer.fromJson(v));
      }
    });
  }
}