高德地图点标记切换大小

         let marker = [];
         //循环添加地图中的点标记
          res.result.equipments.forEach((item, index) => {
            var temp = new AMap.Marker({
              position: new AMap.LngLat(item.areaLongitude, item.areaLatitude),
              offset: new AMap.Pixel(-10, -10),
              icon: new AMap.Icon({
                size: new AMap.Size(40, 40), // 图标尺寸
                image: _this.picHttp + item.image,//绝对路径
                imageSize: new AMap.Size(40, 40)
              }),
              extData: {//自定义属性
                id: item.id,
                state: item.state
              },
              map: _this.map,
              clickable: true
            });
 
            marker.push(temp);
 
            AMap.event.addListener(temp, "click", function(e) {  //每个点标记的点击事件
              _this.showType = this.getExtData().state;
              _this.getWeatherStationById(this.getExtData().id);
              //获取点标记的自定义数据 this.getExtData()
              if (this.getExtData().state == 2) {
                _this.$router.push({
                  path: "/Camera",
                  query: { id: this.getExtData().id }
                });
              }
         
              if (_this.clickedMarker === e.target) return;    // 点击的是同一个Marker
              if (_this.clickedMarker) {
                // 把上次点击的Marker的样式恢复至原来模样
                _this.clickedMarker.setOffset(new AMap.Pixel(-10, -10));
                _this.clickedMarker.setIcon(
                  new AMap.Icon({
                    image: _this.images,
                    size: new AMap.Size(40, 40), //图标大小
                    imageSize: new AMap.Size(40, 40)
                  })
                );           
              }
              this.setIcon(
                new AMap.Icon({
                  image: _this.picHttp + item.image,
                  size: new AMap.Size(50, 50), //图标大小
                  imageSize: new AMap.Size(50, 50)
                })
              );
              e.target.setOffset(new AMap.Pixel(-18, -20));
              _this.clickedMarker = e.target;         //data中存储上一次点击事件
              _this.images = e.target.getIcon().B.image;//data中存储上一次点击事件中的图片
            });
          });

posted on 2019-12-25 17:52  Dong1995  阅读(1306)  评论(0编辑  收藏  举报

导航