From 76fb92f18f5aebff32b7ba13008b0c0a8955bd4f Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期二, 05 三月 2024 17:25:34 +0800
Subject: [PATCH] #
---
zy-asrs-flow/src/pages/map/utils.js | 70 +++++++++++++++++++++++++++++++++-
1 files changed, 67 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..c7bb455 100644
--- a/zy-asrs-flow/src/pages/map/utils.js
+++ b/zy-asrs-flow/src/pages/map/utils.js
@@ -12,10 +12,74 @@
mapContainer = param;
}
-export const getRealPosition = (x, y) => {
+export const MapEvent = Object.freeze({
+ SELECTION_BOX: Symbol.for(0),
+ PAN: Symbol.for(1),
+})
+
+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, setDidClickSprite) => {
+ sprite.off('pointerup');
+ sprite.off('pointerdown');
+ sprite.off('click');
+
+ sprite.on("pointerdown", onDragStart);
+
+ let dragTarget;
+ function onDragStart(event) {
+ setDidClickSprite(true);
+ 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) {
+ setDidClickSprite(false);
+ this.parent.off('pointermove');
+ dragTarget.alpha = 1;
+ dragTarget = null;
+ }
+ }
+
+}
+
+export const isSpriteInSelectionBox = (sprite, selectionBox) => {
+ const spriteBounds = sprite.getBounds();
+ const boxBounds = selectionBox.getBounds();
+
+ return spriteBounds.x + spriteBounds.width > boxBounds.x
+ && spriteBounds.x < boxBounds.x + boxBounds.width
+ && spriteBounds.y + spriteBounds.height > boxBounds.y
+ && spriteBounds.y < boxBounds.y + boxBounds.height;
+}
+
+export const markSprite = (sprite) => {
+ sprite.alpha = 0.5;
+}
+
+export const unMarkSprite = (sprite) => {
+ sprite.alpha = 1;
}
\ No newline at end of file
--
Gitblit v1.9.1