| | |
| | | draft.addChild(label); |
| | | }; |
| | | |
| | | export const loadAreas = (curZone) => { |
| | | export const loadAreas = (curZone, setCurSprite) => { |
| | | if (!mapContainer) return; |
| | | clearAreas(); |
| | | fetchAreaList(curZone).then((areas) => { |
| | |
| | | if (!start || !end || !name || !id) { |
| | | return; |
| | | } |
| | | const graphics = createAreaGraphic({ name, start, end, color, id }); |
| | | const graphics = createAreaGraphic({ name, start, end, color, id }, setCurSprite); |
| | | if (graphics) { |
| | | mapContainer.addChild(graphics); |
| | | } |
| | |
| | | } |
| | | }; |
| | | |
| | | const createAreaGraphic = ({ name, start, end, color, id }) => { |
| | | const createAreaGraphic = ({ name, start, end, color, id }, setCurSprite) => { |
| | | if (!mapContainer) return null; |
| | | const from = start || { x: 0, y: 0 }; |
| | | const to = end || { x: 0, y: 0 }; |
| | |
| | | draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.AREA, name, color: areaColor, id }; |
| | | draft.eventMode = 'static'; |
| | | draft.cursor = 'pointer'; |
| | | if (setCurSprite) { |
| | | draft.off('click'); |
| | | draft.on('click', () => setCurSprite(draft)); |
| | | } |
| | | return draft; |
| | | }; |
| | | |
| | | export const startAreaDrawing = ({ promptText, onComplete, onFinish } = {}) => { |
| | | export const startAreaDrawing = ({ promptText, onComplete, onFinish, setCurSprite } = {}) => { |
| | | if (!mapContainer || !mapContainer.parent) { |
| | | return false; |
| | | } |
| | |
| | | draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.AREA, name: areaName, color: areaColor }; |
| | | draft.eventMode = 'static'; |
| | | draft.cursor = 'pointer'; |
| | | if (setCurSprite) { |
| | | draft.off('click'); |
| | | draft.on('click', () => setCurSprite(draft)); |
| | | } |
| | | |
| | | if (onComplete) { |
| | | onComplete({ |