From 0773d66c559f2d648b62ed8f7db80c7ffc47ce1c Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期六, 02 三月 2024 15:39:31 +0800
Subject: [PATCH] #

---
 zy-asrs-flow/src/pages/map/index.jsx |   20 +++++++++++---------
 zy-asrs-flow/src/pages/map/utils.js  |   21 +++++++++++++++++++++
 2 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/zy-asrs-flow/src/pages/map/index.jsx b/zy-asrs-flow/src/pages/map/index.jsx
index 5c9e828..9e38601 100644
--- a/zy-asrs-flow/src/pages/map/index.jsx
+++ b/zy-asrs-flow/src/pages/map/index.jsx
@@ -6,6 +6,7 @@
 import './index.css'
 import { createStyles } from 'antd-style';
 import Edit from './components/edit'
+import * as Utils from './utils'
 
 const useStyles = createStyles(({ token }) => {
     let dark = token.colorBgBase === '#000';
@@ -59,6 +60,10 @@
     });
 
     React.useEffect(() => {
+
+        Utils.syncApp(app);
+        Utils.syncMapContainer(mapContainer);
+
         const handleResize = () => {
             setWindowSize({
                 width: window.innerWidth,
@@ -104,10 +109,9 @@
     }
 
     const onDrop = (sprite, x, y) => {
-        const rect = app.view.getBoundingClientRect();
-        sprite.anchor.set(0.5);
-        sprite.x = x - rect.left;
-        sprite.y = y - rect.top;
+        const { mapX, mapY } = Utils.getRealPosition(x, y);
+        sprite.x = mapX;
+        sprite.y = mapY;
         mapContainer.addChild(sprite);
     }
 
@@ -126,11 +130,9 @@
 
             <Edit
                 open={editModalVisible}
-                onCancel={
-                    () => {
-                        setEditModalVisible(false);
-                    }
-                }
+                onCancel={() => {
+                    setEditModalVisible(false);
+                }}
                 refCurr={mapRef.current}
                 onDrop={onDrop}
                 mapContainer={mapContainer}
diff --git a/zy-asrs-flow/src/pages/map/utils.js b/zy-asrs-flow/src/pages/map/utils.js
new file mode 100644
index 0000000..dd542bd
--- /dev/null
+++ b/zy-asrs-flow/src/pages/map/utils.js
@@ -0,0 +1,21 @@
+
+
+
+let app = null;
+let mapContainer = null;
+
+export function syncApp(param) {
+    app = param;
+}
+
+export function syncMapContainer(param) {
+    mapContainer = param;
+}
+
+export const getRealPosition = (x, y) => {
+    const rect = app.view.getBoundingClientRect();
+    return {
+        mapX: x - rect.left,
+        mapY: y - rect.top
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.1