|
@@ -166,7 +166,7 @@ export default class Draw {
|
|
|
const endReal = isTemp
|
|
|
? vector.end
|
|
|
: dataService.getRoadPoint(vector.endId);
|
|
|
- this.drawText(
|
|
|
+ this.drawTextByInfo(
|
|
|
{ x: (startReal.x + endReal.x) / 2, y: (startReal.y + endReal.y) / 2 },
|
|
|
vector.vectorId
|
|
|
);
|
|
@@ -218,7 +218,7 @@ export default class Draw {
|
|
|
ctx.lineTo(point2.x, point2.y);
|
|
|
ctx.stroke();
|
|
|
}
|
|
|
- this.drawText(
|
|
|
+ this.drawTextByInfo(
|
|
|
{
|
|
|
x: (edgeVector.start.x + edgeVector.end.x) / 2,
|
|
|
y: (edgeVector.start.y + edgeVector.end.y) / 2,
|
|
@@ -356,18 +356,90 @@ export default class Draw {
|
|
|
this.drawPoint(vector);
|
|
|
}
|
|
|
|
|
|
+ drawArrow(vector) {
|
|
|
+ let start = dataService.getPoint(vector.startId);
|
|
|
+ start = coordinate.getScreenXY(start);
|
|
|
+ let end = dataService.getPoint(vector.endId);
|
|
|
+ end = coordinate.getScreenXY(end);
|
|
|
+ const ctx = this.context
|
|
|
+
|
|
|
+ const ange = 30
|
|
|
+ const L = 8;
|
|
|
+ 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()
|
|
|
+
|
|
|
+ help.setVectorStyle(
|
|
|
+ this.context,
|
|
|
+ vector,
|
|
|
+ vector.category || vector.geoType
|
|
|
+ );
|
|
|
+ if (vector.arrowColor) {
|
|
|
+ ctx.strokeStyle = vector.arrowColor
|
|
|
+ }
|
|
|
+ ctx.beginPath();
|
|
|
+ ctx.moveTo(start.x, start.y);
|
|
|
+ ctx.lineTo(end.x, end.y);
|
|
|
+ ctx.moveTo(xC, yC);
|
|
|
+ ctx.lineTo(end.x, end.y);
|
|
|
+ ctx.lineTo(xD, yD);
|
|
|
+ ctx.stroke();
|
|
|
+ ctx.restore();
|
|
|
+ }
|
|
|
+
|
|
|
+ drawMagnifier(vector) {
|
|
|
+ const ctx = this.context
|
|
|
+ this.drawPoint({
|
|
|
+ ...vector.position,
|
|
|
+ radius: Style.Magnifier.radius,
|
|
|
+ geoType: vector.geoType,
|
|
|
+ })
|
|
|
+ const pt = vector.position
|
|
|
+ const target = vector.popPosition
|
|
|
+ const style = help.setVectorStyle(ctx, vector)
|
|
|
+ const offset = style.radius / 2
|
|
|
+ console.log(pt, target, pt, style.radius)
|
|
|
+ const targetPts = [
|
|
|
+ mathUtil.translate(pt, target, pt, style.radius),
|
|
|
+ target
|
|
|
+ ]
|
|
|
+
|
|
|
+ ctx.save();
|
|
|
+ ctx.beginPath()
|
|
|
+ ctx.moveTo(pt.x - offset, pt.y)
|
|
|
+ ctx.lineTo(pt.x + offset, pt.y)
|
|
|
+ ctx.stroke();
|
|
|
+ ctx.beginPath()
|
|
|
+ ctx.moveTo(pt.x, pt.y - offset)
|
|
|
+ ctx.lineTo(pt.x, pt.y + offset)
|
|
|
+ ctx.stroke();
|
|
|
+ if (targetPts) {
|
|
|
+ ctx.beginPath()
|
|
|
+ ctx.moveTo(targetPts[0].x, targetPts[0].y)
|
|
|
+ ctx.lineTo(targetPts[1].x, targetPts[1].y)
|
|
|
+ ctx.stroke();
|
|
|
+ }
|
|
|
+ ctx.restore();
|
|
|
+ }
|
|
|
+
|
|
|
drawCircle(element) {
|
|
|
this.drawPoint({
|
|
|
+ ...element,
|
|
|
...element.center,
|
|
|
- radius: element.radius,
|
|
|
- geoType: element.geoType,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
drawPoint(vector) {
|
|
|
- const pt = coordinate.getScreenXY({ x: vector.x, y: vector.y });
|
|
|
+ // const pt = coordinate.getScreenXY({ x: vector.x, y: vector.y });
|
|
|
+ const pt = vector
|
|
|
const ctx = this.context;
|
|
|
const style = help.setVectorStyle(ctx, vector, vector.geoType || "Point");
|
|
|
+ if (vector.color) {
|
|
|
+ ctx.strokeStyle = vector.color
|
|
|
+ }
|
|
|
const radius = (vector.radius || style.radius) * coordinate.ratio;
|
|
|
ctx.save();
|
|
|
ctx.beginPath();
|
|
@@ -378,18 +450,20 @@ export default class Draw {
|
|
|
|
|
|
if (import.meta.env.DEV) {
|
|
|
if (vector.vectorId) {
|
|
|
- this.drawText(vector, vector.vectorId);
|
|
|
+ this.drawTextByInfo(vector, vector.vectorId);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 文字
|
|
|
- drawText(position, txt, angle) {
|
|
|
+ drawTextByInfo(position, txt, angle, setStyle = true) {
|
|
|
const ctx = this.context;
|
|
|
ctx.save();
|
|
|
- help.setVectorStyle(ctx, null, "Text");
|
|
|
+ setStyle && help.setVectorStyle(ctx, null, "Text");
|
|
|
|
|
|
const pt = coordinate.getScreenXY(position);
|
|
|
+ const text = ctx.measureText("foo");
|
|
|
+ pt.x -= text.width / 2
|
|
|
+ pt.y -= (text.actualBoundingBoxAscent + text.actualBoundingBoxDescent) / 2
|
|
|
if (angle) {
|
|
|
ctx.translate(pt.x, pt.y);
|
|
|
ctx.rotate(angle);
|
|
@@ -400,7 +474,18 @@ export default class Draw {
|
|
|
ctx.restore();
|
|
|
}
|
|
|
|
|
|
+ // 文字
|
|
|
+ drawText(vector) {
|
|
|
+ help.setVectorStyle(this.context, vector);
|
|
|
+ this.context.fillStyle = vector.color
|
|
|
+ this.context.font = `${vector.fontSize}px Microsoft YaHei`
|
|
|
+ this.drawTextByInfo(vector.center, vector.value, 0, false);
|
|
|
+ }
|
|
|
+
|
|
|
drawLine(vector) {
|
|
|
+ if (vector.category === "Arrow") {
|
|
|
+ return this.drawArrow(vector);
|
|
|
+ }
|
|
|
let start = dataService.getPoint(vector.startId);
|
|
|
start = coordinate.getScreenXY(start);
|
|
|
let end = dataService.getPoint(vector.endId);
|
|
@@ -412,7 +497,6 @@ export default class Draw {
|
|
|
vector,
|
|
|
vector.category || vector.geoType
|
|
|
);
|
|
|
-
|
|
|
if (style.dash) {
|
|
|
this.context.setLineDash(style.dash);
|
|
|
}
|