荣耀新人 2022-03-24 15:45 采纳率: 66.7%
浏览 123
已结题

openlayers的drawend事件对画圆的影响问题


addInteraction() {
      if (this.draw !== null) {
        this.map.removeInteraction(this.draw);
      }
      if (this.tool !== "None") {
        this.draw = new Draw({
          source: this.source,
          type: this.tool,
        });
        this.draw.on("drawend", (event) => {
          if (this.tool === "Circle") {
            let draws = event.feature.values_.geometry.flatCoordinates;
            let drawsCenter = transform(
              draws.splice(0, 2),
              "EPSG:3857",
              "EPSG:4326"
            );
            let drawEnd = transform(
              JSON.parse(JSON.stringify(draws)),
              "EPSG:3857",
              "EPSG:4326"
            );
            let from = turf.point(drawsCenter);1
            let to = turf.point(drawEnd);
            let options = { units: "kilometers" };
            let distance = turf.distance(from, to, options);
            this.listMapStringOne = this.drawCircle(
              [drawsCenter],
              distance * 1000
            );
          } else {
            let draws = event.feature.values_.geometry.flatCoordinates;
            let arr = new Array();
            let arrs = "";
            draws.forEach((item, index) => {
              arr.push(item);
              if (arr.length == 2) {
                arrs += `${String(
                  transform(arr, "EPSG:3857", "EPSG:4326")
                ).replace(",", " ")},`;
                arr = [];
              }
            });
            this.listMapStringTwo = `(${arrs.substring(0, arrs.length - 1)}),`;
          }
          this.listMapStrings();
        });
        this.map.addInteraction(this.draw);
      }
    },

为什么我第一次画圆不显示 第二次之后会显示 但是不在我画的点上
我知道在 if (this.tool === "Circle") 这个判断和上边的 drawend 事件上 但是我不知道原因

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 4月1日
    • 创建了问题 3月24日

    悬赏问题

    • ¥15 c#转安卓 java html
    • ¥15 os.listdir文件路径找不到
    • ¥15 使用gojs3.0,如何在nodeDataArray设置好text的位置,再go.TextBlock alignment中进行相应的改变
    • ¥15 psfusion图像融合指标很低
    • ¥15 银河麒麟linux系统如何修改/etc/hosts权限为777
    • ¥50 医院HIS系统代码、逻辑学习
    • ¥30 docker离线安装mysql报错,如何解决?
    • ¥15 构建工单的总账影响在哪里查询或修改
    • ¥15 三个简单项目写完之后有重赏之后联系我
    • ¥15 python报内存不能read错误