使用new mars3d.graphic.PolylinePrimitive({的时候报错 At least two positions are required.

问题:

1.使用new mars3d.graphic.PolylinePrimitive({的时候报错 At least two positions are required.

解决:

1.提示十分明确:坐标数量少于2个无法渲染线

此时参考mars3d官网的示例,传入指定数据在按需修改即可。

效果:

相关代码:

function addDemoGraphic1(graphicLayer) {

  const graphic = new mars3d.graphic.PolylinePrimitive({

    positions: [

      [117.220337, 31.832987],

      [117.220242, 31.835234],

      [117.216263, 31.835251],

      [117.217219, 31.819929],

      [117.223096, 31.818342],

      [117.249686, 31.818964],

      [117.263171, 31.816664],

      [117.278695, 31.816107],

      [117.279826, 31.804185],

      [117.286308, 31.804112],

      [117.28621, 31.801059]

    ],

    style: {

      width: 4,

      materialType: mars3d.MaterialType.LineTrail,

      materialOptions: {

        color: Cesium.Color.CHARTREUSE,

        speed: 5

      },

      clampToGround: true,

      label: {

        text: "我是线",

        font_size: 18,

        color: "#ffffff",

        distanceDisplayCondition: true,

        distanceDisplayCondition_far: 500000,

        distanceDisplayCondition_near: 0

      }

    },

    attr: { remark: "示例1" }

  })

  graphicLayer.addGraphic(graphic)

}

官网链接:

功能示例(Vue版) | Mars3D三维可视化平台 | 火星科技

相关api:

Mars3D三维可视化平台 | 火星科技

实现的效果是,按视距显示流动的线型效果。