#
luxiaotao1123
2024-03-04 b9442775de36686d00ddf32cde34c51b8f8d9551
zy-asrs-flow/src/pages/map/utils.js
@@ -19,3 +19,42 @@
        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) => {
    sprite.off('pointerup');
    sprite.off('pointerdown');
    sprite.off('click');
    sprite.on("pointerdown", onDragStart);
    let dragTarget;
    function onDragStart(event) {
        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) {
            this.parent.off('pointermove');
            dragTarget.alpha = 1;
            dragTarget = null;
        }
    }
}