123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- 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 Settings from "./Settings";
- 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) {
- this.layer.initLocation();
- 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 {
- if (dataLocal.backgroundImg.src) {
- 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 {
- if (dataLocal.magnifiers[key].photoUrl) {
- 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(dataLocal.points[key], key);
- point.setCategory(dataLocal.points[key].category);
- 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].color) {
- line.setColor(dataLocal.lines[key].color);
- }
- if (dataLocal.lines[key].value) {
- line.setValue(dataLocal.lines[key].value);
- }
- line.setDisplay(dataLocal.lines[key].display);
- if (line.getCategory() == VectorCategory.Line.BaseLine) {
- Settings.baseLineId = key;
- }
- }
- }
- if (dataLocal.hasOwnProperty("currentId")) {
- dataService.setCurrentId(dataLocal.currentId);
- }
- if (dataLocal.hasOwnProperty("res")) {
- coordinate.setRes(dataLocal.res);
- }
- } else if (data3d) {
- if (data3d.backImage) {
- let bgImg = imageService.create(data3d.backImage, data3d.vectorId);
- bgImg.setCenter(coordinate.center);
- try {
- if (bgImg.src) {
- await bgImg.setImageData();
- }
- } catch (e) {}
- if (data3d.meterPerPixel) {
- coordinate.setRes(data3d.meterPerPixel);
- }
- const width = bgImg.imageData.width;
- const height = bgImg.imageData.height;
- if (data3d.baseLines) {
- for (let i = 0; i < data3d.baseLines.length; ++i) {
- //理论上基准线只能有一条
- let baseLine = lineService.create(
- this.getXY(width, height, data3d.baseLines[i][0]),
- this.getXY(width, height, data3d.baseLines[i][1]),
- VectorCategory.Line.BaseLine
- );
- Settings.baseLineId = baseLine.vectorId;
- }
- }
- if (data3d.measures) {
- for (let i = 0; i < data3d.measures.length; ++i) {
- //理论上基准线只能有一条
- //
- const line = lineService.create(
- this.getXY(width, height, data3d.measures[i].pos[0]),
- this.getXY(width, height, data3d.measures[i].pos[1]),
- VectorCategory.Line.MeasureLine
- );
- line.value = data3d.measures[i].dis;
- }
- }
- if (data3d.basePoints) {
- for (let i = 0; i < data3d.basePoints.length; ++i) {
- let point = pointService.create(
- this.getXY(width, height, data3d.basePoints[i])
- );
- point.setCategory(VectorCategory.Point.BasePoint);
- }
- }
- if (data3d.fixPoints) {
- for (let i = 0; i < data3d.fixPoints.length; ++i) {
- let point = pointService.create(
- // data3d.fixPoints[i].text
- this.getXY(width, height, data3d.fixPoints[i].pos)
- );
- point.setCategory(VectorCategory.Point.FixPoint);
- }
- }
- }
- }
- if (Settings.baseLineId) {
- this.layer.updateForLocation();
- }
- this.layer.history.init();
- this.layer.renderer.autoRedraw();
- }
- getXY(width, height, position) {
- const point = {};
- point.x = position.x - width / 2;
- point.y = height / 2 - position.y;
- return point;
- }
- save() {
- const res = coordinate.getRes();
- dataService.setRes(res);
- const scale = res / (coordinate.zoom / coordinate.defaultZoom);
- dataService.setScale(scale);
- return dataService.vectorData;
- }
- // 退出页面清除缓存及其他操作
- clear() {
- this.layer.uiControl.menu_clear();
- console.warn("clear");
- }
- }
|