Carflow车流

向场景中添加沿路径持续运动的车辆模型

参数包括坐标线串,单/双向,车道数,车道宽,车距,是否随机排列...

img

方法

批量添加车流

  • 方法名:add
  • 参数说明:
// 方法
add(
  carFlow: CarFlowOptions | Array<CarFlowOptions>,
  groupId: string
): this

// CarFlowOptions 参数说明
export type CarFlowOptions = {
  id: string;
  coordinates: Array<Array<number>>; // 三维坐标数组[[x,y,z],[x,y,z]]
  twoSide?: boolean; // 是否双向通行,默认false
  splineLoop?: boolean; // 是否循环,默认false
  lanesNumber?: number; //单侧车道数量,默认1;
  lanesWidth?: number; //正向车道宽度,默认300;
  twoSideWidth?: number; // 双向车道宽度,默认300;
  forwardInterval?: number; // 正向车道间隔,默认1000;
  reverseInterval?: number; // 反向车道间隔,默认1000;
  randomBool?: boolean; // 是否随机,默认false
  runOnTheGround?: boolean; // 是否在地面运行,默认false
};
  • 示例参考:
function addCarFlow() {
  const height = 50
  const coordinates = [
    [121.98339118135789, 40.78112801815573],
    [121.98501014184853, 40.78028156251776],
    [121.98674474237538, 40.77952266208578],
    [121.98925027647016, 40.778238349294895],
    [121.99190999727796, 40.77683725247533],
    [121.99376023783958, 40.775903171512454],
    [121.99503227822453, 40.77537774519914],
    [121.99611158521986, 40.77473555183937],
    [121.99534065165199, 40.77377225016042],
    [121.99522501161726, 40.772984083853004],
    [121.99657414536028, 40.77245863445356],
    [121.99792327910325, 40.771670452562546],
    [121.99738362560635, 40.77056114369191],
    [121.99672833207319, 40.76965616747478],
    [121.99599594518514, 40.768809565662934],
    [121.99522501161726, 40.76761262745487],
    [121.99422279798, 40.76641566768768],
    [121.99349041109036, 40.76559821935987],
    [121.9926809308443, 40.7644304185925],
    [121.99156307717226, 40.76305822647021],
    [121.99083069028262, 40.76186118467422],
    [121.99005975671474, 40.76107287708393],
    [121.9891433043257, 40.75982614195408],
    [121.98831270718216, 40.75895023117104],
    [121.98820429677767, 40.75844521675015],
    [121.98901087167371, 40.757977789294614],
    [121.98784071936865, 40.75654093996698],
    [121.98974265876217, 40.755599019380696],
    [121.99150543308895, 40.75469297908634],
    [121.99334228141947, 40.75381044253638]
  ]
  const carflowinstance: any = {
    id: `carflow1`,
    coordinates: coordinates.map((item) => {
      return [...item, height]
    }),
    forwardInterval: 3000,
    lanesNumber: 2,
    twoSide: true
  }
  const polysline: PolylineOptions = {
    id: `polyline1s`,
    coordinates: coordinates.map((item) => {
      return [...item, height - 10]
    }),
    width: 2,
    color: 'rgba(0,255,0,1)',
    style: PolylineStyle.ARROW,
    splineType: PolylineType.LINEAR,
    meshDirection: PolylineDirection.GROUND_CENTER
  }
  viewer.carFlow.add([carflowinstance], 'carflowlayer')
  viewer.polyline.add([polysline], 'testlayer')
}

全部车流移除

  • 移除场景中全部车流
  • 方法名:clear
  • 参数说明:
/**
   * 清除全部车流
   * @returns
   */
clear(): this
  • 示例参考
function clearCarFlow() {
  viewer.carFlow.clear()
}

根据id移除车流

  • 根据id移除场景中的车流
  • 方法名:clearById
  • 参数说明:
/**
   * 传入id(单个或数组)清除车流
   * @param id
   * @returns
   */
clearById(id: string | Array<string>): this
  • 示例参考
function clearCarFlowById() {
  viewer.carFlow.clearById('carflow1')
}

根据分组id移除车流

  • 根据groupId移除场景中的车流
  • 方法名:clearByGroup
  • 参数说明:
/**
   * 传入groupId(单个或数组)清除车流
   * @param groupId
   * @returns
   */
  clearByGroup(groupId: string | Array<string>): this
  • 示例参考
function clearCarFlowByGroup() {
  viewer.carFlow.clearByGroup('carflowlayer')
}

全部车流显示/隐藏

  • 场景中全部车流显示/隐藏
  • 方法名:setCarFlowVisible
  • 参数说明:
  /**
   * 设置全体可见性
   * @param visible
   * @returns
   */
  setCarFlowVisible(visible = true):
  • 示例参考
function hideCarflow() {
  viewer.carFlow.setCarFlowVisible(false)
}

根据id显示/隐藏车流

  • 根据id显示/隐藏车流
  • 方法名:setCarFlowVisibleById
  • 参数说明:
/**
   * 传入id(单个或数组)设置可见性
   * @param id
   * @param visible
   * @returns
   */
setCarFlowVisibleById(id: string | Array<string>, visible = true): this
  • 示例参考
function showCarflowById() {
  viewer.carFlow.setCarFlowVisibleById('carflow1', true)
}

根据分组id移除车流

  • 根据groupId显示/隐藏车流
  • 方法名:clearByGroup
  • 参数说明:
/**
   * 传入groupId(单个或数组)设置可见性
   * @param groupId
   * @param visible
   * @returns
   */
setCarFlowVisibleByGroup(
  groupId: string | Array<string>,
  visible = true
): this
  • 示例参考
function hideCarflowByGroup() {
  viewer.carFlow.setCarFlowVisibleByGroup('carflowlayer', false)
}
上次更新:
贡献者: liuhe_ay