From 20d4a002ea62a173ed8689613503c1f03ab1c7f1 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期六, 16 三月 2024 13:59:36 +0800
Subject: [PATCH] #
---
zy-asrs-flow/src/pages/map/utils.js | 25 ++++++++++++++++++++++++-
zy-asrs-flow/src/pages/map/header/search.jsx | 6 +++++-
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/zy-asrs-flow/src/pages/map/header/search.jsx b/zy-asrs-flow/src/pages/map/header/search.jsx
index 4fb895d..09dedf8 100644
--- a/zy-asrs-flow/src/pages/map/header/search.jsx
+++ b/zy-asrs-flow/src/pages/map/header/search.jsx
@@ -116,7 +116,11 @@
value={curSensorLabel}
onSelect={(value, option) => {
const uuid = option.label?.props?.children?.[1].props.children;
- setCurSensor(Utils.findSpriteByUuid(uuid));
+ const selectSensor = Utils.findSpriteByUuid(uuid);
+ setCurSensor(selectSensor);
+ if (selectSensor) {
+ Utils.beCenter(selectSensor);
+ }
}}
onChange={setCurSensorLabel}
/>
diff --git a/zy-asrs-flow/src/pages/map/utils.js b/zy-asrs-flow/src/pages/map/utils.js
index dfeee52..de532ab 100644
--- a/zy-asrs-flow/src/pages/map/utils.js
+++ b/zy-asrs-flow/src/pages/map/utils.js
@@ -344,7 +344,7 @@
mapContainer.addChild(sprite);
}
})
-
+
}).catch((error) => {
console.error(error);
})
@@ -404,4 +404,27 @@
});
childList = [];
}
+}
+
+export const beCenter = (sprite) => {
+ if (!sprite || !app || !mapContainer) {
+ return;
+ }
+
+ // 鑾峰彇 sprite 鐨勪腑蹇冪偣鍧愭爣
+ let bounds = sprite.getBounds();
+ let centerPoint = {
+ x: bounds.x + bounds.width / 2,
+ y: bounds.y + bounds.height / 2
+ };
+
+ // 璁$畻 sprite 搴斿綋骞崇Щ鐨勫儚绱犻噺浠ヨ兘澶熷皢鍏舵斁缃埌灞忓箷涓績
+ let targetPos = {
+ x: app.renderer.width / 2 - centerPoint.x * this.scale,
+ y: app.renderer.height / 2 - centerPoint.y * this.scale
+ };
+
+ // 浣跨敤 TWEEDLE.Tween 鍔ㄧ敾搴撲负骞崇Щ杩囩▼娣诲姞杩囨浮鏁堟灉
+ new TWEEDLE.Tween(mapContainer.position).easing(TWEEDLE.Easing.Quadratic.Out)
+ .to(targetPos, 200).start();
}
\ No newline at end of file
--
Gitblit v1.9.1