h18857377611 2021-11-20 22:50 采纳率: 25%
浏览 39
已结题

vue-amap的marker点单击高亮

我使用vue-amap组件显示marker点,部分代码如下

<el-amap-marker v-for="marker in markers" :key="marker.index" :position="marker.position" :events="marker.events" ></el-amap-marker>

#####点击高亮的思路
我的思路是点击之后修改icon的样式,但该如何使得下次点击后前一次的图标变回蓝色呢
在下方method方法中的显示marker的方法中,点击事件e.target.setIcon(afticon);成功在点击后变换红色图标,结果如下

img


在vue的method中的部分代码

Point() {
      let markers = [];
      let windows1 = [];
      let srcLists1=[];
      let myicon=[];
      let that = this;
      let afticon=new AMap.Icon({
        //size: new AMap.Size(30, 35),//图标大小
        imageSize:new AMap.Size(35, 35),
        //image: "../../static/5.png"
        image: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-red.png"
      });
      let beficon=new AMap.Icon({
        //size: new AMap.Size(19, 31),//图标大小
        imageSize:new AMap.Size(28, 28),
        //image:"../../static/7.png"
        image: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-blue.png"
      });
      //let showed=e.target.setIcon(afticon);
      this.CollectPoint.forEach((item, index) => {
        markers.push({
          position: item.position,
          offset: new AMap.Pixel(-10, -10),
          icon:beficon, //不设置默认蓝色水滴
          events: {
            click(e) {
               //let showered=e.target.setIcon(afticon);
              that.srcList1 = that.srcLists1[index];
              // 方法:鼠标移动到点标记上,显示相应窗体
              that.windows1.forEach((window1) => {
                window1.visible = false; // 关闭窗体
              });
              that.window1 = that.windows1[index];
              that.$nextTick(() => {
                that.window1.visible = true;
                e.target.setIcon(afticon);
                that.$refs.map.$$getInstance().setZoomAndCenter(6,item.position)
              });
            },
          },
        });
        windows1.push({
          name:item.name,
          recorder:item.recorder,
          position: item.position,
          offset: [0, -20], // 窗体偏移
          showShadow: false,
          visible: false, // 初始是否显示
        });
        srcLists1.push({
          photos:item.url4,
          lont:item.lont,
          lat:item.lat,
          gaocheng:item.gaocheng,
          recorder:item.recorder,
          name:item.name,
          wea:item.weather,
          dtm:item.dtm,
          place:item.place,
        });
      });
      //  加点
      this.markers = markers;
      // 加弹窗
      this.windows1 = windows1;
      this.srcLists1 =srcLists1;
    }

但如何写使得点击下一个点之后,前一个点可以变回原来的蓝色图标,就是如何修改这个events中的click里的事件

  • 写回答

2条回答 默认 最新

  • 风雪一更 2021-11-22 09:35
    关注

    先循环this.markers,把坐标全都变蓝,然后再setIcon把点击的变红

    that.$nextTick(() => {
      that.window1.visible = true;
      that.markers.forEach(itemm=>{
        itemm.icon = beficon;
      })
      e.target.setIcon(afticon);
      that.$refs.map.$$getInstance().setZoomAndCenter(6,item.position)
    });
    
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 11月28日
  • 创建了问题 11月20日

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM