|
@@ -6,15 +6,7 @@ import VectorCategory from "../enum/VectorCategory.js";
|
|
|
|
|
|
export class DataService {
|
|
|
constructor() {
|
|
|
- this.grid = {
|
|
|
- startX: 0,
|
|
|
- startY: 0,
|
|
|
- step1: 50 * coordinate.ratio,
|
|
|
- step2: 250 * coordinate.ratio,
|
|
|
- defalutstep1: 50 * coordinate.ratio,
|
|
|
- defalutstep2: 250 * coordinate.ratio,
|
|
|
- display: true,
|
|
|
- };
|
|
|
+ this.grid = null;
|
|
|
this.vectorData = {
|
|
|
currentId: 0, // 当前可用id
|
|
|
};
|
|
@@ -36,6 +28,35 @@ export class DataService {
|
|
|
return this.vectorData;
|
|
|
}
|
|
|
|
|
|
+ initGrid() {
|
|
|
+ this.grid = {
|
|
|
+ defalutstep1: 50 * coordinate.ratio,
|
|
|
+ defalutstep2: 250 * coordinate.ratio,
|
|
|
+ display: true,
|
|
|
+ };
|
|
|
+ this.grid.start = JSON.parse(JSON.stringify(coordinate.center));
|
|
|
+ this.setGridStartPosition();
|
|
|
+ }
|
|
|
+
|
|
|
+ setGridStartPosition() {
|
|
|
+ this.grid.step1 =
|
|
|
+ (this.grid.defalutstep1 * coordinate.zoom) / coordinate.defaultZoom;
|
|
|
+ this.grid.step2 =
|
|
|
+ (this.grid.defalutstep2 * coordinate.zoom) / coordinate.defaultZoom;
|
|
|
+ let startScreenPosition = coordinate.getScreenXY(this.grid.start);
|
|
|
+
|
|
|
+ while (startScreenPosition.x > 0 || startScreenPosition.y > 0) {
|
|
|
+ if (startScreenPosition.x > 0) {
|
|
|
+ startScreenPosition.x -= this.grid.step2;
|
|
|
+ }
|
|
|
+ if (startScreenPosition.y > 0) {
|
|
|
+ startScreenPosition.y -= this.grid.step2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.grid.startX = startScreenPosition.x;
|
|
|
+ this.grid.startY = startScreenPosition.y;
|
|
|
+ }
|
|
|
+
|
|
|
initVectorData() {
|
|
|
this.vectorData.backgroundImg = null;
|
|
|
//直路
|
|
@@ -60,6 +81,7 @@ export class DataService {
|
|
|
this.vectorData.texts = {};
|
|
|
this.vectorData.svgs = {};
|
|
|
this.vectorData.magnifiers = {};
|
|
|
+ this.initGrid();
|
|
|
}
|
|
|
|
|
|
//网格
|
|
@@ -67,32 +89,12 @@ export class DataService {
|
|
|
return this.grid;
|
|
|
}
|
|
|
|
|
|
- setGridForPan(dx, dy) {
|
|
|
- this.grid.startX += dx * coordinate.ratio;
|
|
|
- this.grid.startY += dy * coordinate.ratio;
|
|
|
- this.grid.step1 =
|
|
|
- (this.grid.defalutstep1 * coordinate.zoom) / coordinate.defaultZoom;
|
|
|
- this.grid.step2 =
|
|
|
- (this.grid.defalutstep2 * coordinate.zoom) / coordinate.defaultZoom;
|
|
|
- while (this.grid.startX > 0) {
|
|
|
- this.grid.startX -= this.grid.step2;
|
|
|
- }
|
|
|
- while (this.grid.startY > 0) {
|
|
|
- this.grid.startY -= this.grid.step2;
|
|
|
- }
|
|
|
+ setGridForPan() {
|
|
|
+ this.setGridStartPosition();
|
|
|
}
|
|
|
|
|
|
- setGridForZoom(w, h, zoom) {
|
|
|
- this.grid.startX = w / 2 - (zoom * w) / 2;
|
|
|
- this.grid.startY = h / 2 - (zoom * h) / 2;
|
|
|
- this.grid.step1 = this.grid.defalutstep1 * zoom;
|
|
|
- this.grid.step2 = this.grid.defalutstep2 * zoom;
|
|
|
- while (this.grid.startX > 0) {
|
|
|
- this.grid.startX -= this.grid.step2;
|
|
|
- }
|
|
|
- while (this.grid.startY > 0) {
|
|
|
- this.grid.startY -= this.grid.step2;
|
|
|
- }
|
|
|
+ setGridForZoom() {
|
|
|
+ this.setGridStartPosition();
|
|
|
}
|
|
|
|
|
|
setGridDisplay(value) {
|