MapShapeSource class Null safety

The source that maps the data source with the shape file and provides data for the elements of the shape layer like data labels, bubbles, tooltip, and shape colors.

The source can be set as the .json file from an asset bundle, network or from Uint8List as bytes. Use the respective constructor depends on the type of the source.

The MapShapeSource.shapeDataField property is used to refer the unique field name in the .json file to identify each shapes and map with the respective data in the data source.

By default, the value specified for the MapShapeSource.shapeDataField in the GeoJSON file will be used in the elements like data labels, tooltip, and legend for their respective shapes.

However, it is possible to keep a data source and customize these elements based on the requirement. The value of the MapShapeSource.shapeDataField will be used to map with the respective data returned in MapShapeSource.primaryValueMapper from the data source.

Once the above mapping is done, you can customize the elements using the APIs like MapShapeSource.dataLabelMapper, MapShapeSource.shapeColorMappers, etc.

late MapShapeSource _mapSource;
late List<Model> _data;

@override
void initState() {
  _data = <Model>[
   Model('India', 280, "Low"),
   Model('United States of America', 190, "High"),
   Model('Pakistan', 37, "Low"),
  ];

  _mapSource = MapShapeSource.asset(
    'assets/world_map.json',
    shapeDataField: 'name',
    dataCount: _data.length,
    primaryValueMapper: (int index) {
      return _data[index].country;
    },
    dataLabelMapper: (int index) {
      return _data[index].country;
    },
  );

  super.initState();
}

@override
Widget build(BuildContext context) {
  return
    SfMaps(
      layers: [
        MapShapeLayer(
          source: _mapSource,
          showDataLabels: true,
       )
    ],
  );
}

class Model {
 const Model(this.country, this.count, this.storage);

 final String country;
 final double count;
 final String storage;
}

See also:

Inheritance

Constructors

MapShapeSource.asset(String name, {String? shapeDataField, int dataCount = 0, IndexedStringValueMapper? primaryValueMapper, List<MapColorMapper>? shapeColorMappers, List<MapColorMapper>? bubbleColorMappers, IndexedStringValueMapper? dataLabelMapper, IndexedDoubleValueMapper? bubbleSizeMapper, IndexedColorValueMapper? shapeColorValueMapper, IndexedColorValueMapper? bubbleColorValueMapper})
Creates a layer using the .json file from an asset bundle. [...]
const
MapShapeSource.memory(Uint8List bytes, {String? shapeDataField, int dataCount = 0, IndexedStringValueMapper? primaryValueMapper, List<MapColorMapper>? shapeColorMappers, List<MapColorMapper>? bubbleColorMappers, IndexedStringValueMapper? dataLabelMapper, IndexedDoubleValueMapper? bubbleSizeMapper, IndexedColorValueMapper? shapeColorValueMapper, IndexedColorValueMapper? bubbleColorValueMapper})
Creates a layer using the GeoJSON source as bytes from Uint8List. [...]
const
MapShapeSource.network(String src, {String? shapeDataField, int dataCount = 0, IndexedStringValueMapper? primaryValueMapper, List<MapColorMapper>? shapeColorMappers, List<MapColorMapper>? bubbleColorMappers, IndexedStringValueMapper? dataLabelMapper, IndexedDoubleValueMapper? bubbleSizeMapper, IndexedColorValueMapper? shapeColorValueMapper, IndexedColorValueMapper? bubbleColorValueMapper})
Creates a layer using the .json file from the network. [...]
const

Properties

bubbleColorMappers List<MapColorMapper>?
Collection of MapColorMapper which specifies bubble's color based on the data. [...]
final
bubbleColorValueMapper IndexedColorValueMapper?
Returns a color or value based on which bubble color will be updated. [...]
final
bubbleSizeMapper IndexedDoubleValueMapper?
Returns a value based on which bubble size will be calculated. [...]
final
dataCount int
Length of the data source.
final
dataLabelMapper IndexedStringValueMapper?
Returns the data label text for each shape. [...]
final
hashCode int
The hash code for this object. [...]
read-only, inherited
primaryValueMapper IndexedStringValueMapper?
Returns the the primary value for the every data in the data source collection. [...]
final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
shapeColorMappers List<MapColorMapper>?
Collection of MapColorMapper which specifies shape's color based on the data. [...]
final
shapeColorValueMapper IndexedColorValueMapper?
Returns a color or value based on which shape color will be updated. [...]
final
shapeDataField String?
Field name in the .json file to identify each shape. [...]
final

Methods

debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children. [...]
@protected, inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep. [...]
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object. [...]
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants. [...]
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object. [...]
inherited
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode. [...]
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited