offset property
Places the marker position in additional to the given offset.
Defaults to Offset.zero.
late List<Model> data;
late MapShapeSource _mapSource;
@override
void initState() {
data = const <Model>[
Model('Brazil', -14.235004, -51.92528),
Model('Germany', 51.16569, 10.451526),
Model('Australia', -25.274398, 133.775136),
Model('India', 20.593684, 78.96288),
Model('Russia', 61.52401, 105.318756)
];
_mapSource = MapShapeSource.asset(
'assets/world_map.json',
shapeDataField: 'name',
dataCount: data.length,
primaryValueMapper: (int index) => data[index].country,
);
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
height: 350,
child: Padding(
padding: EdgeInsets.only(left: 15, right: 15),
child: SfMaps(
layers: <MapLayer>[
MapShapeLayer(
source: _mapSource,
initialMarkersCount: 5,
markerBuilder: (BuildContext context, int index) {
return MapMarker(
latitude: data[index].latitude,
longitude: data[index].longitude,
offset: Offset(20.0, 10.0),
);
},
),
],
),
),
)
),
);
}
class Model {
const Model(this.country, this.latitude, this.longitude);
final String country;
final double latitude;
final double longitude;
}
See also:
- MapShapeLayerController, MapTileLayerController for dynamically updating the markers.
Implementation
final Offset offset;