MapShapeSublayer class
The shape sublayer for tile and shape layer.
This sublayer can be added as a sublayer of both MapShapeLayer and MapTileLayer.
The actual geographical rendering is done here using the MapShapeSublayer.source. The source can be set as the .json file from an asset bundle, network or from Uint8List as bytes.
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 source will be used in the elements like data labels, and tooltip 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.
The snippet below shows how to render the basic world map using the data from .json file.
late MapShapeSource _mapSource;
late MapShapeSource _mapSublayerSource;
@override
void initState() {
_mapSource = MapShapeSource.asset(
"assets/world_map.json",
shapeDataField: "name",
);
_mapSublayerSource = MapShapeSource.asset(
"assets/africa.json",
shapeDataField: "name",
);
super.initState();
}
@override
Widget build(BuildContext context) {
return SfMaps(
layers: [
MapShapeLayer(
source: _mapSource,
sublayers:[
MapShapeSublayer(
source: _mapSublayerSource,
color: Colors.red,
),
]
)
],
);
}
See also:
- source, to provide data for the elements of this layer like data labels, bubbles, tooltip, and shape colors.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- MapSublayer
- MapShapeSublayer
Constructors
-
MapShapeSublayer({Key? key, required MapShapeSource source, MapShapeLayerController? controller, int initialMarkersCount = 0, MapMarkerBuilder? markerBuilder, IndexedWidgetBuilder? shapeTooltipBuilder, IndexedWidgetBuilder? bubbleTooltipBuilder, IndexedWidgetBuilder? markerTooltipBuilder, int selectedIndex = -1, ValueChanged<
int> ? onSelectionChanged, bool showDataLabels = false, Color? color, Color? strokeColor, double? strokeWidth, MapDataLabelSettings dataLabelSettings = const MapDataLabelSettings(), MapBubbleSettings bubbleSettings = const MapBubbleSettings(), MapSelectionSettings selectionSettings = const MapSelectionSettings()}) -
Creates a MapShapeSublayer.
const
Properties
- bubbleSettings → MapBubbleSettings
-
Customizes the appearance of the bubbles.
final
- bubbleTooltipBuilder → IndexedWidgetBuilder?
-
Returns a widget for the bubble tooltip based on the index.
final
- color → Color?
-
Color which is used to paint the sublayer shapes.
final
- controller → MapShapeLayerController?
-
Provides option for adding, removing, deleting and updating marker
collection.
final
- dataLabelSettings → MapDataLabelSettings
-
Customizes the appearance of the data labels.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialMarkersCount → int
-
Option to set markers count initially. It cannot be updated dynamically.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- markerBuilder → MapMarkerBuilder?
-
Returns the MapMarker for the given index. Markers which be used to
denote the locations on the map.
final
- markerTooltipBuilder → IndexedWidgetBuilder?
-
Returns the widget for the tooltip of the MapMarker.
final
-
onSelectionChanged
→ ValueChanged<
int> ? -
Called when the user tapped or clicked on a shape.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selectedIndex → int
-
Selects the shape in the given index.
final
- selectionSettings → MapSelectionSettings
-
Customizes the appearance of the selected shape.
final
- shapeTooltipBuilder → IndexedWidgetBuilder?
-
Returns a widget for the shape tooltip based on the index.
final
- showDataLabels → bool
-
Shows or hides the data labels in the sublayer.
final
- source → MapShapeSource
-
The source that maps the data source with the shape file and provides
data for the elements of the this layer like data labels, bubbles,
tooltip, and shape colors.
final
- strokeColor → Color?
-
Color which is used to paint the stroke of the sublayer shapes.
final
- strokeWidth → double?
-
Sets the stroke width of the sublayer shapes.
final
- tooltipBuilder → IndexedWidgetBuilder?
-
Returns a widget for the map line tooltip based on the index.
finalinherited
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent 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, int wrapWidth = 65}) → 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 short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited