|
@@ -27,12 +27,12 @@ const help = {
|
|
|
|
|
|
return [
|
|
|
itemsEntry.reduce((prev, [item, attr]) => {
|
|
|
- if (!item) return prev
|
|
|
- const selected = geoId === item.vectorId || (
|
|
|
- item.parent && Object.keys(item.parent).some(id => id === geoId)
|
|
|
- );
|
|
|
+ if (!item) return prev;
|
|
|
+ const selected =
|
|
|
+ geoId === item.vectorId ||
|
|
|
+ (item.parent && Object.keys(item.parent).some((id) => id === geoId));
|
|
|
if (selected && Style[attr]) {
|
|
|
- const style = Style[attr][geoType] || Style[attr][vector.category]
|
|
|
+ const style = Style[attr][geoType] || Style[attr][vector.category];
|
|
|
if (style) {
|
|
|
currentAttr = attr;
|
|
|
return style;
|
|
@@ -54,7 +54,7 @@ const help = {
|
|
|
}
|
|
|
},
|
|
|
setVectorStyle(ctx, vector, geoType = vector.geoType) {
|
|
|
- let styles, attr
|
|
|
+ let styles, attr;
|
|
|
if (Array.isArray(geoType)) {
|
|
|
for (const type of geoType) {
|
|
|
[styles, attr] = help.getVectorStyle(vector, type);
|
|
@@ -65,7 +65,7 @@ const help = {
|
|
|
} else {
|
|
|
[styles, attr] = help.getVectorStyle(vector, geoType);
|
|
|
}
|
|
|
- help.setStyle(ctx, styles)
|
|
|
+ help.setStyle(ctx, styles);
|
|
|
return [styles, attr];
|
|
|
},
|
|
|
transformCoves(lines) {
|
|
@@ -118,13 +118,13 @@ const help = {
|
|
|
},
|
|
|
getTextCenter(ctx, txt) {
|
|
|
const text = ctx.measureText(txt);
|
|
|
- const height = text.actualBoundingBoxAscent + text.actualBoundingBoxDescent
|
|
|
+ const height = text.actualBoundingBoxAscent + text.actualBoundingBoxDescent;
|
|
|
return {
|
|
|
width: text.width,
|
|
|
height,
|
|
|
x: text.width / 2,
|
|
|
- y: -height / 2
|
|
|
- }
|
|
|
+ y: -height / 2,
|
|
|
+ };
|
|
|
},
|
|
|
// 绘制圆角矩形
|
|
|
roundRect(ctx, x, y, width, height, radius) {
|
|
@@ -141,13 +141,15 @@ const help = {
|
|
|
ctx.closePath();
|
|
|
},
|
|
|
getRealDistance(p1, p2) {
|
|
|
- return Math.round(mathUtil.getDistance(p1, p2) * coordinate.res * 100) / 100
|
|
|
+ return (
|
|
|
+ Math.round(mathUtil.getDistance(p1, p2) * coordinate.res * 100) / 100
|
|
|
+ );
|
|
|
},
|
|
|
getPerpendicularPoint(p1, p2, p3, d) {
|
|
|
if (p1.x === p2.x) {
|
|
|
- return {x: p3.x + d, y: p3.y}
|
|
|
+ return { x: p3.x + d, y: p3.y };
|
|
|
} else if (p1.y === p2.y) {
|
|
|
- return {x: p3.x, y: p3.y + d}
|
|
|
+ return { x: p3.x, y: p3.y + d };
|
|
|
}
|
|
|
|
|
|
// 计算通过 p1 和 p2 的直线的斜率和截距
|
|
@@ -159,11 +161,12 @@ const help = {
|
|
|
const perpendicularIntercept = p3.y - perpendicularSlope * p3.x;
|
|
|
|
|
|
// 计算垂足点 p0
|
|
|
- const x = (perpendicularIntercept - intercept) / (slope - perpendicularSlope);
|
|
|
+ const x =
|
|
|
+ (perpendicularIntercept - intercept) / (slope - perpendicularSlope);
|
|
|
const y = slope * x + intercept;
|
|
|
const p0 = { x, y };
|
|
|
|
|
|
-// 计算点 p4
|
|
|
+ // 计算点 p4
|
|
|
const distance = d; // 指定距离
|
|
|
const dx = distance / Math.sqrt(1 + perpendicularSlope ** 2);
|
|
|
const dy = perpendicularSlope * dx;
|
|
@@ -171,16 +174,17 @@ const help = {
|
|
|
},
|
|
|
drawLineText(ctx, start, end, text, style) {
|
|
|
if (start.x > end.x) {
|
|
|
- [start, end] = [end, start]
|
|
|
+ [start, end] = [end, start];
|
|
|
}
|
|
|
|
|
|
- const angle = Math.atan2(end.y - start.y, end.x - start.x) * 180 / Math.PI;
|
|
|
- const center = mathUtil.lineCenter(start, end)
|
|
|
+ const angle =
|
|
|
+ (Math.atan2(end.y - start.y, end.x - start.x) * 180) / Math.PI;
|
|
|
+ const center = mathUtil.lineCenter(start, end);
|
|
|
|
|
|
ctx.save();
|
|
|
ctx.translate(center.x, center.y);
|
|
|
- ctx.rotate(angle * Math.PI / 180);
|
|
|
- const textCenter = help.getTextCenter(ctx, text)
|
|
|
+ ctx.rotate((angle * Math.PI) / 180);
|
|
|
+ const textCenter = help.getTextCenter(ctx, text);
|
|
|
const padding = style.padding;
|
|
|
help.roundRect(
|
|
|
ctx,
|
|
@@ -188,14 +192,14 @@ const help = {
|
|
|
textCenter.y - padding,
|
|
|
textCenter.width + 2 * padding,
|
|
|
textCenter.height + 2 * padding,
|
|
|
- (textCenter.height / 2) + padding
|
|
|
- )
|
|
|
- ctx.fillStyle = style.backColor
|
|
|
- ctx.fill()
|
|
|
- ctx.fillStyle = style.fillColor
|
|
|
+ textCenter.height / 2 + padding
|
|
|
+ );
|
|
|
+ ctx.fillStyle = style.backColor;
|
|
|
+ ctx.fill();
|
|
|
+ ctx.fillStyle = style.fillColor;
|
|
|
ctx.fillText(text, -textCenter.x, -textCenter.y);
|
|
|
ctx.restore();
|
|
|
- }
|
|
|
+ },
|
|
|
};
|
|
|
|
|
|
export default class Draw {
|
|
@@ -505,8 +509,8 @@ export default class Draw {
|
|
|
ctx.save();
|
|
|
|
|
|
const [style] = help.setVectorStyle(this.context, vector);
|
|
|
- if (vector.arrowColor) {
|
|
|
- ctx.strokeStyle = vector.arrowColor;
|
|
|
+ if (vector.color) {
|
|
|
+ ctx.strokeStyle = vector.color;
|
|
|
}
|
|
|
|
|
|
const dires =
|
|
@@ -615,19 +619,18 @@ export default class Draw {
|
|
|
}
|
|
|
const pt = coordinate.getScreenXY({ x: vector.x, y: vector.y });
|
|
|
const ctx = this.context;
|
|
|
- let [style, attr] = help.setVectorStyle(
|
|
|
- ctx,
|
|
|
- vector,
|
|
|
- [vector.category, vector.geoType, "Point"]
|
|
|
-
|
|
|
- );
|
|
|
+ let [style, attr] = help.setVectorStyle(ctx, vector, [
|
|
|
+ vector.category,
|
|
|
+ vector.geoType,
|
|
|
+ "Point",
|
|
|
+ ]);
|
|
|
if (vector.category === VectorCategory.Point.NormalPoint) {
|
|
|
- const lineid = Object.keys(vector.parent)[0]
|
|
|
- let line, style
|
|
|
+ const lineid = Object.keys(vector.parent)[0];
|
|
|
+ let line, style;
|
|
|
if (!(lineid && (line = dataService.getLine(lineid)))) {
|
|
|
return;
|
|
|
}
|
|
|
- const [_, attr] = help.getVectorStyle(line)
|
|
|
+ const [_, attr] = help.getVectorStyle(line);
|
|
|
if (!attr) {
|
|
|
return;
|
|
|
}
|
|
@@ -641,11 +644,11 @@ export default class Draw {
|
|
|
ctx.save();
|
|
|
ctx.beginPath();
|
|
|
ctx.arc(pt.x, pt.y, radius, 0, Math.PI * 2, true);
|
|
|
- help.setStyle(ctx, style)
|
|
|
+ help.setStyle(ctx, style);
|
|
|
ctx.stroke();
|
|
|
ctx.fill();
|
|
|
ctx.restore();
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
if (Settings.selectBasePointId === vector.vectorId) {
|
|
|
style = {
|
|
@@ -654,12 +657,12 @@ export default class Draw {
|
|
|
out: style.out && {
|
|
|
...style.out,
|
|
|
strokeStyle: "red",
|
|
|
- }
|
|
|
- }
|
|
|
+ },
|
|
|
+ };
|
|
|
}
|
|
|
- draw(style)
|
|
|
+ draw(style);
|
|
|
if (style.out) {
|
|
|
- draw(style.out)
|
|
|
+ draw(style.out);
|
|
|
}
|
|
|
|
|
|
if (import.meta.env.DEV) {
|
|
@@ -694,7 +697,9 @@ export default class Draw {
|
|
|
help.setVectorStyle(this.context, vector);
|
|
|
this.context.fillStyle = vector.color;
|
|
|
const oldFont = this.context.font;
|
|
|
- this.context.font = `${vector.fontSize * coordinate.ratio}px Microsoft YaHei`;
|
|
|
+ this.context.font = `${
|
|
|
+ vector.fontSize * coordinate.ratio
|
|
|
+ }px Microsoft YaHei`;
|
|
|
this.drawTextByInfo(vector.center, vector.value, 0, false);
|
|
|
|
|
|
const ctx = this.context;
|
|
@@ -715,7 +720,7 @@ export default class Draw {
|
|
|
coordinate.getScreenXY(endReal),
|
|
|
help.getRealDistance(startReal, endReal) + "m",
|
|
|
style
|
|
|
- )
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
drawBaseLineLabel(vector) {
|
|
@@ -724,10 +729,18 @@ export default class Draw {
|
|
|
const endReal = dataService.getPoint(vector.endId);
|
|
|
const end = coordinate.getScreenXY(endReal);
|
|
|
const point = mathUtil.translate(
|
|
|
- end, start, end, mathUtil.getDistance(start, end) / 3
|
|
|
- )
|
|
|
- const p4 = help.getPerpendicularPoint(start, end, point, 30 * coordinate.ratio)
|
|
|
- const ctx = this.context
|
|
|
+ end,
|
|
|
+ start,
|
|
|
+ end,
|
|
|
+ mathUtil.getDistance(start, end) / 3
|
|
|
+ );
|
|
|
+ const p4 = help.getPerpendicularPoint(
|
|
|
+ start,
|
|
|
+ end,
|
|
|
+ point,
|
|
|
+ 30 * coordinate.ratio
|
|
|
+ );
|
|
|
+ const ctx = this.context;
|
|
|
ctx.beginPath();
|
|
|
const [style] = help.setVectorStyle(
|
|
|
this.context,
|
|
@@ -738,7 +751,12 @@ export default class Draw {
|
|
|
ctx.lineTo(p4.x, p4.y);
|
|
|
ctx.stroke();
|
|
|
|
|
|
- const p5 = help.getPerpendicularPoint(start, end, point, 35 * coordinate.ratio)
|
|
|
+ const p5 = help.getPerpendicularPoint(
|
|
|
+ start,
|
|
|
+ end,
|
|
|
+ point,
|
|
|
+ 35 * coordinate.ratio
|
|
|
+ );
|
|
|
this.context.font = `${10 * coordinate.ratio}px Microsoft YaHei`;
|
|
|
help.drawLineText(
|
|
|
this.context,
|
|
@@ -748,9 +766,9 @@ export default class Draw {
|
|
|
{
|
|
|
padding: 6 * coordinate.ratio,
|
|
|
backColor: "rgba(0,0,0,0)",
|
|
|
- fillColor: style.strokeStyle
|
|
|
+ fillColor: style.strokeStyle,
|
|
|
}
|
|
|
- )
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
drawLine(vector) {
|
|
@@ -760,11 +778,11 @@ export default class Draw {
|
|
|
const end = coordinate.getScreenXY(endReal);
|
|
|
|
|
|
this.context.save();
|
|
|
- const [style, attr] = help.setVectorStyle(
|
|
|
- this.context,
|
|
|
- vector,
|
|
|
- [vector.category, vector.geoType, 'BaseLine']
|
|
|
- );
|
|
|
+ const [style, attr] = help.setVectorStyle(this.context, vector, [
|
|
|
+ vector.category,
|
|
|
+ vector.geoType,
|
|
|
+ "BaseLine",
|
|
|
+ ]);
|
|
|
if (style.dash) {
|
|
|
this.context.setLineDash(style.dash);
|
|
|
}
|
|
@@ -780,24 +798,22 @@ export default class Draw {
|
|
|
// this.drawPoint(dataService.getPoint(vector.startId))
|
|
|
// this.drawPoint(dataService.getPoint(vector.endId))
|
|
|
// }
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
switch (vector.category) {
|
|
|
case VectorCategory.Line.ArrowLine:
|
|
|
this.drawArrow(vector);
|
|
|
- drawPoints()
|
|
|
- break
|
|
|
+ drawPoints();
|
|
|
+ break;
|
|
|
case VectorCategory.Line.BaseLine:
|
|
|
- this.drawBaseLineLabel(vector)
|
|
|
- drawPoints()
|
|
|
+ this.drawBaseLineLabel(vector);
|
|
|
+ drawPoints();
|
|
|
break;
|
|
|
case VectorCategory.Line.MeasureLine:
|
|
|
case VectorCategory.Line.PositionLine:
|
|
|
- this.drawLineText(vector, style.text)
|
|
|
+ this.drawLineText(vector, style.text);
|
|
|
break;
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
drawElementLine(element) {
|