|
@@ -10,7 +10,12 @@ import ElementEvents from "../enum/ElementEvents.js";
|
|
|
import Constant from "../Constant.js";
|
|
|
|
|
|
const help = {
|
|
|
- getVectorStyle(vector) {
|
|
|
+ getVectorStyle(vector, geoType = vector.geoType) {
|
|
|
+ const geoId = vector?.vectorId
|
|
|
+ if (!geoId) {
|
|
|
+ return Style[geoType]
|
|
|
+ }
|
|
|
+
|
|
|
const itemsEntry = [
|
|
|
[stateService.getSelectItem(), "Select"],
|
|
|
[stateService.getDraggingItem(), "Dragging"],
|
|
@@ -19,17 +24,18 @@ const help = {
|
|
|
return itemsEntry.reduce((prev, [item, attr]) => {
|
|
|
if (
|
|
|
item &&
|
|
|
- item.type === VectorType[vector.geoType] &&
|
|
|
- vector.vectorId === item.vectorId
|
|
|
+ item.type === VectorType[geoType] &&
|
|
|
+ geoId === item.vectorId
|
|
|
) {
|
|
|
- return Style[attr][vector.geoType];
|
|
|
- } else {
|
|
|
- return prev
|
|
|
+ if (Style[attr] && Style[attr][geoType]) {
|
|
|
+ return Style[attr][geoType];
|
|
|
+ }
|
|
|
}
|
|
|
- }, Style[vector.geoType]);
|
|
|
+ return prev
|
|
|
+ }, Style[geoType]);
|
|
|
},
|
|
|
- setVectorStyle(ctx, vector) {
|
|
|
- const styles = help.getVectorStyle(vector);
|
|
|
+ setVectorStyle(ctx, vector, geoType = vector.geoType) {
|
|
|
+ const styles = help.getVectorStyle(vector, geoType);
|
|
|
for (const style in styles) {
|
|
|
ctx[style] = styles[style];
|
|
|
}
|
|
@@ -67,31 +73,29 @@ export default class Draw {
|
|
|
|
|
|
|
|
|
drawRoad(vector, isTemp) {
|
|
|
- this.context.save();
|
|
|
- this.context.beginPath();
|
|
|
-
|
|
|
- help.setVectorStyle(this.context, vector)
|
|
|
-
|
|
|
const startReal = isTemp ? vector.start : dataService.getPoint(vector.startId)
|
|
|
const endReal = isTemp ? vector.end : dataService.getPoint(vector.endId)
|
|
|
- const startScreen = coordinate.getScreenXY(startReal);
|
|
|
- const endScreen = coordinate.getScreenXY(endReal);
|
|
|
+ if (vector?.midDivide?.display) {
|
|
|
+ const ctx = this.context;
|
|
|
+ const startScreen = coordinate.getScreenXY(startReal);
|
|
|
+ const endScreen = coordinate.getScreenXY(endReal);
|
|
|
+
|
|
|
+ ctx.save();
|
|
|
+ help.setVectorStyle(ctx, vector)
|
|
|
+ ctx.beginPath();
|
|
|
+ ctx.moveTo(startScreen.x, startScreen.y);
|
|
|
+ ctx.lineTo(endScreen.x, endScreen.y);
|
|
|
+ ctx.stroke();
|
|
|
+ ctx.restore();
|
|
|
+ }
|
|
|
|
|
|
if (!isTemp) {
|
|
|
this.drawText(
|
|
|
{ x: (startReal.x + endReal.x) / 2, y: (startReal.y + endReal.y) / 2 },
|
|
|
vector.vectorId
|
|
|
);
|
|
|
- } else {
|
|
|
- this.context.globalAlpha = 0.3
|
|
|
}
|
|
|
this.drawEdge(vector, isTemp);
|
|
|
-
|
|
|
- this.context.beginPath();
|
|
|
- this.context.moveTo(startScreen.x, startScreen.y);
|
|
|
- this.context.lineTo(endScreen.x, endScreen.y);
|
|
|
- this.context.stroke();
|
|
|
- this.context.restore();
|
|
|
}
|
|
|
|
|
|
drawCurveRoad(vector, isTemp) {
|
|
@@ -332,17 +336,11 @@ export default class Draw {
|
|
|
|
|
|
drawEdge(vector, isTemp) {
|
|
|
//判断是否与road方向一致。角度足够小,路足够宽,有可能向量方向不一致
|
|
|
- let start = dataService.getPoint(vector.startId);
|
|
|
- let end = dataService.getPoint(vector.endId);
|
|
|
-
|
|
|
- let leftEdge = dataService.getEdge(vector.leftEdgeId);
|
|
|
- let rightEdge = dataService.getEdge(vector.rightEdgeId);
|
|
|
- if (isTemp) {
|
|
|
- start = vector.start;
|
|
|
- end = vector.end;
|
|
|
- leftEdge = vector.leftEdge;
|
|
|
- rightEdge = vector.rightEdge;
|
|
|
- }
|
|
|
+ const ctx = this.context
|
|
|
+ const start = isTemp ? vector.start : dataService.getPoint(vector.startId);
|
|
|
+ const end = isTemp ? vector.end : dataService.getPoint(vector.endId);
|
|
|
+ const leftEdge = isTemp ? vector.leftEdge : dataService.getEdge(vector.leftEdgeId);
|
|
|
+ const rightEdge = isTemp ? vector.rightEdge : dataService.getEdge(vector.rightEdgeId);
|
|
|
|
|
|
const leftFlag = mathUtil.isSameDirForVector(
|
|
|
start,
|
|
@@ -357,52 +355,27 @@ export default class Draw {
|
|
|
rightEdge.end
|
|
|
);
|
|
|
|
|
|
- this.context.save();
|
|
|
- this.context.lineCap = "round"; //线段端点的样式
|
|
|
- this.context.strokeStyle = Style.Road.strokeStyle;
|
|
|
-
|
|
|
- const selectItem = stateService.getSelectItem();
|
|
|
- const draggingItem = stateService.getDraggingItem();
|
|
|
- const focusItem = stateService.getFocusItem();
|
|
|
-
|
|
|
- if (selectItem && selectItem.type == VectorType.Road) {
|
|
|
- if (vector.vectorId == selectItem.vectorId) {
|
|
|
- this.context.strokeStyle = Style.Select.Road.strokeStyle;
|
|
|
- }
|
|
|
- } else if (draggingItem && draggingItem.type == VectorType.Road) {
|
|
|
- if (vector.vectorId == draggingItem.vectorId) {
|
|
|
- this.context.strokeStyle = Style.Select.Road.strokeStyle;
|
|
|
- }
|
|
|
- } else if (focusItem && focusItem.type == VectorType.Road) {
|
|
|
- if (vector.vectorId == focusItem.vectorId) {
|
|
|
- this.context.strokeStyle = Style.Focus.Road.strokeStyle;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- let point1, point2;
|
|
|
-
|
|
|
- this.context.globalAlpha = 0.3;
|
|
|
- this.context.lineWidth = 1;
|
|
|
+ ctx.save();
|
|
|
+ help.setVectorStyle(ctx, vector, "Edge")
|
|
|
+ isTemp && (ctx.globalAlpha = 0.3);
|
|
|
|
|
|
if (leftFlag > 0) {
|
|
|
- this.context.beginPath();
|
|
|
- point1 = coordinate.getScreenXY(leftEdge.start);
|
|
|
- point2 = coordinate.getScreenXY(leftEdge.end);
|
|
|
- this.context.moveTo(point1.x, point1.y);
|
|
|
- this.context.lineTo(point2.x, point2.y);
|
|
|
- this.context.stroke();
|
|
|
+ ctx.beginPath();
|
|
|
+ const point1 = coordinate.getScreenXY(leftEdge.start);
|
|
|
+ const point2 = coordinate.getScreenXY(leftEdge.end);
|
|
|
+ ctx.moveTo(point1.x, point1.y);
|
|
|
+ ctx.lineTo(point2.x, point2.y);
|
|
|
+ ctx.stroke();
|
|
|
}
|
|
|
-
|
|
|
if (rightFlag > 0) {
|
|
|
- point1 = coordinate.getScreenXY(rightEdge.start);
|
|
|
- point2 = coordinate.getScreenXY(rightEdge.end);
|
|
|
- this.context.moveTo(point1.x, point1.y);
|
|
|
- this.context.lineTo(point2.x, point2.y);
|
|
|
- this.context.stroke();
|
|
|
+ const point1 = coordinate.getScreenXY(rightEdge.start);
|
|
|
+ const point2 = coordinate.getScreenXY(rightEdge.end);
|
|
|
+ ctx.moveTo(point1.x, point1.y);
|
|
|
+ ctx.lineTo(point2.x, point2.y);
|
|
|
+ ctx.stroke();
|
|
|
}
|
|
|
|
|
|
- this.context.restore();
|
|
|
-
|
|
|
+ ctx.restore();
|
|
|
this.drawText(
|
|
|
{
|
|
|
x: (leftEdge.start.x + leftEdge.end.x) / 2,
|
|
@@ -410,7 +383,6 @@ export default class Draw {
|
|
|
},
|
|
|
vector.leftEdgeId
|
|
|
);
|
|
|
-
|
|
|
this.drawText(
|
|
|
{
|
|
|
x: (rightEdge.start.x + rightEdge.end.x) / 2,
|
|
@@ -421,11 +393,15 @@ export default class Draw {
|
|
|
}
|
|
|
|
|
|
drawPoint(vector) {
|
|
|
+ const ctx = this.context;
|
|
|
+ console.log(vector)
|
|
|
const pt = coordinate.getScreenXY({ x: vector.x, y: vector.y });
|
|
|
const selectItem = stateService.getSelectItem();
|
|
|
const draggingItem = stateService.getDraggingItem();
|
|
|
const focusItem = stateService.getFocusItem();
|
|
|
|
|
|
+ help.setVectorStyle(ctx, vector)
|
|
|
+
|
|
|
let radius = Style.Point.radius;
|
|
|
if (
|
|
|
(draggingItem &&
|
|
@@ -435,28 +411,28 @@ export default class Draw {
|
|
|
selectItem.type == VectorType.Point &&
|
|
|
vector.vectorId == selectItem.vectorId)
|
|
|
) {
|
|
|
- this.context.save();
|
|
|
- this.context.lineWidth = Style.Select.Point.lineWidth * coordinate.ratio;
|
|
|
- this.context.strokeStyle = Style.Select.Point.strokeStyle;
|
|
|
- this.context.fillStyle = Style.Select.Point.fillStyle;
|
|
|
+ ctx.save();
|
|
|
+ ctx.lineWidth = Style.Select.Point.lineWidth * coordinate.ratio;
|
|
|
+ ctx.strokeStyle = Style.Select.Point.strokeStyle;
|
|
|
+ ctx.fillStyle = Style.Select.Point.fillStyle;
|
|
|
radius = Style.Select.Point.radius;
|
|
|
} else if (
|
|
|
focusItem &&
|
|
|
focusItem.type == VectorType.Point &&
|
|
|
vector.vectorId == focusItem.vectorId
|
|
|
) {
|
|
|
- this.context.save();
|
|
|
- this.context.lineWidth = Style.Focus.Point.lineWidth * coordinate.ratio;
|
|
|
- this.context.strokeStyle = Style.Focus.Point.strokeStyle;
|
|
|
- this.context.fillStyle = Style.Focus.Point.fillStyle;
|
|
|
+ ctx.save();
|
|
|
+ ctx.lineWidth = Style.Focus.Point.lineWidth * coordinate.ratio;
|
|
|
+ ctx.strokeStyle = Style.Focus.Point.strokeStyle;
|
|
|
+ ctx.fillStyle = Style.Focus.Point.fillStyle;
|
|
|
radius = Style.Focus.Point.radius;
|
|
|
}
|
|
|
// else {
|
|
|
// return;
|
|
|
// }
|
|
|
|
|
|
- this.context.beginPath();
|
|
|
- this.context.arc(
|
|
|
+ ctx.beginPath();
|
|
|
+ ctx.arc(
|
|
|
pt.x,
|
|
|
pt.y,
|
|
|
radius * coordinate.ratio,
|
|
@@ -464,9 +440,9 @@ export default class Draw {
|
|
|
Math.PI * 2,
|
|
|
true
|
|
|
);
|
|
|
- this.context.stroke();
|
|
|
- this.context.fill();
|
|
|
- this.context.restore();
|
|
|
+ ctx.stroke();
|
|
|
+ ctx.fill();
|
|
|
+ ctx.restore();
|
|
|
|
|
|
this.drawText(vector, vector.vectorId);
|
|
|
}
|
|
@@ -599,24 +575,19 @@ export default class Draw {
|
|
|
|
|
|
// 文字
|
|
|
drawText(position, txt, angle) {
|
|
|
- this.context.save();
|
|
|
- this.setCanvasStyle(Style.Font);
|
|
|
- if (coordinate.ratio == Constant.ratio) {
|
|
|
- this.context.font = "12px Microsoft YaHei";
|
|
|
- } else {
|
|
|
- this.context.font = "12px Microsoft YaHei";
|
|
|
- }
|
|
|
- let pt = coordinate.getScreenXY(position);
|
|
|
+ const ctx = this.context;
|
|
|
+ ctx.save();
|
|
|
+ help.setVectorStyle(null, "Text");
|
|
|
+
|
|
|
+ const pt = coordinate.getScreenXY(position);
|
|
|
if (angle) {
|
|
|
- this.context.translate(pt.x, pt.y);
|
|
|
- this.context.rotate(angle);
|
|
|
- //this.context.strokeText(txt, 0, 0)
|
|
|
- this.context.fillText(txt, 0, 0);
|
|
|
+ ctx.translate(pt.x, pt.y);
|
|
|
+ ctx.rotate(angle);
|
|
|
+ ctx.fillText(txt, 0, 0);
|
|
|
} else {
|
|
|
- //this.context.strokeText(txt, pt.x, pt.y)
|
|
|
- this.context.fillText(txt, pt.x, pt.y);
|
|
|
+ ctx.fillText(txt, pt.x, pt.y);
|
|
|
}
|
|
|
- this.context.restore();
|
|
|
+ ctx.restore();
|
|
|
}
|
|
|
|
|
|
drawTag(geometry, styleType, hide) {
|