123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- import VectorType from "../enum/VectorType.js";
- import Geometry from "./Geometry.js";
- import { mathUtil } from "../Util/MathUtil.js";
- import { coordinate } from "../Coordinate.js";
- import Constant from "../Constant.js";
- import VectorCategory from "../enum/VectorCategory";
- import RoadStructure from "../enum/RoadStructure";
- import SVGType from "../enum/SVGType";
- //const sideWidth = 10;
- export default class SVG extends Geometry {
- constructor(center, type, vectorId) {
- super();
- this.category = null;
- this.center = center;
- this.points = null; //包裹的矩形的四个顶点,顺时针。0-1是width,1-3是height
- this.angle = 0; //逆时针为负,顺时针为正。单位是:°
- this.type = type;
- this.geoType = VectorType.SVG;
- this.scaleLength = this.getScale();
- this.scaleWidth = this.getScale();
- this.setBoundingVertexs();
- this.setId(vectorId);
- this.checkCategory(type);
- }
- // createDefaultPoints() {
- // this.points = [];
- // this.points[0] = {
- // x: this.center.x - sideWidth / 2,
- // y: this.center.y + sideWidth / 2,
- // };
- // this.points[1] = {
- // x: this.center.x + sideWidth / 2,
- // y: this.center.y + sideWidth / 2,
- // };
- // this.points[2] = {
- // x: this.center.x + sideWidth / 2,
- // y: this.center.y - sideWidth / 2,
- // };
- // this.points[3] = {
- // x: this.center.x - sideWidth / 2,
- // y: this.center.y - sideWidth / 2,
- // };
- // }
- checkCategory(type) {
- // this.setCategory()
- let category = "";
- if (RoadStructure[type]) {
- category = VectorCategory.SVG["RoadStructure"];
- } else if (SVGType[type]) {
- category = VectorCategory.SVG["SVG"];
- }
- this.setCategory(category);
- }
- setCategory(value) {
- this.category = value;
- }
- setBoundingVertexs() {
- this.points = [];
- const rec = this.getLengthWidth();
- const length = this.scaleLength * rec.length;
- const width = this.scaleWidth * rec.width;
- const minX = this.center.x - length / 2;
- const minY = this.center.y - width / 2;
- const maxX = this.center.x + length / 2;
- const maxY = this.center.y + width / 2;
- const point1 = this.rotatePoint(
- {
- x: minX,
- y: maxY,
- },
- this.center,
- this.angle
- );
- const point2 = this.rotatePoint(
- {
- x: maxX,
- y: maxY,
- },
- this.center,
- this.angle
- );
- const point3 = this.rotatePoint(
- {
- x: maxX,
- y: minY,
- },
- this.center,
- this.angle
- );
- const point4 = this.rotatePoint(
- {
- x: minX,
- y: minY,
- },
- this.center,
- this.angle
- );
- this.points.push(point1);
- this.points.push(point2);
- this.points.push(point3);
- this.points.push(point4);
- }
- setPoints(points) {
- this.points = points;
- }
- // setLengthScale(scale1) {
- // this.scaleLength = scale1;
- // }
- // setWidthScale(scale2) {
- // this.scaleWidth = scale2;
- // }
- //不同图例,缩放比不一样
- getScale() {
- return 1;
- }
- setBoundingVertexs2(position, pointIndex) {
- if (mathUtil.getDistance(position, this.center) < Constant.minAdsorbPix) {
- return;
- }
- mathUtil.clonePoint(this.points[pointIndex], position);
- // 【注意】angle 逆时针为正,顺时针为负
- let nextIndex = this.getNextIndex(pointIndex);
- this.points[nextIndex] = this.rotatePoint(position, this.center, 90);
- nextIndex = this.getNextIndex(nextIndex);
- this.points[nextIndex] = this.rotatePoint(position, this.center, 180);
- nextIndex = this.getNextIndex(nextIndex);
- this.points[nextIndex] = this.rotatePoint(position, this.center, 270);
- }
- getPreIndex(index) {
- let preIndex = index - 1;
- if (preIndex < 0) {
- preIndex = preIndex + 4;
- }
- return preIndex;
- }
- getNextIndex(index) {
- let nextIndex = index + 1;
- if (nextIndex > 3) {
- nextIndex = nextIndex - 4;
- }
- return nextIndex;
- }
- getLengthWidth() {
- return {
- length: 100,
- width: 100,
- };
- }
- //变更顺序
- resetPointsIndex() {
- const point0 = JSON.parse(JSON.stringify(this.points[1]));
- const point1 = JSON.parse(JSON.stringify(this.points[2]));
- const point2 = JSON.parse(JSON.stringify(this.points[3]));
- const point3 = JSON.parse(JSON.stringify(this.points[0]));
- this.points[0] = point0;
- this.points[1] = point1;
- this.points[2] = point2;
- this.points[3] = point3;
- }
- }
|