Browse Source

锚点问题修改

haojianlong 4 years ago
parent
commit
3b861a4fea
1 changed files with 30 additions and 20 deletions
  1. 30 20
      src/components/mapClass/EditScence.ts

+ 30 - 20
src/components/mapClass/EditScence.ts

@@ -1268,32 +1268,42 @@ export class EditScence extends SGraphScene {
         let minAnchor = null;
         let len: number = -1;
         this.Nodes.forEach(image => {
-            image.showAnchor = false;
+            // image.showAnchor = false;
             if (image.anchorList && image.anchorList.length) {
-                image.anchorList.forEach(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;
-                    }
-                })
+                let scenePoint = image.mapFromScene(event.x, event.y);
+                if (image.contains(scenePoint.x, scenePoint.y)) {
+                    image.anchorList.forEach(anchor => {
+                        let anchorPoint = anchor.mapToScene(0, 0);
+                        let dis = SMathUtil.pointDistance(
+                            event.x,
+                            event.y,
+                            anchorPoint.x,
+                            anchorPoint.y
+                        );
+                        // let dis = SMathUtil.pointDistance(
+                        //     scenePoint.x,
+                        //     scenePoint.y,
+                        //     anchorPoint.x,
+                        //     anchorPoint.y
+                        // );
+                        console.log(dis)
+                        if (len < 0) {
+                            len = anchor.sceneDis;
+                        }
+                        if (dis < len) {
+                            minAnchor = anchor;
+                            len = dis;
+                        }
+                    })
+                }
             }
         })
         console.log('-----------------------')
         console.log(minAnchor)
         console.log('-----------------------')
-        if (minAnchor&&minAnchor.parent) {
-            minAnchor.parent.showAnchor = true
-        }
+        // if (minAnchor&&minAnchor.parent) {
+        //     minAnchor.parent.showAnchor = true
+        // }
         return minAnchor;
     }