|
@@ -7,6 +7,7 @@ import { mathUtil } from "../Util/MathUtil.js";
|
|
|
import ElementEvents from "../enum/ElementEvents.js";
|
|
|
import { elementService } from "../Service/ElementService.js";
|
|
|
|
|
|
+const imgCache = {}
|
|
|
const help = {
|
|
|
getVectorStyle(vector, geoType = vector.geoType) {
|
|
|
const geoId = vector?.vectorId;
|
|
@@ -23,7 +24,7 @@ const help = {
|
|
|
return itemsEntry.reduce((prev, [item, attr]) => {
|
|
|
if (
|
|
|
item &&
|
|
|
- item.type === VectorType[geoType] &&
|
|
|
+ // item.type === VectorType[geoType] &&
|
|
|
geoId === item.vectorId
|
|
|
) {
|
|
|
if (Style[attr] && Style[attr][geoType]) {
|
|
@@ -77,18 +78,36 @@ const help = {
|
|
|
ctx.stroke();
|
|
|
}
|
|
|
},
|
|
|
+ getReal(data) {
|
|
|
+ return (data * coordinate.ratio * coordinate.zoom) / coordinate.defaultZoom;
|
|
|
+ },
|
|
|
+ getImage(src) {
|
|
|
+ if (imgCache[src]) {
|
|
|
+ return imgCache[src];
|
|
|
+ }
|
|
|
+ const img = new Image()
|
|
|
+ img.src = src
|
|
|
+ return imgCache[src] = new Promise(resolve => {
|
|
|
+ img.onload = () => {
|
|
|
+ resolve(img)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
export default class Draw {
|
|
|
constructor() {
|
|
|
+ this.canvas = null
|
|
|
this.context = null;
|
|
|
}
|
|
|
|
|
|
initContext(canvas) {
|
|
|
if (canvas) {
|
|
|
+ this.canvas = canvas
|
|
|
this.context = canvas.getContext("2d");
|
|
|
} else {
|
|
|
this.context = null;
|
|
|
+ this.canvas = null
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -102,9 +121,23 @@ export default class Draw {
|
|
|
}
|
|
|
|
|
|
drawBackGroundImg(vector) {
|
|
|
- this.context.save();
|
|
|
+ help.getImage(vector.src)
|
|
|
+ .then(img => {
|
|
|
+ const width = help.getReal(img.width)
|
|
|
+ const height = help.getReal(img.height)
|
|
|
+ const center = coordinate.getScreenXY({x: 0, y: 0});
|
|
|
+ this.context.save();
|
|
|
+ this.context.drawImage(
|
|
|
+ img,
|
|
|
+ center.x - width / 2,
|
|
|
+ center.y - height / 2,
|
|
|
+ width,
|
|
|
+ height
|
|
|
+ )
|
|
|
+ this.context.restore();
|
|
|
+ })
|
|
|
+
|
|
|
|
|
|
- this.context.restore();
|
|
|
}
|
|
|
|
|
|
drawGrid(startX, startY, w, h, step1, step2) {
|
|
@@ -140,7 +173,6 @@ export default class Draw {
|
|
|
}
|
|
|
|
|
|
drawRoad(vector, isTemp) {
|
|
|
- console.log(vector);
|
|
|
if (!isTemp && vector.display && vector.way !== "oneWay") {
|
|
|
const ctx = this.context;
|
|
|
const draw = (midDivide) => {
|
|
@@ -357,10 +389,10 @@ export default class Draw {
|
|
|
}
|
|
|
|
|
|
drawArrow(vector) {
|
|
|
- let start = dataService.getPoint(vector.startId);
|
|
|
- start = coordinate.getScreenXY(start);
|
|
|
- let end = dataService.getPoint(vector.endId);
|
|
|
- end = coordinate.getScreenXY(end);
|
|
|
+ const startReal = dataService.getPoint(vector.startId);
|
|
|
+ const start = coordinate.getScreenXY(startReal);
|
|
|
+ const endReal = dataService.getPoint(vector.endId);
|
|
|
+ const end = coordinate.getScreenXY(endReal);
|
|
|
const ctx = this.context
|
|
|
|
|
|
const ange = 30
|
|
@@ -372,7 +404,7 @@ export default class Draw {
|
|
|
let yD = end.y - L * Math.sin(a - ange * Math.PI/180);
|
|
|
ctx.save()
|
|
|
|
|
|
- help.setVectorStyle(
|
|
|
+ const style = help.setVectorStyle(
|
|
|
this.context,
|
|
|
vector,
|
|
|
'Arrow'
|
|
@@ -388,20 +420,29 @@ export default class Draw {
|
|
|
ctx.lineTo(xD, yD);
|
|
|
ctx.stroke();
|
|
|
ctx.restore();
|
|
|
+
|
|
|
+ if ([Style.Focus.Arrow, Style.Select.Arrow].includes(style)) {
|
|
|
+ this.drawPoint(startReal)
|
|
|
+ this.drawPoint(endReal)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
drawMagnifier(vector) {
|
|
|
const ctx = this.context
|
|
|
this.drawPoint({
|
|
|
+ ...vector,
|
|
|
...vector.position,
|
|
|
radius: Style.Magnifier.radius,
|
|
|
})
|
|
|
const pt = coordinate.getScreenXY(vector.position)
|
|
|
const target = coordinate.getScreenXY(vector.popPosition)
|
|
|
const style = help.setVectorStyle(ctx, vector)
|
|
|
- const offset = style.radius / 2
|
|
|
+ const radius =
|
|
|
+ ((vector.radius || style.radius) * coordinate.ratio * coordinate.zoom) /
|
|
|
+ coordinate.defaultZoom;
|
|
|
+ const offset = radius / 2
|
|
|
const targetPts = style === Style.Focus.Magnifier ? [
|
|
|
- mathUtil.translate(pt, target, pt, style.radius),
|
|
|
+ mathUtil.translate(pt, target, pt, radius),
|
|
|
target
|
|
|
] : null
|
|
|
|
|
@@ -414,11 +455,36 @@ export default class Draw {
|
|
|
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();
|
|
|
+
|
|
|
+ imgCache[Object.keys(imgCache)[0]].then(img => {
|
|
|
+ const size = help.getReal(style.target.radius);
|
|
|
+ ctx.save();
|
|
|
+ ctx.beginPath()
|
|
|
+ ctx.arc(target.x, target.y, size, 0, 2*Math.PI);
|
|
|
+ ctx.clip()
|
|
|
+ ctx.drawImage(
|
|
|
+ img,
|
|
|
+ vector.position.x - style.target.radius,
|
|
|
+ vector.position.y - style.target.radius,
|
|
|
+ style.target.radius*2,
|
|
|
+ style.target.radius*2,
|
|
|
+ target.x - size,
|
|
|
+ target.y - size,
|
|
|
+ size*2,
|
|
|
+ size*2
|
|
|
+ );
|
|
|
+ ctx.strokeStyle = style.target.strokeStyle
|
|
|
+ ctx.lineWidth = style.target.lineWidth
|
|
|
+ ctx.stroke()
|
|
|
+ ctx.restore();
|
|
|
+ })
|
|
|
+
|
|
|
}
|
|
|
ctx.restore();
|
|
|
}
|
|
@@ -429,6 +495,8 @@ export default class Draw {
|
|
|
geoType: 'Circle',
|
|
|
...element.center
|
|
|
});
|
|
|
+
|
|
|
+ console.log(element)
|
|
|
}
|
|
|
|
|
|
drawPoint(vector) {
|
|
@@ -438,9 +506,7 @@ export default class Draw {
|
|
|
if (vector.color) {
|
|
|
ctx.strokeStyle = vector.color
|
|
|
}
|
|
|
- const radius =
|
|
|
- ((vector.radius || style.radius) * coordinate.ratio * coordinate.zoom) /
|
|
|
- coordinate.defaultZoom;
|
|
|
+ const radius = help.getReal(vector.radius || style.radius)
|
|
|
ctx.save();
|
|
|
ctx.beginPath();
|
|
|
ctx.arc(pt.x, pt.y, radius, 0, Math.PI * 2, true);
|
|
@@ -483,8 +549,7 @@ export default class Draw {
|
|
|
}
|
|
|
|
|
|
drawLine(vector) {
|
|
|
- console.log(vector)
|
|
|
- if (vector.category === "MeasureLine") {
|
|
|
+ if (vector.category === "ArrowLine") {
|
|
|
return this.drawArrow(vector);
|
|
|
}
|
|
|
let start = dataService.getPoint(vector.startId);
|