15.gis车辆轨迹回放之openlayers

本文描述了一个使用JavaScript和OpenLayers库实现的数据处理和地图上车辆轨迹动态绘制的应用,包括开始、暂停、恢复和停止车辆移动,以及显示和管理不同类型的标记点。

准备数据

// 含属性点位
var points = [];
//移动车辆速度
var moveSpeed = 500;//移动速度
//所有移动的坐标
var allMovePoints = [];
//所有移动的坐标索引
var allMovePointsIndex = [];
var movings = [];

操作

开始暂停恢复停止

export const start = (datas) => {
   
   
  if (datas && datas.length) {
   
   
    clean();
    addLayer()
    datas.forEach((items, index) => {
   
   
      allMovePointsIndex.push(0)
      let pointArray = [];
      if (items && items.length) {
   
   
        let pointindex = []
        items.forEach((item) => {
   
   
          if (item.LNG && item.LAT) {
   
   
            pointindex.push(item);
            pointArray.push([Number(item.LNG), Number(item.LAT)]);
          }
        });
        points.push(pointindex)
        if (pointArray && pointArray.length) {
   
   
          creatCarLine(pointArray, pointindex);
          createCarIcon(pointArray[0][0], pointArray[0][1], pointArray[1][0], pointArray[1][1], index);
          let allMovePoint = getAllMovePoint(pointArray, 50);
          allMovePoints.push(allMovePoint)
          //进行移动
          let moving = setInterval(() => {
   
   
            showPoint(index)
          }, moveSpeed);
          movings.push(moving)
        }
      }
    })
  }
};


const removeLayer = (id) => {
   
   
  for (let layerTmp of window.$olMap.getLayers().getArray()) {
   
   
    if (layerTmp.get("id") === id) {
   
   
      window.$olMap.removeLayer(layerTmp);
    }
  }
};
const addLayer = () => {
   
   
  // 轨迹
  let vectorLayer = new VectorLayer({
   
   
    id: "carline",
    source: new VectorSource({
   
    features: [] }),
    style: new Style({
   
   
      stroke: new Stroke({
   
   
        width: 6,
        color: "blue",
      })
    })
  });

  // 活动轨迹
  let hdvectorLayer = new VectorLayer({
   
   
    id: "hdcarline",
    source: new VectorSource({
   
    features: [] }),
    style: new Style({
   
   
      stroke: new Stroke({
   
   
        width: 6,
        color: "black",
      })
    })
  });
  // 正常点
  let zcvectorLayer = new VectorLayer({
   
   
    id: "zcpointid",
    source: new VectorSource({
   
    features: [] }),
    style: function (feature
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

紫雪giser

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值