MapLegend.bar constructor
- MapElement source, {
- bool shouldAlwaysShowScrollbar = false,
- Widget? title,
- MapLegendOverflowMode overflowMode = MapLegendOverflowMode.scroll,
- EdgeInsetsGeometry? padding = const EdgeInsets.all(10.0),
- MapLegendPosition position = MapLegendPosition.top,
- Offset? offset,
- double spacing = 2.0,
- Size? segmentSize,
- TextStyle? textStyle,
- Axis? direction,
- MapLegendLabelsPlacement? labelsPlacement,
- MapLegendEdgeLabelsPlacement edgeLabelsPlacement = MapLegendEdgeLabelsPlacement.inside,
- MapLabelOverflow labelOverflow = MapLabelOverflow.visible,
- MapLegendPaintingStyle segmentPaintingStyle = MapLegendPaintingStyle.solid,
- bool showPointerOnHover = false,
- MapLegendPointerBuilder? pointerBuilder,
- Color? pointerColor,
- Size pointerSize = const Size(16, 12),
Creates a bar type legend for the bubbles or shapes.
Information provided in the legend helps to identify the data rendered in the map shapes or bubbles.
Defaults to null
.
By default, legend will not be shown.
-
labelsPlacement - Places the labels either between the bar items or on the items. By default, labels placement will be MapLegendLabelsPlacement.betweenItems when setting range color mapping (MapColorMapper) without setting MapColorMapper.text property. In all other cases, it will be MapLegendLabelsPlacement.onItem.
-
edgeLabelsPlacement - Places the edge labels either inside or at center of the edges. It doesn't work with MapLegendLabelsPlacement.betweenItems. Defaults to MapLegendEdgeLabelsPlacement.inside.
-
segmentPaintingStyle - Option for setting solid or gradient color for the bar. To enable the gradient, set this as MapLegendPaintingStyle.gradient. Defaults to MapLegendPaintingStyle.solid.
-
labelOverflow - Option to trim or remove the legend item's text when it is overflowed. Defaults to MapLabelOverflow.hide.
Legend for shape
Set MapLegend.source to MapElement.shape to show legend for shapes.
If MapShapeSource.shapeColorMappers is not null, then MapColorMapper.color and MapColorMapper.text will be used for the legend item's icon and the legend item's text respectively.
If MapShapeSource.shapeColorMappers is null, the color returned in the MapShapeSource.shapeColorValueMapper will be applied to the legend item's icon and the legend item's text will be taken from the MapShapeSource.shapeDataField.
If both the MapShapeSource.shapeColorMappers and the MapShapeSource.shapeColorValueMapper properties are null, the legend item's text will be taken from the MapShapeSource.shapeDataField property and the legend item's icon will have the default color.
Legend for bubbles
Set MapLegend.source to MapElement.bubble to show legend for bubbles.
If MapShapeSource.bubbleColorMappers is not null, then MapColorMapper.color and MapColorMapper.text will be used for the legend item's icon and the legend item's text respectively.
If MapShapeSource.bubbleColorMappers is null, the color returned in the MapShapeSource.bubbleColorValueMapper will be applied to the legend item's icon and the legend item's text will be taken from the MapShapeSource.shapeDataField.
If both the MapShapeSource.bubbleColorMappers and the MapShapeSource.bubbleColorValueMapper properties are null, the legend item's text will be taken from the MapShapeSource.shapeDataField property and the legend item's icon will have the default color.
late List<DataModel> _data;
late MapShapeSource _mapSource;
@override
void initState() {
super.initState();
_data = <DataModel>[
DataModel('India', 280, "Low"),
DataModel('United States of America', 190, "High"),
DataModel('Pakistan', 37, "Low"),
];
_mapSource = MapShapeSource.asset(
"assets/world_map.json",
shapeDataField: "name",
dataCount: _data.length,
primaryValueMapper: (int index) {
return _data[index].country;
},
shapeColorValueMapper: (int index) {
return _data[index].storage;
},
shapeColorMappers: [
MapColorMapper(value: "Low", color: Colors.red),
MapColorMapper(value: "High", color: Colors.green)
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Bar legend'),
),
body: Center(
child: SfMaps(
layers: [
MapShapeLayer(
source: _mapSource,
legend: MapLegend.bar(MapElement.shape),
)
],
),
),
);
}
class DataModel {
const DataModel(this.country, this.count, this.storage);
final String country;
final double count;
final String storage;
}
See also:
MapLegend()
, for legend type with different styles like circle, diamond, rectangle and triangle.
Implementation
const MapLegend.bar(
this.source, {
this.shouldAlwaysShowScrollbar = false,
this.title,
this.overflowMode = MapLegendOverflowMode.scroll,
this.padding = const EdgeInsets.all(10.0),
this.position = MapLegendPosition.top,
this.offset,
this.spacing = 2.0,
this.segmentSize,
this.textStyle,
this.direction,
this.labelsPlacement,
this.edgeLabelsPlacement = MapLegendEdgeLabelsPlacement.inside,
this.labelOverflow = MapLabelOverflow.visible,
this.segmentPaintingStyle = MapLegendPaintingStyle.solid,
this.showPointerOnHover = false,
this.pointerBuilder,
this.pointerColor,
this.pointerSize = const Size(16, 12),
}) : _type = _LegendType.bar,
enableToggleInteraction = false,
toggledItemColor = null,
toggledItemStrokeColor = null,
toggledItemStrokeWidth = 0.0,
toggledItemOpacity = 0.0,
iconType = MapIconType.circle,
iconSize = const Size(8.0, 8.0),
assert(spacing >= 0);