高德地图移除marker 清除marker

vue yekong

高德地图移除代码

that.map.remove(that.markerList);

添加marker

      this.potList.forEach(item => {
        // 根据type判断icon类型
        // 1 隧道 2服务区 3收费站 4 管理中心 5 互通
        var staticLine = [];
        item.spotList.forEach((type) => {
          if (type.spotType != 0) {
            var marker = new AMap.Marker({
              position: [type.longitude, type.latitude],
              map: that.map,
              extData: type,
              extData2: item,
              icon: new AMap.Icon({
                image: that.filterData(type.spotType),
                imageSize: new AMap.Size(68, 93),
                size: new AMap.Size(68, 93)
              })
            });
            that.map.add(marker);
            that.markerList.push(marker)
            marker.on('click', that.markerClick)
          }
          staticLine.push([type.longitude, type.latitude])
        });

清除旧marker并添加新的marker

initMarker() {
      var that = this;
      that.map.remove(that.markerList);
      that.markerList = []
      this.potList.forEach(item => {
        item.spotList.forEach((type) => {
          if (type.spotType == this.mapActive) {
            var marker = new AMap.Marker({
              position: [type.longitude, type.latitude],
              map: that.map,
              extData: type,
              extData2: item,
              icon: new AMap.Icon({
                image: that.filterData(type.spotType),
                imageSize: new AMap.Size(68, 93),
                size: new AMap.Size(68, 93)
              })
            });
            that.markerList.push(marker)
            that.map.add(marker);
            marker.on('click', that.markerClick)
          }
        });
      })
      // that.map.setFitView();
    },
喜欢