decodeSymbolRenderer static method
Decodes the object from a Map-like dynamic structure. This expects the JSON format to be of the following structure:
{
"dashPattern": <List<int>>,
"isSolid": <bool>,
"radius": <double>,
"strokeWidth": <double>,
"type": <"circle" | "icon" | "line" | "rect" | "rounded_rect" | "triangle">
}
Implementation
static common.SymbolRenderer? decodeSymbolRenderer(
dynamic map, {
bool validate = true,
}) {
common.SymbolRenderer? result;
if (result is common.SymbolRenderer) {
result = map;
} else if (map != null) {
assert(SchemaValidator.validate(
schemaId: '$_baseSchemaUrl/symbol_renderer',
value: map,
validate: validate,
));
final type = map['type'];
switch (type) {
case 'circle':
result = common.CircleSymbolRenderer(
isSolid: map['isSolid'] == null
? true
: JsonClass.parseBool(
map['isSolid'],
whenNull: true,
),
);
break;
case 'icon':
result = IconSymbolRenderer(
map['icon'],
JsonClass.parseDouble(
map['size'],
),
);
break;
case 'line':
result = common.LineSymbolRenderer(
dashPattern: map['dashPattern'] == null
? null
: List<int>.from(
map['dashPattern'].map((e) => JsonClass.parseInt(e)!),
),
isSolid: map['isSolid'] == null
? true
: JsonClass.parseBool(
map['isSolid'],
whenNull: true,
),
strokeWidth: JsonClass.parseDouble(map['strokeWidth']),
);
break;
case 'rect':
result = common.RectSymbolRenderer(
isSolid: map['isSolid'] == null
? true
: JsonClass.parseBool(
map['isSolid'],
whenNull: true,
),
);
break;
case 'rounded_rect':
result = common.RoundedRectSymbolRenderer(
isSolid: map['isSolid'] == null
? true
: JsonClass.parseBool(
map['isSolid'],
whenNull: true,
),
radius: JsonClass.parseDouble(map['radius']),
);
break;
case 'triangle':
result = common.TriangleSymbolRenderer(
isSolid: map['isSolid'] == null
? true
: JsonClass.parseBool(
map['isSolid'],
whenNull: true,
),
);
break;
default:
throw Exception('Unknown [SymbolRenderer.type] encountered: [$type]');
}
}
return result;
}