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"]?.toDouble(),
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"]?.toDouble(),
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"]?.toDouble(),
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"]?.toDouble(),
symbolSpacing: map["layout"]["symbol-spacing"]?.toDouble(),
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"]?.toDouble(),
textLineHeight: map["layout"]["text-line-height"]?.toDouble(),
textMaxAngle: map["layout"]["text-max-angle"]?.toDouble(),
textMaxWidth: map["layout"]["text-max-width"]?.toDouble(),
textOffset: (map["layout"]["text-offset"] as List?)
?.map<double?>((e) => e.toDouble())
.toList(),
textOptional: map["layout"]["text-optional"],
textPadding: map["layout"]["text-padding"]?.toDouble(),
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"]?.toDouble(),
textRotate: map["layout"]["text-rotate"]?.toDouble(),
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"]?.toDouble(),
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"]?.toDouble(),
iconHaloColor: (map["paint"]["icon-halo-color"] as List?)?.toRGBAInt(),
iconHaloWidth: map["paint"]["icon-halo-width"]?.toDouble(),
iconOpacity: map["paint"]["icon-opacity"]?.toDouble(),
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"]?.toDouble(),
textHaloColor: (map["paint"]["text-halo-color"] as List?)?.toRGBAInt(),
textHaloWidth: map["paint"]["text-halo-width"]?.toDouble(),
textOpacity: map["paint"]["text-opacity"]?.toDouble(),
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"])),
);
}