فهرست منبع

修改了drawCircle。确保缩放正常。

xushiting 2 سال پیش
والد
کامیت
f9843142c8
1فایلهای تغییر یافته به همراه41 افزوده شده و 43 حذف شده
  1. 41 43
      src/graphic/Renderer/Draw.js

+ 41 - 43
src/graphic/Renderer/Draw.js

@@ -361,24 +361,20 @@ export default class Draw {
     start = coordinate.getScreenXY(start);
     let end = dataService.getPoint(vector.endId);
     end = coordinate.getScreenXY(end);
-    const ctx = this.context
+    const ctx = this.context;
 
-    const ange = 30
+    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,
-      'Arrow'
-    );
+    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, "Arrow");
     if (vector.arrowColor) {
-      ctx.strokeStyle = vector.arrowColor
+      ctx.strokeStyle = vector.arrowColor;
     }
     ctx.beginPath();
     ctx.moveTo(start.x, start.y);
@@ -391,36 +387,36 @@ export default class Draw {
   }
 
   drawMagnifier(vector) {
-    console.error(123)
-    const ctx = this.context
+    console.error(123);
+    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.error(pt, target, pt, style.radius)
+    });
+    const pt = vector.position;
+    const target = vector.popPosition;
+    const style = help.setVectorStyle(ctx, vector);
+    const offset = style.radius / 2;
+    console.error(pt, target, pt, style.radius);
     const targetPts = [
       mathUtil.translate(pt, target, pt, style.radius),
-      target
-    ]
+      target,
+    ];
 
     ctx.save();
-    ctx.beginPath()
-    ctx.moveTo(pt.x - offset, pt.y)
-    ctx.lineTo(pt.x + offset, pt.y)
+    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.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.beginPath();
+      ctx.moveTo(targetPts[0].x, targetPts[0].y);
+      ctx.lineTo(targetPts[1].x, targetPts[1].y);
       ctx.stroke();
     }
     ctx.restore();
@@ -429,8 +425,8 @@ export default class Draw {
   drawCircle(element) {
     this.drawPoint({
       ...element,
-      geoType: 'Circle',
-      ...element.center
+      geoType: "Circle",
+      ...element.center,
     });
   }
 
@@ -439,9 +435,11 @@ export default class Draw {
     const ctx = this.context;
     const style = help.setVectorStyle(ctx, vector, vector.geoType || "Point");
     if (vector.color) {
-      ctx.strokeStyle = vector.color
+      ctx.strokeStyle = vector.color;
     }
-    const radius = (vector.radius || style.radius) * coordinate.ratio ;
+    const radius =
+      ((vector.radius || style.radius) * coordinate.ratio * coordinate.zoom) /
+      coordinate.defaultZoom;
     ctx.save();
     ctx.beginPath();
     ctx.arc(pt.x, pt.y, radius, 0, Math.PI * 2, true);
@@ -463,8 +461,8 @@ export default class Draw {
 
     const pt = coordinate.getScreenXY(position);
     const text = ctx.measureText("foo");
-    pt.x -= text.width / 2
-    pt.y -= (text.actualBoundingBoxAscent + text.actualBoundingBoxDescent) / 2
+    pt.x -= text.width / 2;
+    pt.y -= (text.actualBoundingBoxAscent + text.actualBoundingBoxDescent) / 2;
     if (angle) {
       ctx.translate(pt.x, pt.y);
       ctx.rotate(angle);
@@ -478,13 +476,13 @@ export default class Draw {
   // 文字
   drawText(vector) {
     help.setVectorStyle(this.context, vector);
-    this.context.fillStyle = vector.color
-    this.context.font = `${vector.fontSize}px Microsoft YaHei`
+    this.context.fillStyle = vector.color;
+    this.context.font = `${vector.fontSize}px Microsoft YaHei`;
     this.drawTextByInfo(vector.center, vector.value, 0, false);
   }
 
   drawLine(vector) {
-    console.log(vector)
+    console.log(vector);
     if (vector.category === "MeasureLine") {
       return this.drawArrow(vector);
     }