| | |
| | | import React, { useState, useRef, useEffect } from 'react'; |
| | | import { Col, Form, Modal, Row, Checkbox, Image, Tree, Drawer, Space, Button, Card } from 'antd'; |
| | | import { FormattedMessage, useIntl, useModel } from '@umijs/max'; |
| | | import * as PIXI from 'pixi.js'; |
| | | |
| | | import agv from '/public/img/map/agv.svg' |
| | | |
| | | const Edit = (props) => { |
| | | const [dragging, setDragging] = useState(false); |
| | | const [dragImage, setDragImage] = useState(null); |
| | | |
| | | useEffect(() => { |
| | | const handleMouseMove = (e) => { |
| | | if (dragging) { |
| | | props.onDrop(e.clientX, e.clientY); |
| | | setDragging(false); |
| | | props.onCancel(); |
| | | } |
| | | }; |
| | | window.addEventListener('mousemove', handleMouseMove); |
| | | return () => window.removeEventListener('mousemove', handleMouseMove); |
| | | }, [dragging, props.onDrop, props.onCancel]); |
| | | |
| | | const onDragStart = (e) => { |
| | | setDragging(true) |
| | | }; |
| | | |
| | | return ( |
| | | <> |
| | | <Drawer |
| | |
| | | } |
| | | > |
| | | <Card> |
| | | <Image |
| | | <Image |
| | | src={agv} |
| | | width='50px' |
| | | preview={false} |
| | | draggable="true" |
| | | onDragStart={onDragStart} |
| | | /> |
| | | </Card> |
| | | </Drawer> |
| | |
| | | height: window.innerHeight, |
| | | }); |
| | | |
| | | let mapContainer = new PIXI.Container(); |
| | | mapContainer.name = "mapContainer"; |
| | | mapContainer.data = {}; |
| | | app.stage.addChild(mapContainer); |
| | | |
| | | React.useEffect(() => { |
| | | const handleResize = () => { |
| | | setWindowSize({ |
| | |
| | | app.stage.hitArea = app.screen; |
| | | globalThis.__PIXI_APP__ = app; |
| | | mapRef.current.appendChild(app.view); |
| | | |
| | | // mapContainer ------------------------------ |
| | | const mapContainer = new PIXI.Container(); |
| | | mapContainer.name = "mapContainer"; |
| | | mapContainer.data = {}; |
| | | app.stage.addChild(mapContainer); |
| | | |
| | | const texture = PIXI.Texture.from('https://pixijs.com/assets/bunny.png'); |
| | | const bunny = new PIXI.Sprite(texture); |
| | |
| | | setEditModalVisible(true); |
| | | } |
| | | |
| | | const onDrop = (x, y) => { |
| | | const bunny = PIXI.Sprite.from('https://pixijs.io/examples/examples/assets/bunny.png'); |
| | | bunny.anchor.set(0.5); |
| | | bunny.x = x; |
| | | bunny.y = y; |
| | | app.stage.addChild(bunny); |
| | | } |
| | | |
| | | return ( |
| | | <> |
| | | <Layout className={styles.layout}> |
| | |
| | | } |
| | | } |
| | | refCurr={mapRef.current} |
| | | onDrop={onDrop} |
| | | /> |
| | | </> |
| | | ) |