|
@@ -141,6 +141,9 @@ export class SPolylineItem extends SGraphItem {
|
|
|
// 查询鼠标最近的索引
|
|
|
this.findNearestPoint(new SPoint(event.x, event.y));
|
|
|
// 增加点
|
|
|
+ if (this.curIndex < 0) {
|
|
|
+ this.findAddPos(new SPoint(event.x, event.y));
|
|
|
+ }
|
|
|
// 删除点
|
|
|
if (event.altKey && this.canHandle(this.curIndex)) {
|
|
|
this.pointList.splice(this.curIndex, 1);
|
|
@@ -250,14 +253,15 @@ export class SPolylineItem extends SGraphItem {
|
|
|
* @param p 鼠标点击点
|
|
|
* */
|
|
|
findAddPos(p: SPoint): void {
|
|
|
- let len = {
|
|
|
- MinDis: this.sceneDis
|
|
|
- },
|
|
|
+ let len = SMathUtil.pointToLine(
|
|
|
+ p,
|
|
|
+ new SLine(this.pointList[0], this.pointList[1])
|
|
|
+ ),
|
|
|
index = 0;
|
|
|
if (this.pointList.length > 2) {
|
|
|
- for (let i = 0; i < this.pointList.length - 1; i++) {
|
|
|
+ for (let i = 1; i < this.pointList.length - 1; i++) {
|
|
|
let dis = SMathUtil.pointToLine(
|
|
|
- new SPoint(p.x, p.y),
|
|
|
+ p,
|
|
|
new SLine(this.pointList[i], this.pointList[i + 1])
|
|
|
);
|
|
|
if (dis.MinDis < len.MinDis) {
|
|
@@ -265,10 +269,10 @@ export class SPolylineItem extends SGraphItem {
|
|
|
index = i;
|
|
|
}
|
|
|
}
|
|
|
- // @ts-ignore
|
|
|
+ }
|
|
|
+ if (len.MinDis < this.sceneDis) {
|
|
|
if (len.Point) {
|
|
|
- // @ts-ignore
|
|
|
- this.addPoint(new SPoint(len.Point.X, len.Point.Y), index);
|
|
|
+ this.addPoint(len.Point, index + 1);
|
|
|
}
|
|
|
}
|
|
|
} // Function findAddPos()
|