|
@@ -1,5 +1,5 @@
|
|
|
import { SMouseEvent, SUndoStack } from "@saga-web/base";
|
|
|
-import { SGraphScene, SGraphLayoutType } from '@saga-web/graph/lib';
|
|
|
+import { SGraphScene, SGraphLayoutType, SAnchorItem } from '@saga-web/graph/lib';
|
|
|
import { SFloorParser, SLineItem, SPolylineItem, SItemStatus, ItemOrder, STooltipItem } from "@saga-web/big";
|
|
|
import { SGraphItem, SLineStyle, SImageItem, STextItem, SGraphPointListInsert, SGraphPointListDelete, SGraphPointListUpdate, SGraphAddCommand } from "@saga-web/graph/lib";
|
|
|
import { SZoneLegendItem } from "@/lib/items/SZoneLegendItem";
|
|
@@ -7,9 +7,8 @@ import { SSCPZZoneLegendItem } from "@/lib/items/SSCPZZoneLegendItem";
|
|
|
import { SFHFQZoneLegendItem } from "@/lib/items/SFHFQZoneLegendItem";
|
|
|
import { SImageLegendItem } from "@/lib/items/SImageLegendItem";
|
|
|
import { TipelineItem } from "@/lib/items/TipelineItem";
|
|
|
-import { SImgTextItem } from "@/lib/items/SImgTextItem";
|
|
|
import { SImageMarkerItem } from "@/lib/items/SImageMarkerItem"
|
|
|
-import { SPoint, SFont, SColor } from '@saga-web/draw/lib';
|
|
|
+import { SPoint, SFont, SColor, SRect } from '@saga-web/draw/lib';
|
|
|
import { Legend } from '@/lib/types/Legend';
|
|
|
import { Relation } from '@/lib/types/Relation';
|
|
|
|
|
@@ -17,6 +16,9 @@ import { uuid } from "@/components/mapClass/until";
|
|
|
import { STextMarkerItem } from '@/lib/items/STextMarkerItem';
|
|
|
import { SLineMarkerItem } from '@/lib/items/SLineMarkerItem';
|
|
|
import { SSpaceItem } from '@saga-web/big/lib/items/floor/SSpaceItem';
|
|
|
+import { SMathUtil } from '@saga-web/big/lib/utils/SMathUtil';
|
|
|
+import { MinDis } from '@saga-web/big/lib/types/MinDis';
|
|
|
+import { HighlightItem } from '@/lib/items/HighlightItem';
|
|
|
/**
|
|
|
* 在线绘图
|
|
|
*
|
|
@@ -51,6 +53,11 @@ export class EditScence extends SGraphScene {
|
|
|
/** 绘制区域时 是否为点选 */
|
|
|
isSelecting: boolean = false;
|
|
|
|
|
|
+ /** 是否开启吸附 */
|
|
|
+ isAbsorbing: boolean = false;
|
|
|
+ /** 吸附展示item */
|
|
|
+ highLight: HighlightItem | null = null;
|
|
|
+
|
|
|
/** 当前选中焦点Item */
|
|
|
focusItem: SGraphItem | null = null;
|
|
|
|
|
@@ -725,6 +732,15 @@ export class EditScence extends SGraphScene {
|
|
|
////////////////////////
|
|
|
// 以下为鼠标键盘操作事件
|
|
|
onMouseDown(event: SMouseEvent): any {
|
|
|
+ // 判断是否开启吸附,并且有吸附的点
|
|
|
+ if (
|
|
|
+ this.isAbsorbing &&
|
|
|
+ this.highLight &&
|
|
|
+ this.highLight.visible
|
|
|
+ ) {
|
|
|
+ event.x = this.highLight.point.x;
|
|
|
+ event.y = this.highLight.point.y;
|
|
|
+ }
|
|
|
if (this.grabItem) {
|
|
|
return this.grabItem.onMouseDown(event);
|
|
|
}
|
|
@@ -757,6 +773,18 @@ export class EditScence extends SGraphScene {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ onMouseMove(event: SMouseEvent):boolean {
|
|
|
+ if (this.isAbsorbing) {
|
|
|
+ if (!this.highLight) {
|
|
|
+ this.highLight = new HighlightItem(null);
|
|
|
+ this.addItem(this.highLight);
|
|
|
+ }
|
|
|
+ this.highLight.visible = false;
|
|
|
+ this.absorbSpace(event);
|
|
|
+ }
|
|
|
+ return super.onMouseMove(event)
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 键盘事件
|
|
|
*
|
|
@@ -772,4 +800,184 @@ export class EditScence extends SGraphScene {
|
|
|
// }
|
|
|
return false
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 划线时点击位置是否是锚点
|
|
|
+ *
|
|
|
+ * @param event 事件
|
|
|
+ * @param len 限制距离
|
|
|
+ * @return 点击的锚点
|
|
|
+ * */
|
|
|
+ clickIsAnchor(event: SMouseEvent): SAnchorItem | null {
|
|
|
+ let minAnchor = null;
|
|
|
+ let len: number = -1;
|
|
|
+ this.Nodes.forEach(image => {
|
|
|
+ if (image.anchorList && image.anchorList.length) {
|
|
|
+ image.anchorList.forEach(anchor => {
|
|
|
+ console.log(anchor)
|
|
|
+ let anchorPoint = anchor.mapToScene(0, 0);
|
|
|
+ let dis = SMathUtil.pointDistance(
|
|
|
+ event.x,
|
|
|
+ event.y,
|
|
|
+ anchorPoint.x,
|
|
|
+ anchorPoint.y
|
|
|
+ );
|
|
|
+ if (len < 0) {
|
|
|
+ len = anchor.sceneDis;
|
|
|
+ }
|
|
|
+ if (dis < len) {
|
|
|
+ minAnchor = anchor;
|
|
|
+ len = dis;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ console.log('-----------------------')
|
|
|
+ console.log(minAnchor)
|
|
|
+ return minAnchor;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 点是否在吸附区域内
|
|
|
+ *
|
|
|
+ * @param p 要判断的点
|
|
|
+ * @param minX 空间区域
|
|
|
+ * @param minY 空间区域
|
|
|
+ * @param maxX 空间区域
|
|
|
+ * @param maxY 空间区域
|
|
|
+ */
|
|
|
+ static isPointInAbsorbArea(
|
|
|
+ p: SPoint,
|
|
|
+ minX: number,
|
|
|
+ maxX: number,
|
|
|
+ minY: number,
|
|
|
+ maxY: number
|
|
|
+ ): boolean {
|
|
|
+ let rect = new SRect(
|
|
|
+ minX - 1000,
|
|
|
+ minY - 1000,
|
|
|
+ maxX - minX + 2000,
|
|
|
+ maxY - minY + 2000
|
|
|
+ );
|
|
|
+ return rect.contains(p.x, p.y);
|
|
|
+ } // Function isPointInAbsorbArea()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 吸附空间
|
|
|
+ *
|
|
|
+ * @param event 鼠标事件对象
|
|
|
+ * @return boolean 是否找到吸附的对象
|
|
|
+ */
|
|
|
+ absorbSpace(event: SMouseEvent): boolean {
|
|
|
+ if (!this.highLight) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ let absorbLen = 1000;
|
|
|
+ if (this.view) {
|
|
|
+ absorbLen = 10 / this.view.scale;
|
|
|
+ }
|
|
|
+ let P = this.absorbSpacePoint(event, absorbLen);
|
|
|
+ if (P.Point) {
|
|
|
+ this.highLight.distance = P.MinDis;
|
|
|
+ this.highLight.point = new SPoint(P.Point.X, -P.Point.Y);
|
|
|
+ this.highLight.visible = true;
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ let L = this.absorbSpaceLine(event, absorbLen);
|
|
|
+ if (L.Line && L.Point) {
|
|
|
+ this.highLight.distance = L.MinDis;
|
|
|
+ this.highLight.point = L.Point;
|
|
|
+ this.highLight.line = L.Line;
|
|
|
+ this.highLight.visible = true;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } // Function absorbSpace()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 吸附空间点
|
|
|
+ *
|
|
|
+ * @param event 鼠标事件对象
|
|
|
+ * @param absorbLen 吸附距离
|
|
|
+ * @return MinDis 吸附的点
|
|
|
+ */
|
|
|
+ absorbSpacePoint(event: SMouseEvent, absorbLen: number): MinDis {
|
|
|
+ let minPointDis = Number.MAX_SAFE_INTEGER;
|
|
|
+ let Point;
|
|
|
+ this.spaceList.map((space): void => {
|
|
|
+ if (
|
|
|
+ EditScence.isPointInAbsorbArea(
|
|
|
+ new SPoint(event.x, event.y),
|
|
|
+ space.minX,
|
|
|
+ space.maxX,
|
|
|
+ space.minY,
|
|
|
+ space.maxY
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ space.data.OutLine.forEach((item): void => {
|
|
|
+ let minDis = SMathUtil.getMinDisPoint(
|
|
|
+ new SPoint(event.x, event.y),
|
|
|
+ item
|
|
|
+ );
|
|
|
+ if (
|
|
|
+ minDis &&
|
|
|
+ minDis.MinDis < absorbLen &&
|
|
|
+ minDis.MinDis < minPointDis
|
|
|
+ ) {
|
|
|
+ minPointDis = minDis.MinDis;
|
|
|
+ Point = minDis.Point;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return {
|
|
|
+ MinDis: minPointDis,
|
|
|
+ Point: Point
|
|
|
+ };
|
|
|
+ } // Function absorbSpacePoint()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 吸附空间线
|
|
|
+ *
|
|
|
+ * @param event 鼠标事件对象
|
|
|
+ * @param absorbLen 吸附距离
|
|
|
+ * @return PointToLine 吸附的线
|
|
|
+ */
|
|
|
+ absorbSpaceLine(event: SMouseEvent, absorbLen: number): PointToLine {
|
|
|
+ let minPointDis = Number.MAX_SAFE_INTEGER;
|
|
|
+ let Point, Line;
|
|
|
+ this.spaceList.forEach((space): void => {
|
|
|
+ if (
|
|
|
+ EditScence.isPointInAbsorbArea(
|
|
|
+ new SPoint(event.x, event.y),
|
|
|
+ space.minX,
|
|
|
+ space.maxX,
|
|
|
+ space.minY,
|
|
|
+ space.maxY
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ space.data.OutLine.forEach((item): void => {
|
|
|
+ let minDisLine = SMathUtil.getMinDisLine(
|
|
|
+ new SPoint(event.x, event.y),
|
|
|
+ item
|
|
|
+ );
|
|
|
+ if (
|
|
|
+ minDisLine &&
|
|
|
+ minDisLine.MinDis < absorbLen &&
|
|
|
+ minDisLine.MinDis < minPointDis
|
|
|
+ ) {
|
|
|
+ minPointDis = minDisLine.MinDis;
|
|
|
+ Point = minDisLine.Point;
|
|
|
+ Line = minDisLine.Line;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return {
|
|
|
+ MinDis: minPointDis,
|
|
|
+ Point: Point,
|
|
|
+ Line: Line
|
|
|
+ };
|
|
|
+ } // Function absorbSpaceLine()
|
|
|
}
|