mars3d 和 turf结合使用——线相关分析

turf简介:
1、turf官网http://turfjs.org/
2、用于地理空间分析的js库,处理各种地图算法。

使用:
1、使用mars3d画一条简单的线

  lineLayer.startDraw({
    type: "polyline",
    style: {
      color: "#55ff33",
      width: 3,
      clampToGround: false
    }
  })

2、使用turf计算曲线


  let line = lineLayer.getGraphics() //获取地图上的线矢量数据
  if (line.length === 0) {
    globalMsg("请绘制线!")
    return
  }
  line = line[0].toGeoJSON()

  const curved = turf.bezierSpline(line)
  const positions = curved.geometry.coordinates

  const graphic = new mars3d.graphic.PolylineEntity({
    positions: positions,
    style: {
      width: 4,
      color: "#00ffff"
    }
  })
  graphicLayer.addGraphic(graphic)

3、计算平行线

let line = lineLayer.getGraphics()
  if (line.length === 0) {
    globalMsg("请绘制线!")
    return
  }
  line = line[0].toGeoJSON()

  graphicLayer.clear()

  const offsetLine = turf.lineOffset(line, distance, { units: "miles" })

  const positions = offsetLine.geometry.coordinates

  const graphic = new mars3d.graphic.PolylineEntity({
    positions: positions,
    style: {
      width: 4,
      color: "#ff0000"
    }
  })
  graphicLayer.addGraphic(graphic)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值