defaultOnPolygon function
Default implementation for GeoJsonLayer.onPolygon. Parses object properties to determine polygon style. Those properties are supported:
fill
: fill color, as a material color name or a hexadecimal value.fill-opacity
: opacity, a floating-point number between 0.0 and 1.0.- Stroke options from defaultOnPolyline are also included for the polygon border.
Implementation
Polygon defaultOnPolygon(
List<LatLng> points, List<List<LatLng>>? holes, Map<String, dynamic> props,
{GeoJsonStyleDefaults? defaults}) {
defaults ??= GeoJsonStyleDefaults.initial;
Color? fill =
props.containsKey('fill') ? colorFromString(props['fill']) : null;
fill ??= defaults.fillColor;
dynamic opacity = props['fill-opacity'];
if (opacity is String) opacity = double.tryParse(opacity);
if (opacity is double && opacity >= 0.0 && opacity <= 1.0) {
fill = fill.withValues(alpha: opacity);
} else if (fill.a > 0.99) {
fill = fill.withValues(alpha: defaults.fillOpacity);
}
Color? stroke =
props.containsKey('stroke') ? colorFromString(props['stroke']) : null;
stroke ??= defaults.strokeColor;
dynamic sOpacity = props['stroke-opacity'];
if (sOpacity is String) sOpacity = double.tryParse(sOpacity);
if (sOpacity is double && sOpacity >= 0.0 && sOpacity <= 1.0) {
stroke = stroke.withValues(alpha: sOpacity);
} else if (stroke.a > 0.99) {
stroke = stroke.withValues(alpha: defaults.strokeOpacity);
}
dynamic width = props['stroke-width'];
if (width is String) width = double.tryParse(width);
return Polygon(
points: points,
holePointsList: holes,
color: fill,
borderColor: stroke,
borderStrokeWidth: width is num ? width.toDouble() : defaults.strokeWidth,
);
}