addPolyline method
添加线
在点points
的位置添加线, 可以设置宽度width
和颜色strokeColor
Implementation
Future<void> addPolyline(
List<LatLng> points, {
double width,
Color strokeColor = Colors.black,
}) {
return platform(
android: (pool) async {
final map = await androidController.getMap();
// 构造折线点
List<com_amap_api_maps_model_LatLng> latLngList = [];
for (final point in points) {
final latLng = await ObjectFactory_Android
.createcom_amap_api_maps_model_LatLng__double__double(
point.lat, point.lng);
latLngList.add(latLng);
}
// 构造折线参数
final polylineOptions = await ObjectFactory_Android
.createcom_amap_api_maps_model_PolylineOptions__();
// 添加参数
await polylineOptions.addAll(latLngList);
if (width != null) {
await polylineOptions.width(width);
}
if (strokeColor != null) {
await polylineOptions
.color(Int32List.fromList([strokeColor.value])[0]);
}
// 设置参数
await map.addPolyline(polylineOptions);
pool
..add(map)
..add(polylineOptions)
..addAll(latLngList);
},
ios: (pool) async {
await iosController.set_delegate(IOSMapDelegate());
// 构造折线点
List<CLLocationCoordinate2D> latLngList = [];
for (final point in points) {
final latLng = await ObjectFactory_iOS.createCLLocationCoordinate2D(
point.lat, point.lng);
latLngList.add(latLng);
}
// 构造折线参数
final polyline = await MAPolyline.polylineWithCoordinatesCount(
latLngList, latLngList.length);
// 宽度和颜色需要设置到STACK里去
if (width != null)
await ObjectFactory_iOS.pushStackJsonable('width', width);
if (strokeColor != null)
await ObjectFactory_iOS.pushStackJsonable(
'strokeColor', strokeColor.value);
// 设置参数
await iosController.addOverlay(polyline);
pool
..add(polyline)
..addAll(latLngList);
},
);
}