实现路线规划,主要思路也比较简单,如下图

    1. 创建路线查询对象

      1. const gaodeRoute = new mars3d.query.GaodeRoute({})
    2. 选择地点,包括起点、终点、途经点,并存储在数组中

      1. const points = [[-95.712891,37.09024],[117.225025,31.809225]]
    3. 使用 queryDriving方法查询

      1. gaodeRoute.queryDriving({
      2. points: positionArr,
      3. avoidpolygons: [],
      4. extensions: "all",
      5. strategy: "0", // 默认为0 ,速度优先
      6. success: (data: any) => {
      7. if (!data || data.paths.length < 1) {
      8. return
      9. }
      10. drawLine(data.paths[0].points)
      11. }
      12. })
    4. 使用 mars3d 画出路线

      1. function drawLine(points: any) {
      2. lineGraphic = new mars3d.graphic.PolylineEntity({
      3. positions: points,
      4. style: {
      5. clampToGround: true,
      6. material: Cesium.Color.AQUA.withAlpha(0.8),
      7. width: 5
      8. }
      9. })
      10. graphicLayer.addGraphic(lineGraphic)
      11. }