fromMap<T extends Object> static method

PolygonProperties<T> fromMap<T extends Object>(
  1. Map<String, dynamic>? properties,
  2. PolygonProperties<T> polygonLayerProperties
)

Creates a PolygonProperties instance from a map of properties.

The properties parameter is a map containing properties for customizing polygon rendering. It can be used to override the default properties specified in the polygonLayerProperties.

Example:

Map<String, dynamic> customProperties = {
  'fillColor': '#FFA500', // Override fill color
  'label': 'Custom Label', // Override label
  // Add more custom properties as needed
};

PolygonProperties properties = PolygonProperties.fromMap(
  customProperties,
  PolygonProperties(),
);

Implementation

static PolygonProperties<T> fromMap<T extends Object>(
  Map<String, dynamic>? properties,
  PolygonProperties<T> polygonLayerProperties,
) {
  Map<LayerPolygonIndexes, String>? layerProperties =
      polygonLayerProperties.layerProperties;
  if (properties != null && layerProperties != null) {
    // fill
    final String? keyPropertieFillColor =
        layerProperties[LayerPolygonIndexes.fillColor];
    bool isFilledMap = keyPropertieFillColor != null;
    String hexString = '${properties[keyPropertieFillColor]}';
    Color? polyLayProp = polygonLayerProperties.fillColor;
    final Color? fillColor = polyLayProp == null
        ? null
        : HexColor.fromHex(hexString, polyLayProp);
    // border color
    final String? layerPropertieBorderColor =
        layerProperties[LayerPolygonIndexes.borderColor];
    String hexString2 = '${properties[layerPropertieBorderColor]}';
    Color fall = polygonLayerProperties.borderColor;
    final Color borderColor = HexColor.fromHex(hexString2, fall);
    // border width
    String? layerPropertieBWidth =
        layerProperties[LayerPolygonIndexes.borderStokeWidth];
    // label
    final String? label = layerProperties[LayerPolygonIndexes.label];
    final bool labeled = properties[label] != null;
    bool isLabelled = labeled && polygonLayerProperties.labeled;
    String label2 = labeled
        ? '${properties[label]}'
        : polygonLayerProperties.label;
    return PolygonProperties<T>(
      isFilled: isFilledMap && polygonLayerProperties.isFilled,
      fillColor: fillColor,
      borderColor: borderColor,
      borderStokeWidth:
          (properties[layerPropertieBWidth] ??
                  polygonLayerProperties.borderStokeWidth)
              .toDouble(),
      label: label2,
      layerProperties: layerProperties,
      labeled: isLabelled,
      disableHolesBorder: polygonLayerProperties.disableHolesBorder,
      pattern: polygonLayerProperties.pattern,
      labelPlacementCalculator:
          polygonLayerProperties.labelPlacementCalculator,
      labelStyle: polygonLayerProperties.labelStyle,
      rotateLabel: polygonLayerProperties.rotateLabel,
      strokeCap: polygonLayerProperties.strokeCap,
      strokeJoin: polygonLayerProperties.strokeJoin,
    );
  } else {
    return polygonLayerProperties;
  }
}