多选框checkbox控制高德地图轨迹展示

效果图

点击表格某一行获取checkbox列表,通过选中多选框来展示选中的轨迹

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
先准备json数据,要包含name、轨迹线的颜色、check选中的数字(也就是id)
在这里插入图片描述

核心代码

drawLine() {
      let that = this;
      //获取选中的多选框id
      console.log(that.checkList);
      let lineColor = null;
      //绘制轨迹前先清除上一次的轨迹
      if (this.pathSimplifierIns) {
        this.pathSimplifierIns.setData([]);
      }
      AMapUI.load(
        ['ui/misc/PathSimplifier', 'lib/$'],
        function (PathSimplifier, $) {
          if (!PathSimplifier.supportCanvas) {
            alert('当前环境不支持 Canvas!');
            return;
          }
          //获取数据
          axios.get('/path.json').then((res) => {
            let data = res.data;
            that.list = [];
            for (var j = 0; j < data.length; j++) {
              that.checkList.forEach((item) => {
              //如果选中的id和返回的数据下标一致则向list中添加该条数据
                if (j == item) {
                
                  that.list.push(data[j]);
                }
              });
            }
            that.pathSimplifierIns = new PathSimplifier({
              zIndex: 100,
              //autoSetFitView:false,
              map: that.map, //所属的地图实例
              getPath: function (pathData, pathIndex) {
                return pathData.path;
              },
              //鼠标移入轨迹线所展示的内容
              getHoverTitle: function (pathData, pathIndex, pointIndex) {
                if (pointIndex >= 0) {
                  //point
                  return (
                    pathData.name +
                    ',点:' +
                    pointIndex +
                    '/' +
                    pathData.path.length
                  );
                }
                return pathData.name + ',点数量' + pathData.path.length;
              },
              轨迹线样式
              renderOptions: {
                getPathStyle: function (pathItem, zoom) {
                //设置每条轨迹线的颜色和线宽
                  var color = pathItem.pathData.color,
                    lineWidth = Math.round(4 * Math.pow(1.1, zoom - 3));
                  return {
                    pathLineStyle: {
                      lineWidth: lineWidth,
                      strokeStyle: color,
                      borderWidth: 1,
                      borderStyle: '#eeeeee',
                      dirArrowStyle: false,
                    },
                    //鼠标移入线的样式(此处清除移入样式)
                    pathLineHoverStyle: {
                      lineWidth: 0,
                      fillStyle: null,
                      strokeStyle: null,
                      borderStyle: null,
                    },
                  };
                },
              },
            });
            window.pathSimplifierIns = that.pathSimplifierIns;
            //设置数据
            that.pathSimplifierIns.setData(that.list);
          });
          // that.pathSimplifierIns.hide();
        }
      );
    },

各位客官要是感觉有用的话能留个小心心嘛,谢谢啦!!!^ v ^

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值