sublayers property
Collection of MapShapeSublayer, MapLineLayer, MapPolylineLayer, MapPolygonLayer, MapCircleLayer, and MapArcLayer.
It is applicable for both the MapShapeLayer and MapTileLayer.
late MapShapeSource _mapSource;
late List<DataModel> _data;
int _selectedIndex = -1;
@override
void initState() {
_mapSource = MapShapeSource.asset(
'assets/india.json',
shapeDataField: 'name',
);
_data = <DataModel>[
DataModel(MapLatLng(28.7041, 77.1025), MapLatLng(11.1271, 78.6569)),
DataModel(MapLatLng(28.7041, 77.1025), MapLatLng(9.9312, 76.2673)),
DataModel(MapLatLng(28.7041, 77.1025), MapLatLng(15.3173, 75.7139)),
DataModel(MapLatLng(28.7041, 77.1025), MapLatLng(18.1124, 79.0193)),
];
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Line layer')),
body: Column(
children: [
Container(
child: SfMaps(
layers: [
MapShapeLayer(
source: _mapSource,
sublayers: [
MapLineLayer(
lines: List<MapLine>.generate(
_data.length,
(int index) {
return MapLine(
from: _data[index].from,
to: _data[index].to,
dashArray: [8, 3, 4, 2],
color: _selectedIndex == index
? Colors.red
: Colors.blue,
width: 2,
onTap: () {
setState(() {
_selectedIndex = index;
});
});
},
).toSet(),
),
],
),
],
),
),
],
),
);
}
class DataModel {
DataModel(this.from, this.to);
MapLatLng from;
MapLatLng to;
}
Implementation
final List<MapSublayer>? sublayers;