实现路线规划,主要思路也比较简单,如下图
创建路线查询对象
const gaodeRoute = new mars3d.query.GaodeRoute({})
选择地点,包括起点、终点、途经点,并存储在数组中
const points = [[-95.712891,37.09024],[117.225025,31.809225]]
使用
queryDriving
方法查询gaodeRoute.queryDriving({
points: positionArr,
avoidpolygons: [],
extensions: "all",
strategy: "0", // 默认为0 ,速度优先
success: (data: any) => {
if (!data || data.paths.length < 1) {
return
}
drawLine(data.paths[0].points)
}
})
使用 mars3d 画出路线
function drawLine(points: any) {
lineGraphic = new mars3d.graphic.PolylineEntity({
positions: points,
style: {
clampToGround: true,
material: Cesium.Color.AQUA.withAlpha(0.8),
width: 5
}
})
graphicLayer.addGraphic(lineGraphic)
}