高德地图画社区网格

// 获取所有网格
    getGrids() {
      this.$http
        .request({
          url: "/rbac/admin/org/info/findOrgListByLevel",
          method: "POST",
          data: {
            orgLevel: 6,
            pageSize: -1,
            pageNo: 1,
          },
        })
        .then((res) => {
          // console.log(res);
          if (res.code == 200 && res.content) {
            this.getGridEchart(res.content.list);
          } else {
            this.$message({
              message: "暂无网格",
              type: "warning",
            });
          }
        });
    },

// 画网格
    getGridEchart(data) {
      if (this.polygons2.length > 0) {
        this.myMap.remove(this.polygons2);
        this.polygons2 = [];
      }
      data.forEach((item, index) => {
        if (item.pointPosition) {
          let polygonArr = [];
          item.pointPosition.split(",").forEach((e) => {
            polygonArr.push(e.split(":"));
          });
          if (index < 100) {
            if (index < 10) {
              index = "00" + index;
            } else {
              index = "0" + index;
            }
          }
          let color = "#" + index + "5EC";
          let polygon = new AMap.Polygon({
            map: this.myMap,
            path: polygonArr, //设置多边形边界路径
            strokeColor: "#fee", //线颜色
            strokeOpacity: 0.5, //线透明度
            strokeWeight: 1, //线宽
            fillColor: color, //填充色
            fillOpacity: 0.5, //填充透明度
            extData: {
              name: item.label,
            },
          });
          let that = this;
          //变色
          polygon.on("mouseover", function (e) {
            // console.log(e);
            this.setOptions({
              strokeOpacity: 1, //线透明度
              strokeWeight: 2, //线宽
              fillOpacity: 1, //填充透明度
            });
            that.sText = new AMap.Text({
              text: item.label,
              anchor: "center", // 设置文本标记锚点
              draggable: false,
              cursor: "pointer",
              angle: 10,
              style: {
                "text-align": "center",
                "font-size": "12px",
                "background-color": "transparent",
                border: "none",
                "z-index": "-1",
              },
              zIndex: -1,
              position: that.getCenterPoint(polygonArr),
            });
            that.sText.setMap(that.myMap);
          });
          polygon.on("mouseout", function () {
            this.setOptions({
              strokeOpacity: 0.5, //线透明度
              strokeWeight: 1, //线宽
              fillOpacity: 0.5, //填充透明度
            });
            if (that.sText) {
              that.myMap.remove(that.sText);
              that.sText = "";
            }
          });
          this.polygons2.push(polygon);
        }
      });
      // console.log(this.polygons2);
      this.myMap.add(this.polygons2);
    },

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值