defaultOnPolyline function

Polyline<Object> defaultOnPolyline(
  1. List<LatLng> points,
  2. Map<String, dynamic> props, {
  3. GeoJsonStyleDefaults? defaults,
})

Default implementation for GeoJsonLayer.onPolyline. Parses object properties to determine polyline style. Those properties are supported:

  • stroke: line color, as a material color name or a hexadecimal value.
  • stroke-opacity: opacity, a floating-point number between 0.0 and 1.0.
  • stroke-width: line width in pixels.

Implementation

Polyline defaultOnPolyline(List<LatLng> points, Map<String, dynamic> props,
    {GeoJsonStyleDefaults? defaults}) {
  defaults ??= GeoJsonStyleDefaults.initial;

  Color? stroke =
      props.containsKey('stroke') ? colorFromString(props['stroke']) : null;
  stroke ??= defaults.strokeColor;

  dynamic opacity = props['stroke-opacity'];
  if (opacity is String) opacity = double.tryParse(opacity);
  if (opacity is double && opacity >= 0.0 && opacity <= 1.0) {
    stroke = stroke.withValues(alpha: opacity);
  } 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 Polyline(
    points: points,
    color: stroke,
    strokeWidth: width is num ? width.toDouble() : defaults.strokeWidth,
  );
}