|
@@ -1,522 +0,0 @@
|
|
|
-import { dataService } from "./DataService";
|
|
|
-// import { mathUtil } from "../MathUtil.js";
|
|
|
-import { coordinate } from "../Coordinate";
|
|
|
-import Constant from "../Constant";
|
|
|
-
|
|
|
-/*
|
|
|
-1. 所有的点都投影到上下左右四个测量区域并排序
|
|
|
-2. 分别从起点开始向终点一段段画测量线,如果太短(按照像素来)则合并到上一条线段上。确定好当前线段的起始点后,开始画
|
|
|
-*/
|
|
|
-
|
|
|
-export default class MeasureService {
|
|
|
- constructor() {
|
|
|
- this.pad = {
|
|
|
- top: 60,
|
|
|
- bottom: 60,
|
|
|
- left: 265,
|
|
|
- right: 265,
|
|
|
- };
|
|
|
-
|
|
|
- this.region = {};
|
|
|
- this.measureLines = {
|
|
|
- top: [],
|
|
|
- bottom: [],
|
|
|
- left: [],
|
|
|
- right: [],
|
|
|
- };
|
|
|
- this.minDis = null;
|
|
|
- //1 英尺=0.3048 米
|
|
|
- //this.ftUnit = 0.3048
|
|
|
- this.unit = "m";
|
|
|
-
|
|
|
- this.defalutMeasurePad = {
|
|
|
- bottom: 60,
|
|
|
- right: 265,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置边距
|
|
|
- * @param {*} config
|
|
|
- */
|
|
|
- padding(config = {}) {
|
|
|
- Object.assign(this.pad, config);
|
|
|
- Object.assign(this.defalutMeasurePad, config);
|
|
|
- }
|
|
|
-
|
|
|
- updatePad(pad) {
|
|
|
- Object.assign(this.pad, pad);
|
|
|
- }
|
|
|
-
|
|
|
- updateRegion(download) {
|
|
|
- this.region.top = this.pad.top;
|
|
|
- this.region.bottom = coordinate.height - this.pad.bottom;
|
|
|
- this.region.left = this.pad.left;
|
|
|
- this.region.right = coordinate.width - this.pad.right;
|
|
|
- // if (download) { //不能用下面的,因为Constant.cadImg_Height / Constant.ratio和coordinate.height不同
|
|
|
- // this.region.bottom = Constant.cadImg_Height / Constant.ratio - this.pad.bottom
|
|
|
- // this.region.right = Constant.cadImg_Width / Constant.ratio - this.pad.right
|
|
|
- // }
|
|
|
-
|
|
|
- // let leftTop = coordinate.getXYFromScreen({
|
|
|
- // x: this.region.left,
|
|
|
- // y: this.region.top,
|
|
|
- // })
|
|
|
-
|
|
|
- // let rightBottom = coordinate.getXYFromScreen({
|
|
|
- // x: this.region.right,
|
|
|
- // y: this.region.bottom,
|
|
|
- // })
|
|
|
-
|
|
|
- // this.region.top = leftTop.y
|
|
|
- // this.region.left = leftTop.x
|
|
|
- // this.region.bottom = rightBottom.y
|
|
|
- // this.region.right = rightBottom.x
|
|
|
- }
|
|
|
-
|
|
|
- //更新测量线
|
|
|
- update() {
|
|
|
- if (this.minDis == null) {
|
|
|
- this.minDis = 100 / coordinate.res;
|
|
|
- }
|
|
|
- let tops = [];
|
|
|
- let bottoms = [];
|
|
|
- let lefts = [];
|
|
|
- let rights = [];
|
|
|
- let measurePoints = [];
|
|
|
-
|
|
|
- let data = dataService.getFloorData();
|
|
|
- if (!data) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const points = dataService.getRoadPoints();
|
|
|
- for (let key in points) {
|
|
|
- const point = points[key];
|
|
|
- measurePoints.push({
|
|
|
- x: point.x,
|
|
|
- y: point.y,
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- function sortNumber_topbottom(a, b) {
|
|
|
- return b.y - a.y;
|
|
|
- }
|
|
|
-
|
|
|
- function sortNumber_leftright(a, b) {
|
|
|
- return a.x - b.x;
|
|
|
- }
|
|
|
-
|
|
|
- tops = [].concat(measurePoints).sort(sortNumber_topbottom.bind(this));
|
|
|
- bottoms = [].concat(tops);
|
|
|
- bottoms.reverse();
|
|
|
- lefts = [].concat(measurePoints).sort(sortNumber_leftright.bind(this));
|
|
|
- rights = [].concat(lefts);
|
|
|
- rights.reverse();
|
|
|
-
|
|
|
- let start = null;
|
|
|
- let end = null;
|
|
|
-
|
|
|
- this.measureLines.top = [];
|
|
|
- for (let i = 0; i < tops.length; ++i) {
|
|
|
- if (i == 0) {
|
|
|
- start = tops[0].x;
|
|
|
- end = tops[0].x;
|
|
|
- this.measureLines.top.push({
|
|
|
- x: tops[0].x,
|
|
|
- y: this.region.top,
|
|
|
- });
|
|
|
- } else {
|
|
|
- if (tops[i].x >= start && tops[i].x <= end) {
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- start = Math.min(start, tops[i].x);
|
|
|
- end = Math.max(end, tops[i].x);
|
|
|
- if (start != end) {
|
|
|
- this.measureLines.top.push({
|
|
|
- x: tops[i].x,
|
|
|
- y: this.region.top,
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- tops = this.measureLines.top.sort(sortNumber_leftright.bind(this));
|
|
|
- this.measureLines.top = [];
|
|
|
- this.measureLines.top.push(tops[0]);
|
|
|
- for (let i = 0; i < tops.length - 1; ++i) {
|
|
|
- start = tops[i];
|
|
|
- end = null;
|
|
|
- for (let j = i + 1; j < tops.length; ++j) {
|
|
|
- end = tops[j];
|
|
|
- if (Math.abs(start.x - end.x) < this.minDis) {
|
|
|
- end = null;
|
|
|
- ++i;
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (end != null) {
|
|
|
- this.measureLines.top.push(end);
|
|
|
- } else if (i == tops.length - 1) {
|
|
|
- let len = this.measureLines.top.length;
|
|
|
- this.measureLines.top[len - 1] = tops[i];
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- this.measureLines.bottom = [];
|
|
|
- for (let i = 0; i < bottoms.length; ++i) {
|
|
|
- if (i == 0) {
|
|
|
- start = bottoms[0].x;
|
|
|
- end = bottoms[0].x;
|
|
|
- this.measureLines.bottom.push({
|
|
|
- x: bottoms[0].x,
|
|
|
- y: this.region.bottom,
|
|
|
- });
|
|
|
- } else {
|
|
|
- if (bottoms[i].x >= start && bottoms[i].x <= end) {
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- start = Math.min(start, bottoms[i].x);
|
|
|
- end = Math.max(end, bottoms[i].x);
|
|
|
- if (start != end) {
|
|
|
- this.measureLines.bottom.push({
|
|
|
- x: bottoms[i].x,
|
|
|
- y: this.region.bottom,
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- bottoms = this.measureLines.bottom.sort(sortNumber_leftright.bind(this));
|
|
|
- this.measureLines.bottom = [];
|
|
|
- this.measureLines.bottom.push(bottoms[0]);
|
|
|
- for (let i = 0; i < bottoms.length - 1; ++i) {
|
|
|
- start = bottoms[i];
|
|
|
- end = null;
|
|
|
- for (let j = i + 1; j < bottoms.length; ++j) {
|
|
|
- end = bottoms[j];
|
|
|
- if (Math.abs(start.x - end.x) < this.minDis) {
|
|
|
- end = null;
|
|
|
- ++i;
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (end != null) {
|
|
|
- this.measureLines.bottom.push(end);
|
|
|
- } else if (i == bottoms.length - 1) {
|
|
|
- let len = this.measureLines.bottom.length;
|
|
|
- this.measureLines.bottom[len - 1] = bottoms[i];
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- this.measureLines.left = [];
|
|
|
- for (let i = 0; i < lefts.length; ++i) {
|
|
|
- if (i == 0) {
|
|
|
- start = lefts[0].y;
|
|
|
- end = lefts[0].y;
|
|
|
- this.measureLines.left.push({
|
|
|
- x: this.region.left,
|
|
|
- y: lefts[0].y,
|
|
|
- });
|
|
|
- } else {
|
|
|
- if (lefts[i].y >= start && lefts[i].y <= end) {
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- start = Math.min(start, lefts[i].y);
|
|
|
- end = Math.max(end, lefts[i].y);
|
|
|
- if (start != end) {
|
|
|
- this.measureLines.left.push({
|
|
|
- x: this.region.left,
|
|
|
- y: lefts[i].y,
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- lefts = this.measureLines.left.sort(sortNumber_topbottom.bind(this));
|
|
|
- this.measureLines.left = [];
|
|
|
- this.measureLines.left.push(lefts[0]);
|
|
|
- for (let i = 0; i < lefts.length - 1; ++i) {
|
|
|
- start = lefts[i];
|
|
|
- end = null;
|
|
|
- for (let j = i + 1; j < lefts.length; ++j) {
|
|
|
- end = lefts[j];
|
|
|
- if (Math.abs(start.y - end.y) < this.minDis) {
|
|
|
- end = null;
|
|
|
- ++i;
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (end != null) {
|
|
|
- this.measureLines.left.push(end);
|
|
|
- } else if (i == lefts.length - 1) {
|
|
|
- let len = this.measureLines.left.length;
|
|
|
- this.measureLines.left[len - 1] = lefts[i];
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- this.measureLines.right = [];
|
|
|
- for (let i = 0; i < rights.length; ++i) {
|
|
|
- if (i == 0) {
|
|
|
- start = rights[0].y;
|
|
|
- end = rights[0].y;
|
|
|
- this.measureLines.right.push({
|
|
|
- x: this.region.right,
|
|
|
- y: rights[0].y,
|
|
|
- });
|
|
|
- } else {
|
|
|
- if (rights[i].y >= start && rights[i].y <= end) {
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- start = Math.min(start, rights[i].y);
|
|
|
- end = Math.max(end, rights[i].y);
|
|
|
- if (start != end) {
|
|
|
- this.measureLines.right.push({
|
|
|
- x: this.region.right,
|
|
|
- y: rights[i].y,
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- rights = this.measureLines.right.sort(sortNumber_topbottom.bind(this));
|
|
|
- this.measureLines.right = [];
|
|
|
- this.measureLines.right.push(rights[0]);
|
|
|
- for (let i = 0; i < rights.length - 1; ++i) {
|
|
|
- start = rights[i];
|
|
|
- end = null;
|
|
|
- for (let j = i + 1; j < rights.length; ++j) {
|
|
|
- end = rights[j];
|
|
|
- if (Math.abs(start.y - end.y) < this.minDis) {
|
|
|
- end = null;
|
|
|
- ++i;
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (end != null) {
|
|
|
- this.measureLines.right.push(end);
|
|
|
- } else if (i == rights.length - 1) {
|
|
|
- let len = this.measureLines.right.length;
|
|
|
- this.measureLines.right[len - 1] = rights[i];
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- update() {
|
|
|
- let tops = []
|
|
|
- let bottoms = []
|
|
|
- let lefts = []
|
|
|
- let rights = []
|
|
|
-
|
|
|
- let minX = coordinate.center.x;
|
|
|
- let minY = coordinate.center.y;
|
|
|
- let maxX = coordinate.center.x;
|
|
|
- let maxY = coordinate.center.y;
|
|
|
-
|
|
|
- const points = dataService.getRoadPoints()
|
|
|
- for (let key in points) {
|
|
|
- const point = points[key]
|
|
|
- if(point.y > coordinate.center.y){
|
|
|
- tops.push({
|
|
|
- x: point.x,
|
|
|
- y: this.region.top,
|
|
|
- })
|
|
|
- }
|
|
|
- else{
|
|
|
- bottoms.push({
|
|
|
- x:point.x,
|
|
|
- y:this.region.bottom
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- if(point.x<coordinate.center.x){
|
|
|
- lefts.push({
|
|
|
- x: this.region.left,
|
|
|
- y: point.y,
|
|
|
- })
|
|
|
- }
|
|
|
- else{
|
|
|
- rights.push({
|
|
|
- x:this.region.right,
|
|
|
- y:point.y
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- if(minX>point.x){
|
|
|
- minX = point.x
|
|
|
- }
|
|
|
- if(maxX<point.x){
|
|
|
- maxX = point.x
|
|
|
- }
|
|
|
-
|
|
|
- if(minY>point.y){
|
|
|
- minY = point.y
|
|
|
- }
|
|
|
- if(maxY<point.y){
|
|
|
- maxY = point.y
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- tops.unshift({
|
|
|
- x:minX,
|
|
|
- y:this.region.top
|
|
|
- })
|
|
|
- tops.push({
|
|
|
- x:maxX,
|
|
|
- y:this.region.top
|
|
|
- })
|
|
|
-
|
|
|
- bottoms.unshift({
|
|
|
- x:minX,
|
|
|
- y:this.region.bottom
|
|
|
- })
|
|
|
- bottoms.push({
|
|
|
- x:maxX,
|
|
|
- y:this.region.bottom
|
|
|
- })
|
|
|
-
|
|
|
- lefts.unshift({
|
|
|
- x:this.region.left,
|
|
|
- y:maxY
|
|
|
- })
|
|
|
- lefts.push({
|
|
|
- x:this.region.left,
|
|
|
- y:minY
|
|
|
- })
|
|
|
-
|
|
|
- rights.unshift({
|
|
|
- x:this.region.right,
|
|
|
- y:maxY
|
|
|
- })
|
|
|
- rights.push({
|
|
|
- x:this.region.right,
|
|
|
- y:minY
|
|
|
- })
|
|
|
-
|
|
|
- function sortNumber_topbottom(a, b) {
|
|
|
- return a.x - b.x
|
|
|
- }
|
|
|
-
|
|
|
- function sortNumber_leftright(a, b) {
|
|
|
- return b.y - a.y
|
|
|
- }
|
|
|
-
|
|
|
- tops = tops.sort(sortNumber_topbottom.bind(this))
|
|
|
- bottoms = bottoms.sort(sortNumber_topbottom.bind(this))
|
|
|
- lefts = lefts.sort(sortNumber_leftright.bind(this))
|
|
|
- rights = rights.sort(sortNumber_leftright.bind(this))
|
|
|
-
|
|
|
- this.measureLines.top = []
|
|
|
- this.measureLines.top.push(tops[0])
|
|
|
- for (let i = 0; i < tops.length - 1; ++i) {
|
|
|
- let start = tops[i]
|
|
|
- let end = null
|
|
|
- for (let j = i + 1; j < tops.length; ++j) {
|
|
|
- end = tops[j]
|
|
|
- if (mathUtil.getDistance(start, end) < this.minDis) {
|
|
|
- end = null
|
|
|
- ++i
|
|
|
- continue
|
|
|
- } else {
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if (end != null) {
|
|
|
- this.measureLines.top.push(end)
|
|
|
- } else if (i == tops.length - 1) {
|
|
|
- let len = this.measureLines.top.length
|
|
|
- this.measureLines.top[len - 1] = tops[i]
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- this.measureLines.bottom = []
|
|
|
- this.measureLines.bottom.push(bottoms[0])
|
|
|
- for (let i = 0; i < bottoms.length - 1; ++i) {
|
|
|
- let start = bottoms[i]
|
|
|
- let end = null
|
|
|
- for (let j = i + 1; j < bottoms.length; ++j) {
|
|
|
- end = bottoms[j]
|
|
|
- if (mathUtil.getDistance(start, end) < this.minDis) {
|
|
|
- end = null
|
|
|
- ++i
|
|
|
- continue
|
|
|
- } else {
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if (end != null) {
|
|
|
- this.measureLines.bottom.push(end)
|
|
|
- } else if (i == bottoms.length - 1) {
|
|
|
- let len = this.measureLines.bottom.length
|
|
|
- this.measureLines.bottom[len - 1] = bottoms[i]
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- this.measureLines.left = []
|
|
|
- this.measureLines.left.push(lefts[0])
|
|
|
- for (let i = 0; i < lefts.length - 1; ++i) {
|
|
|
- let start = lefts[i]
|
|
|
- let end = null
|
|
|
- for (let j = i + 1; j < lefts.length; ++j) {
|
|
|
- end = lefts[j]
|
|
|
- if (mathUtil.getDistance(start, end) < this.minDis) {
|
|
|
- end = null
|
|
|
- ++i
|
|
|
- continue
|
|
|
- } else {
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if (end != null) {
|
|
|
- this.measureLines.left.push(end)
|
|
|
- } else if (i == lefts.length - 1) {
|
|
|
- let len = this.measureLines.left.length
|
|
|
- this.measureLines.left[len - 1] = lefts[i]
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- this.measureLines.right = []
|
|
|
- this.measureLines.right.push(rights[0])
|
|
|
- for (let i = 0; i < rights.length - 1; ++i) {
|
|
|
- let start = rights[i]
|
|
|
- let end = null
|
|
|
- for (let j = i + 1; j < rights.length; ++j) {
|
|
|
- end = rights[j]
|
|
|
- if (mathUtil.getDistance(start, end) < this.minDis) {
|
|
|
- end = null
|
|
|
- ++i
|
|
|
- continue
|
|
|
- } else {
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if (end != null) {
|
|
|
- this.measureLines.right.push(end)
|
|
|
- } else if (i == rights.length - 1) {
|
|
|
- let len = this.measureLines.right.length
|
|
|
- this.measureLines.right[len - 1] = rights[i]
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- */
|
|
|
-}
|
|
|
-
|
|
|
-const measureService = new MeasureService();
|
|
|
-export { measureService };
|