From 8822c17c8f7ff9c5b1f0657814e4968f98520a4f Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期一, 04 三月 2024 16:23:28 +0800
Subject: [PATCH] #

---
 zy-asrs-flow/src/pages/map/utils.js |   45 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/zy-asrs-flow/src/pages/map/utils.js b/zy-asrs-flow/src/pages/map/utils.js
index dd542bd..15d222c 100644
--- a/zy-asrs-flow/src/pages/map/utils.js
+++ b/zy-asrs-flow/src/pages/map/utils.js
@@ -12,10 +12,49 @@
     mapContainer = param;
 }
 
-export const getRealPosition = (x, y) => {
+export const getRealPosition = (x, y, mapContainer) => {
     const rect = app.view.getBoundingClientRect();
     return {
-        mapX: x - rect.left,
-        mapY: y - rect.top
+        mapX: (x - rect.left) / mapContainer.scale.x - mapContainer.x / mapContainer.scale.x,
+        mapY: (y - rect.top) / mapContainer.scale.y - mapContainer.y / mapContainer.scale.y
     }
+}
+
+export const initSprite = (sprite) => {
+    sprite.anchor.set(0.5);
+    sprite.cursor = 'pointer';
+    sprite.eventMode = 'static';
+}
+
+export const beMovable = (sprite) => {
+    sprite.off('pointerup');
+    sprite.off('pointerdown');
+    sprite.off('click');
+
+    sprite.on("pointerdown", onDragStart);
+
+    let dragTarget;
+    function onDragStart(event) {
+        dragTarget = event.currentTarget;
+        mapContainer.parent.off('pointermove');
+        mapContainer.parent.on('pointermove', onDragMove, dragTarget);
+
+        mapContainer.parent.off('pointerup');
+        mapContainer.parent.on('pointerup', onDragEnd.bind(mapContainer));
+    }
+
+    function onDragMove(event) {
+        if (this) {
+            this.parent.toLocal(event.global, null, this.position);
+        }
+    }
+
+    function onDragEnd() {
+        if (dragTarget) {
+            this.parent.off('pointermove');
+            dragTarget.alpha = 1;
+            dragTarget = null;
+        }
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.9.1