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 事件上 但是我不知道原因