|
@@ -13,7 +13,7 @@ const help = {
|
|
|
getVectorStyle(vector, geoType = vector.geoType) {
|
|
|
const geoId = vector?.vectorId;
|
|
|
if (!geoId) {
|
|
|
- return Style[geoType];
|
|
|
+ return [Style[geoType], undefined];
|
|
|
}
|
|
|
|
|
|
const itemsEntry = [
|
|
@@ -21,22 +21,27 @@ const help = {
|
|
|
[stateService.getDraggingItem(), "Dragging"],
|
|
|
[stateService.getFocusItem(), "Focus"],
|
|
|
];
|
|
|
-
|
|
|
- return itemsEntry.reduce((prev, [item, attr]) => {
|
|
|
- if (
|
|
|
- item &&
|
|
|
- // item.type === VectorType[geoType] &&
|
|
|
- geoId === item.vectorId
|
|
|
- ) {
|
|
|
- if (Style[attr] && Style[attr][geoType]) {
|
|
|
- return Style[attr][geoType];
|
|
|
+ let currentAttr
|
|
|
+
|
|
|
+ return [
|
|
|
+ itemsEntry.reduce((prev, [item, attr]) => {
|
|
|
+ if (
|
|
|
+ item &&
|
|
|
+ // item.type === VectorType[geoType] &&
|
|
|
+ geoId === item.vectorId
|
|
|
+ ) {
|
|
|
+ if (Style[attr] && Style[attr][geoType]) {
|
|
|
+ currentAttr = attr
|
|
|
+ return Style[attr][geoType];
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- return prev;
|
|
|
- }, Style[geoType]);
|
|
|
+ return prev;
|
|
|
+ }, Style[geoType]),
|
|
|
+ currentAttr
|
|
|
+ ];
|
|
|
},
|
|
|
setVectorStyle(ctx, vector, geoType = vector.geoType) {
|
|
|
- const styles = help.getVectorStyle(vector, geoType);
|
|
|
+ const [styles, attr] = help.getVectorStyle(vector, geoType);
|
|
|
for (const style in styles) {
|
|
|
if (typeof styles[style] === "function") {
|
|
|
styles[style](ctx, vector);
|
|
@@ -44,7 +49,7 @@ const help = {
|
|
|
ctx[style] = styles[style];
|
|
|
}
|
|
|
}
|
|
|
- return styles;
|
|
|
+ return [styles, attr];
|
|
|
},
|
|
|
transformCoves(lines) {
|
|
|
return lines.map((line) =>
|
|
@@ -394,16 +399,9 @@ export default class Draw {
|
|
|
const end = coordinate.getScreenXY(endReal);
|
|
|
const ctx = this.context;
|
|
|
|
|
|
- const ange = 30;
|
|
|
- const L = 20;
|
|
|
- let a = Math.atan2(end.y - start.y, end.x - start.x);
|
|
|
- let xC = end.x - L * Math.cos(a + (ange * Math.PI) / 180); // θ=30
|
|
|
- let yC = end.y - L * Math.sin(a + (ange * Math.PI) / 180);
|
|
|
- let xD = end.x - L * Math.cos(a - (ange * Math.PI) / 180);
|
|
|
- let yD = end.y - L * Math.sin(a - (ange * Math.PI) / 180);
|
|
|
ctx.save();
|
|
|
|
|
|
- const style = help.setVectorStyle(this.context, vector, "Arrow");
|
|
|
+ const [style] = help.setVectorStyle(this.context, vector, "Arrow");
|
|
|
if (vector.arrowColor) {
|
|
|
ctx.strokeStyle = vector.arrowColor;
|
|
|
}
|
|
@@ -438,7 +436,7 @@ export default class Draw {
|
|
|
});
|
|
|
const pt = coordinate.getScreenXY(vector.position);
|
|
|
const target = coordinate.getScreenXY(vector.popPosition);
|
|
|
- const style = help.setVectorStyle(ctx, vector);
|
|
|
+ const [style] = help.setVectorStyle(ctx, vector);
|
|
|
const radius = help.getReal(vector.radius || style.radius);
|
|
|
const offset = radius / 2;
|
|
|
const targetPts =
|
|
@@ -515,7 +513,7 @@ export default class Draw {
|
|
|
drawPoint(vector) {
|
|
|
const pt = coordinate.getScreenXY({ x: vector.x, y: vector.y });
|
|
|
const ctx = this.context;
|
|
|
- const style = help.setVectorStyle(ctx, vector, vector.geoType || "Point");
|
|
|
+ const [style] = help.setVectorStyle(ctx, vector, vector.geoType || "Point");
|
|
|
if (vector.color) {
|
|
|
ctx.strokeStyle = vector.color;
|
|
|
}
|
|
@@ -560,11 +558,17 @@ export default class Draw {
|
|
|
const oldFont = this.context.font;
|
|
|
this.context.font = `${vector.fontSize}px Microsoft YaHei`;
|
|
|
this.drawTextByInfo(vector.center, vector.value, 0, false);
|
|
|
+
|
|
|
+ const ctx = this.context
|
|
|
+ const pt = coordinate.getScreenXY(vector.center);
|
|
|
+ const text = ctx.measureText(vector.value);
|
|
|
+ pt.x -= text.width / 2;
|
|
|
+ pt.y += (text.actualBoundingBoxAscent + text.actualBoundingBoxDescent) / 2;
|
|
|
+
|
|
|
this.context.font = oldFont;
|
|
|
}
|
|
|
|
|
|
drawLine(vector) {
|
|
|
- console.log(vector)
|
|
|
if ([UIEvents.Arrow, UIEvents.MeasureLine].includes(vector.category)) {
|
|
|
return this.drawArrow(vector);
|
|
|
}
|
|
@@ -574,7 +578,7 @@ export default class Draw {
|
|
|
const end = coordinate.getScreenXY(endReal);
|
|
|
|
|
|
this.context.save();
|
|
|
- const style = help.setVectorStyle(
|
|
|
+ const [style, attr] = help.setVectorStyle(
|
|
|
this.context,
|
|
|
vector,
|
|
|
vector.category || vector.geoType
|
|
@@ -587,8 +591,11 @@ export default class Draw {
|
|
|
this.context.lineTo(end.x, end.y);
|
|
|
this.context.stroke();
|
|
|
this.context.restore();
|
|
|
- this.drawPoint(startReal)
|
|
|
- this.drawPoint(endReal)
|
|
|
+
|
|
|
+ // if (attr) {
|
|
|
+ // this.drawPoint(startReal)
|
|
|
+ // this.drawPoint(endReal)
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
drawElementLine(element) {
|
|
@@ -598,7 +605,7 @@ export default class Draw {
|
|
|
end = coordinate.getScreenXY(end);
|
|
|
|
|
|
this.context.save();
|
|
|
- const style = help.setVectorStyle(
|
|
|
+ const [style] = help.setVectorStyle(
|
|
|
this.context,
|
|
|
element,
|
|
|
element.category || element.geoType
|