routePlanningDraw static method
void
routePlanningDraw({
- required List<
PlanItem> itemList, - String? lineImgPath,
- Color? lineColor,
- String? pathlineId,
- required AMapUIController uiController,
- required AMapController mapController,
- OnComplete? onComplete,
线路规划 一键绘制 不建议使用一键绘制,最好使用线路规划接口获取点位后参考下面自己绘制
Implementation
static void routePlanningDraw({
required List<PlanItem> itemList,
String? lineImgPath,
Color? lineColor,
String? pathlineId,
required AMapUIController uiController,
required AMapController mapController,
OnComplete? onComplete,
}) {
List<LatLng> list = [];
for(int i =0;i<itemList.length;i++){
list.add(ToMLatLng.from(itemList[i].latLng));
}
//线路规划示例
AmapSearchUtil.routePlanning(
//最多支持18个点,第一个为起点,最后一个为终点,中间为途径点,
wayPoints: list,
callBack: (code, linePoints, bounds) {
//处理返回码不是1000的逻辑
if (code != 1000) return;
//code返回码==1000:成功
///绘制规划线
uiController.savePolyline(pathlineId??"planningLine", Polyline(
customTexture: lineImgPath!=null?BitmapDescriptor.fromIconPath(lineImgPath):null,
joinType: JoinType.round,
capType: CapType.round,
points: linePoints,
color: lineColor??Colors.blueAccent,
width: 6,
));
///利用MAP控制器移动相机到线路最大可视面积,边距50
mapController.moveCamera(CameraUpdate.newLatLngBounds(bounds, 50), duration: 1000);
///绘制关键点
for(int i=0;i< itemList.length;i++){
uiController.saveMarker(itemList[i].markerId??"planningPoint$i", Marker(
icon: itemList[i].iconPath==null?null:BitmapDescriptor.fromIconPath(itemList[i].iconPath!),
position: itemList[i].latLng,
infoWindow: InfoWindow(title: "第${i+1}个")
));
if(itemList[i].showScope){
///绘制一个scope米的电子围栏
uiController.savePolygon(itemList[i].scopeId??"scopePolygon$i", Polygon(
points: AmapUtil.getCirclePoints(center: itemList[i].latLng, radiusMi: itemList[i].scope),
joinType: JoinType.round,
fillColor: Colors.deepOrange.withOpacity(0.4),
strokeColor: Colors.cyan.withOpacity(0.6),
strokeWidth: 1,
));
}
if(i > 0 && itemList[i].showConnecting){
///绘制一条方向线 起终点连线
uiController.savePolyline(itemList[i].conineId??"connectingLine$i", Polyline(
joinType: JoinType.round,
capType: CapType.round,
points: [itemList[i-1].latLng, itemList[i].latLng],
color: Colors.red,
width: 1,
));
}
}
///绘制结束,刷新UI
uiController.refreshUI();
if(onComplete!=null) onComplete(itemList);
},
);
}