decode static method Null safety

SymbolLayer decode(
  1. String properties
)

Implementation

static SymbolLayer decode(String properties) {
  var map = json.decode(properties);
  if (map["layout"] == null) {
    map["layout"] = {};
  }
  if (map["paint"] == null) {
    map["paint"] = {};
  }
  return SymbolLayer(
    id: map["id"],
    sourceId: map["source"],
    sourceLayer: map["source-layer"],
    minZoom: map["minzoom"]?.toDouble(),
    maxZoom: map["maxzoom"]?.toDouble(),
    visibility: map["layout"]["visibility"] == null
        ? Visibility.VISIBLE
        : Visibility.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["layout"]["visibility"])),
    iconAllowOverlap: map["layout"]["icon-allow-overlap"],
    iconAnchor: map["layout"]["icon-anchor"] == null
        ? null
        : IconAnchor.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["layout"]["icon-anchor"])),
    iconIgnorePlacement: map["layout"]["icon-ignore-placement"],
    iconImage: map["layout"]["icon-image"],
    iconKeepUpright: map["layout"]["icon-keep-upright"],
    iconOffset: (map["layout"]["icon-offset"] as List?)
        ?.map<double?>((e) => e.toDouble())
        .toList(),
    iconOptional: map["layout"]["icon-optional"],
    iconPadding: map["layout"]["icon-padding"] is num?
        ? (map["layout"]["icon-padding"] as num?)?.toDouble()
        : null,
    iconPitchAlignment: map["layout"]["icon-pitch-alignment"] == null
        ? null
        : IconPitchAlignment.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["layout"]["icon-pitch-alignment"])),
    iconRotate: map["layout"]["icon-rotate"] is num?
        ? (map["layout"]["icon-rotate"] as num?)?.toDouble()
        : null,
    iconRotationAlignment: map["layout"]["icon-rotation-alignment"] == null
        ? null
        : IconRotationAlignment.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["layout"]["icon-rotation-alignment"])),
    iconSize: map["layout"]["icon-size"] is num?
        ? (map["layout"]["icon-size"] as num?)?.toDouble()
        : null,
    iconTextFit: map["layout"]["icon-text-fit"] == null
        ? null
        : IconTextFit.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["layout"]["icon-text-fit"])),
    iconTextFitPadding: (map["layout"]["icon-text-fit-padding"] as List?)
        ?.map<double?>((e) => e.toDouble())
        .toList(),
    symbolAvoidEdges: map["layout"]["symbol-avoid-edges"],
    symbolPlacement: map["layout"]["symbol-placement"] == null
        ? null
        : SymbolPlacement.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["layout"]["symbol-placement"])),
    symbolSortKey: map["layout"]["symbol-sort-key"] is num?
        ? (map["layout"]["symbol-sort-key"] as num?)?.toDouble()
        : null,
    symbolSpacing: map["layout"]["symbol-spacing"] is num?
        ? (map["layout"]["symbol-spacing"] as num?)?.toDouble()
        : null,
    symbolZOrder: map["layout"]["symbol-z-order"] == null
        ? null
        : SymbolZOrder.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["layout"]["symbol-z-order"])),
    textAllowOverlap: map["layout"]["text-allow-overlap"],
    textAnchor: map["layout"]["text-anchor"] == null
        ? null
        : TextAnchor.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["layout"]["text-anchor"])),
    textFont: (map["layout"]["text-font"] as List?)
        ?.map<String?>((e) => e.toString())
        .toList(),
    textIgnorePlacement: map["layout"]["text-ignore-placement"],
    textJustify: map["layout"]["text-justify"] == null
        ? null
        : TextJustify.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["layout"]["text-justify"])),
    textKeepUpright: map["layout"]["text-keep-upright"],
    textLetterSpacing: map["layout"]["text-letter-spacing"] is num?
        ? (map["layout"]["text-letter-spacing"] as num?)?.toDouble()
        : null,
    textLineHeight: map["layout"]["text-line-height"] is num?
        ? (map["layout"]["text-line-height"] as num?)?.toDouble()
        : null,
    textMaxAngle: map["layout"]["text-max-angle"] is num?
        ? (map["layout"]["text-max-angle"] as num?)?.toDouble()
        : null,
    textMaxWidth: map["layout"]["text-max-width"] is num?
        ? (map["layout"]["text-max-width"] as num?)?.toDouble()
        : null,
    textOffset: (map["layout"]["text-offset"] as List?)
        ?.map<double?>((e) => e.toDouble())
        .toList(),
    textOptional: map["layout"]["text-optional"],
    textPadding: map["layout"]["text-padding"] is num?
        ? (map["layout"]["text-padding"] as num?)?.toDouble()
        : null,
    textPitchAlignment: map["layout"]["text-pitch-alignment"] == null
        ? null
        : TextPitchAlignment.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["layout"]["text-pitch-alignment"])),
    textRadialOffset: map["layout"]["text-radial-offset"] is num?
        ? (map["layout"]["text-radial-offset"] as num?)?.toDouble()
        : null,
    textRotate: map["layout"]["text-rotate"] is num?
        ? (map["layout"]["text-rotate"] as num?)?.toDouble()
        : null,
    textRotationAlignment: map["layout"]["text-rotation-alignment"] == null
        ? null
        : TextRotationAlignment.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["layout"]["text-rotation-alignment"])),
    textSize: map["layout"]["text-size"] is num?
        ? (map["layout"]["text-size"] as num?)?.toDouble()
        : null,
    textTransform: map["layout"]["text-transform"] == null
        ? null
        : TextTransform.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["layout"]["text-transform"])),
    textVariableAnchor: (map["layout"]["text-variable-anchor"] as List?)
        ?.map<String?>((e) => e.toString())
        .toList(),
    textWritingMode: (map["layout"]["text-writing-mode"] as List?)
        ?.map<String?>((e) => e.toString())
        .toList(),
    iconColor: (map["paint"]["icon-color"] as List?)?.toRGBAInt(),
    iconHaloBlur: map["paint"]["icon-halo-blur"] is num?
        ? (map["paint"]["icon-halo-blur"] as num?)?.toDouble()
        : null,
    iconHaloColor: (map["paint"]["icon-halo-color"] as List?)?.toRGBAInt(),
    iconHaloWidth: map["paint"]["icon-halo-width"] is num?
        ? (map["paint"]["icon-halo-width"] as num?)?.toDouble()
        : null,
    iconOpacity: map["paint"]["icon-opacity"] is num?
        ? (map["paint"]["icon-opacity"] as num?)?.toDouble()
        : null,
    iconTranslate: (map["paint"]["icon-translate"] as List?)
        ?.map<double?>((e) => e.toDouble())
        .toList(),
    iconTranslateAnchor: map["paint"]["icon-translate-anchor"] == null
        ? null
        : IconTranslateAnchor.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["paint"]["icon-translate-anchor"])),
    textColor: (map["paint"]["text-color"] as List?)?.toRGBAInt(),
    textHaloBlur: map["paint"]["text-halo-blur"] is num?
        ? (map["paint"]["text-halo-blur"] as num?)?.toDouble()
        : null,
    textHaloColor: (map["paint"]["text-halo-color"] as List?)?.toRGBAInt(),
    textHaloWidth: map["paint"]["text-halo-width"] is num?
        ? (map["paint"]["text-halo-width"] as num?)?.toDouble()
        : null,
    textOpacity: map["paint"]["text-opacity"] is num?
        ? (map["paint"]["text-opacity"] as num?)?.toDouble()
        : null,
    textTranslate: (map["paint"]["text-translate"] as List?)
        ?.map<double?>((e) => e.toDouble())
        .toList(),
    textTranslateAnchor: map["paint"]["text-translate-anchor"] == null
        ? null
        : TextTranslateAnchor.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["paint"]["text-translate-anchor"])),
  );
}