From 25abc0ce6236550a9a91ac3897a46fe07f688a96 Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期三, 17 十二月 2025 16:35:49 +0800
Subject: [PATCH] #

---
 zy-acs-flow/src/map/tool.js      |   56 ++++++++++++++++++++++++++++
 zy-acs-flow/src/map/AreaList.jsx |   11 ++++-
 2 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/zy-acs-flow/src/map/AreaList.jsx b/zy-acs-flow/src/map/AreaList.jsx
index 4fe41e1..e9c545c 100644
--- a/zy-acs-flow/src/map/AreaList.jsx
+++ b/zy-acs-flow/src/map/AreaList.jsx
@@ -15,6 +15,7 @@
 import CloseIcon from '@mui/icons-material/Close';
 import { PAGE_DRAWER_WIDTH } from '@/config/setting';
 import { fetchAreaList } from './http';
+import * as Tool from './tool';
 
 const AreaList = ({
     open,
@@ -37,14 +38,20 @@
         setLoading(true);
         fetchAreaList(zoneId)
             .then((list) => {
-                console.log(list);
-
                 setAreas(Array.isArray(list) ? list : []);
             })
             .finally(() => setLoading(false));
     }, [open, zoneId]);
 
     const handleItemClick = (area) => {
+        if (!area?.id) {
+            return;
+        }
+        const sprite = Tool.findAreaSpriteById(area.id);
+        if (sprite) {
+            Tool.focusAreaSprite(sprite);
+            // Tool.showSelectedEffect?.(sprite);
+        }
         onSelect?.(area);
     };
 
diff --git a/zy-acs-flow/src/map/tool.js b/zy-acs-flow/src/map/tool.js
index 2bd45c6..3d9b4c8 100644
--- a/zy-acs-flow/src/map/tool.js
+++ b/zy-acs-flow/src/map/tool.js
@@ -399,6 +399,20 @@
         .start();
 }
 
+export const findAreaSpriteById = (areaId) => {
+    if (!mapContainer || areaId == null) {
+        return null;
+    }
+    const targetId = String(areaId);
+    for (let i = 0; i < mapContainer.children.length; i += 1) {
+        const child = mapContainer.children[i];
+        if (child?.data?.type === DEVICE_TYPE.AREA && String(child.data?.id) === targetId) {
+            return child;
+        }
+    }
+    return null;
+};
+
 export const clearMapData = () => {
     if (!mapContainer) {
         return;
@@ -1144,3 +1158,45 @@
     clearAreas();
     setShowAreas(false);
 };
+
+export const focusAreaSprite = (sprite) => {
+    if (!sprite || !app || !mapContainer) {
+        return;
+    }
+
+    const data = sprite.data || {};
+    const start = data.start;
+    const end = data.end;
+    const currentScale = Math.abs(mapContainer.scale.x || 1);
+    const boundsBefore = sprite.getBounds();
+    const width = start && end ? Math.abs(end.x - start.x) : boundsBefore.width / currentScale;
+    const height = start && end ? Math.abs(end.y - start.y) : boundsBefore.height / currentScale;
+
+    const paddedWidth = (width || 1000) * 1.25;
+    const paddedHeight = (height || 1000) * 1.25;
+    const viewportWidth = app.renderer.width || 1920;
+    const viewportHeight = app.renderer.height || 1080;
+
+    let focusScale = Math.min(
+        (viewportWidth * 0.65) / paddedWidth,
+        (viewportHeight * 0.65) / paddedHeight
+    );
+    focusScale = Math.min(Math.max(focusScale, 0.03), 0.25);
+
+    mapContainer.scale.set(MAP_MIRROR ? -focusScale : focusScale, focusScale);
+    mapContainer.position.set(0, 0);
+
+    const bounds = sprite.getBounds();
+    const centerX = bounds.x + bounds.width / 2;
+    const centerY = bounds.y + bounds.height / 2;
+
+    const targetPos = {
+        x: viewportWidth / 2 - centerX,
+        y: viewportHeight / 2 - centerY,
+    };
+
+    new TWEEDLE.Tween(mapContainer.position)
+        .easing(TWEEDLE.Easing.Quadratic.Out)
+        .to(targetPos, 500)
+        .start();
+};
\ No newline at end of file

--
Gitblit v1.9.1