123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- import { dataService } from "./Service/DataService.js";
- import { lineService } from "./Service/LineService.js";
- import { pointService } from "./Service/PointService.js";
- import { imageService } from "./Service/ImageService.js";
- import VectorCategory from "./enum/VectorCategory.js";
- import { coordinate } from "./Coordinate.js";
- import { circleService } from "./Service/CircleService.js";
- import { magnifierService } from "./Service/MagnifierService.js";
- import { textService } from "./Service/TextService.js";
- export default class Load {
- constructor(layer) {
- this.layer = layer;
- this.version = "v1.0";
- this.vectorsJson = null;
- this.newVectorId = null;
- }
- async load(dataLocal, data3d) {
- if (dataLocal) {
- if (dataLocal.backgroundImg) {
- let bgImg = imageService.create(
- dataLocal.backgroundImg.src,
- dataLocal.backgroundImg.vectorId
- );
- bgImg.setCenter(dataLocal.backgroundImg.center);
- bgImg.setDisplay(dataLocal.backgroundImg.display);
- bgImg.setAngle(dataLocal.backgroundImg.angle);
- try {
- await bgImg.setImageData();
- } catch (e) {}
- }
- if (dataLocal.circles) {
- for (let key in dataLocal.circles) {
- let circle = circleService.create(
- dataLocal.circles[key].center,
- dataLocal.circles[key].radius,
- key
- );
- circle.setPoints(dataLocal.circles[key].points);
- circle.setColor(dataLocal.circles[key].color);
- circle.setDisplay(dataLocal.circles[key].display);
- }
- }
- if (dataLocal.magnifiers) {
- for (let key in dataLocal.magnifiers) {
- let magnifier = magnifierService.create(
- dataLocal.magnifiers[key].position,
- key
- );
- magnifier.setSrc(dataLocal.magnifiers[key].photoUrl);
- magnifier.setDisplay(dataLocal.magnifiers[key].display);
- try {
- await magnifier.setImageData();
- } catch (e) {}
- }
- }
- if (dataLocal.texts) {
- for (let key in dataLocal.texts) {
- let text = textService.create(dataLocal.texts[key].center, key);
- text.setValue(dataLocal.texts[key].value);
- text.setFontSize(dataLocal.texts[key].fontSize);
- text.setColor(dataLocal.texts[key].color);
- text.setDisplay(dataLocal.texts[key].display);
- }
- }
- if (dataLocal.points) {
- for (let key in dataLocal.points) {
- let point = pointService.create(
- { x: dataLocal.points[key].x, y: dataLocal.points[key].y },
- dataLocal.points[key].category,
- key
- );
- point.setParent(
- JSON.parse(JSON.stringify(dataLocal.points[key].parent))
- );
- point.setDisplay(dataLocal.points[key].display);
- }
- }
- if (dataLocal.lines) {
- for (let key in dataLocal.lines) {
- let line = lineService.createByPointId(
- dataLocal.lines[key].startId,
- dataLocal.lines[key].endId,
- dataLocal.lines[key].category,
- key
- );
- if (dataLocal.lines[key].arrowColor) {
- line.setArrowColor(dataLocal.lines[key].arrowColor);
- }
- line.setDisplay(dataLocal.lines[key].display);
- }
- }
- if (dataLocal.hasOwnProperty("currentId")) {
- dataService.setCurrentId(dataLocal.currentId);
- }
- }
- if (data3d) {
- if (data3d.backImage) {
- let bgImg = imageService.create(data3d.backImage, data3d.vectorId);
- bgImg.setCenter(coordinate.center);
- try {
- await bgImg.setImageData();
- } catch (e) {}
- }
- if (data3d.baseLines) {
- for (let i = 0; i < data3d.baseLines.length; ++i) {
- //理论上基准线只能有一条
- lineService.create(
- data3d.baseLines[i][0],
- data3d.baseLines[i][1],
- VectorCategory.Line.BaseLine
- );
- }
- }
- if (data3d.measures) {
- for (let i = 0; i < data3d.measures.length; ++i) {
- //理论上基准线只能有一条
- lineService.create(
- data3d.measures[i][0],
- data3d.measures[i][1],
- VectorCategory.Line.MeasureLine
- );
- }
- }
- if (data3d.basePoints) {
- for (let i = 0; i < data3d.basePoints.length; ++i) {
- pointService.create(
- data3d.basePoints[i],
- VectorCategory.Point.BasePoint
- );
- }
- }
- if (data3d.fixPoints) {
- for (let i = 0; i < data3d.fixPoints.length; ++i) {
- pointService.create(
- data3d.fixPoints[i],
- VectorCategory.Point.FixPoint
- );
- }
- }
- }
- this.layer.history.init();
- this.layer.renderer.autoRedraw();
- }
- save() {
- return dataService.vectorData;
- }
- // 退出页面清除缓存及其他操作
- clear() {
- console.warn("clear");
- }
- }
|