maptalks 单独移除图层 ,添加点击事件

vue-mapmalks单独移除图层 ,添加点击事件

图层

添加和移除

  添加图层1 this.layer = new maptalks.VectorLayer("vector").addTo(this.map);
  添加图层2 this.carlayer = new maptalks.VectorLayer("car").addTo(this.map);

根据自己需要,定义不同的图层,作者要清除 this.carlayer ,因为一个图层里面多个图片标注是无法区分操作的,所以定义了两个图层。
移除标注图层 this.map.removeLayer(this.carlayer);

标注点击事件带参数

setInfoWindow() 官方弹窗跳过

1.添加标注的时候把参数传进去
在这里插入图片描述
2.添加地图点击监听事件
this.map.on(“click”, function (e) {
console.log(e);
that.getData(e);
});
funtion getdata(e){
let that = this;
that.map.identify(
{
coordinate: e.coordinate,
layers: [that.carlayer], //应为独立处理carlayer 图层
},
function (geos) {
if (geos.length === 0) {
return;
}

        let carInfo = geos[0].properties.name;
        that
          .getCarInfo(carInfo)   //去调用后台接口返回自己要的数据
          .then(() => {
            var carAllContent = `<div class="custom_box"><div class="custom_title">${carInfo}--详细信息</div>
                                 <div class="custom_car_marker">
                                        <div>${carContent} <br>${crashContent} </div>
                                </div></div>`;

            that.mapPointList.forEach(function (p) {
              if (p.properties.name == carInfo) {
                p.setInfoWindow({
                  title: "",
                  content: carAllContent,
                  autoPan: true,
                  width: 300,
                  minHeight: 120,
                  custom: true,
                  autoOpenOn: "click",
                  autoCloseOn: "click",
                });
                p.openInfoWindow();
              }
            });
          });
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

神龙见首不见尾

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

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

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

打赏作者

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

抵扣说明:

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

余额充值