From 6acd06009a8d830f3af2b16220d3ed52810ccf62 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期二, 05 三月 2024 18:18:39 +0800
Subject: [PATCH] #

---
 zy-asrs-flow/src/pages/map/player.js |   61 +++++++++++++++---------------
 1 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/zy-asrs-flow/src/pages/map/player.js b/zy-asrs-flow/src/pages/map/player.js
index ba9447e..f688b42 100644
--- a/zy-asrs-flow/src/pages/map/player.js
+++ b/zy-asrs-flow/src/pages/map/player.js
@@ -5,8 +5,9 @@
 export default class Player {
 
     constructor(dom, dark, didClickSprite) {
+        // not dynamic
         this.darkModel = dark;
-        this.didClickSprite = didClickSprite;   // not dynamic
+        this.didClickSprite = didClickSprite;
         // init
         this.app = generatePixiApp(dark);
         dom.appendChild(this.app.view);
@@ -19,19 +20,17 @@
             event.preventDefault();
         });
 
-        this.pan = false; // 骞崇Щ
-
-        this.activateMapEvent(null, Utils.MapEvent.PAN);
+        // this.activateMapEvent(null);
         this.activateMapScale();
+        this.activateMapPan();
         this.showCoordinates();
         this.appTicker();
     }
 
     activateMapEvent = (leftEvent, rightEvent) => {
         if (this.mapEvent) {
-            this.app.view.removeEventListener('mousedown', this.mapEvent);
+            this.mapContainer.parent.off('mousedown', this.mapEvent);
         }
-
         this.mapEvent = (event) => {
             // left
             if (event.button === 0 && leftEvent) {
@@ -46,16 +45,12 @@
             // right
             if (event.button === 2 && rightEvent) {
                 switch (rightEvent) {
-                    case Utils.MapEvent.PAN:
-                        this.mapPan(event);
-                        break
                     default:
                         break
                 }
             }
         }
-
-        this.app.view.addEventListener('mousedown', this.mapEvent)
+        this.mapContainer.parent.on('mousedown', this.mapEvent)
     }
 
     mapSelect = (event) => {
@@ -89,9 +84,9 @@
             }
         }
 
-        this.app.view.addEventListener('mousemove', handleMouseMove);
+        this.mapContainer.parent.on('mousemove', handleMouseMove);
 
-        this.app.view.addEventListener('mouseup', (event) => {
+        this.mapContainer.parent.on('mouseup', (event) => {
             if (isSelecting) {
                 if (this.selectedSprites && this.selectedSprites.length > 0) {
                     this.selectedSprites.forEach(child => {
@@ -108,31 +103,37 @@
                 })
                 isSelecting = false;
                 selectionBox.clear();
+
             }
 
-            this.app.view.removeEventListener('mousemove', handleMouseMove);
+            this.mapContainer.parent.off('mousemove', handleMouseMove);
         });
     }
 
-    mapPan = (event) => {
-        this.pan = true;
-        let previousPosition = { x: event.clientX, y: event.clientY };
-        const mouseMoveHandler = (event) => {
-            if (this.pan) {
-                const dx = event.clientX - previousPosition.x;
-                const dy = event.clientY - previousPosition.y;
+    activateMapPan = () => {
+        const mapPanHandle = (event) => {
+            if (event.button === 2) {
+                this.pan = true;
+                let previousPosition = { x: event.clientX, y: event.clientY };
+                const mouseMoveHandler = (event) => {
+                    if (this.pan) {
+                        const dx = event.clientX - previousPosition.x;
+                        const dy = event.clientY - previousPosition.y;
 
-                this.mapContainer.position.x += dx;
-                this.mapContainer.position.y += dy;
+                        this.mapContainer.position.x += dx;
+                        this.mapContainer.position.y += dy;
 
-                previousPosition = { x: event.clientX, y: event.clientY };
+                        previousPosition = { x: event.clientX, y: event.clientY };
+                    }
+                };
+                this.app.view.addEventListener('mousemove', mouseMoveHandler);
+                this.app.view.addEventListener('mouseup', () => {
+                    this.app.view.removeEventListener('mousemove', mouseMoveHandler);
+                    this.pan = false;
+                });
             }
-        };
-        this.app.view.addEventListener('mousemove', mouseMoveHandler);
-        this.app.view.addEventListener('mouseup', () => {
-            this.app.view.removeEventListener('mousemove', mouseMoveHandler);
-            this.pan = false;
-        });
+        }
+        this.app.view.addEventListener('mousedown', mapPanHandle);
     }
 
     activateMapScale = () => {

--
Gitblit v1.9.1