import { GraphicDrawAssistant, GraphicInteractionPlugin, AbsorbableLine } from 'jl-graphic'; import { JlStation } from './JlStation.js'; import { CategoryType } from '../Platform/PlatformConfig.js'; class StationDraw extends GraphicDrawAssistant { codeGraph; constructor(app, template, icon) { super(app, template, icon, '车站Station'); this.codeGraph = this.graphicTemplate.new(); this.container.addChild(this.codeGraph); StationInteraction.init(app); } bind() { super.bind(); this.codeGraph.loadData(this.graphicTemplate.datas); this.codeGraph.doRepaint(); } onLeftDown(e) { this.container.position.copyFrom(this.toCanvasCoordinates(e.global)); this.createAndStore(true); } redraw(p) { this.container.position.copyFrom(p); } prepareData(data) { const template = this.graphicTemplate; switch (template.categoryType) { case CategoryType.XiAn: data.hasControl = this.graphicTemplate.hasControl; break; } data.transform = this.container.saveTransform(); return true; } } function buildAbsorbablePositions(station) { const aps = []; const stations = station.queryStore.queryByType(JlStation.Type); const { width } = station.getGraphicApp().canvas; stations.forEach((other) => { if (other.id == station.id) { return; } const ps = other.datas.transform.position; const xs = new AbsorbableLine({ x: 0, y: ps.y }, { x: width, y: ps.y }); aps.push(xs); }); return aps; } class StationInteraction extends GraphicInteractionPlugin { static Name = 'station_transform'; constructor(app) { super(StationInteraction.Name, app); } static init(app) { return new StationInteraction(app); } filter(...grahpics) { return grahpics .filter((g) => g.type === JlStation.Type) .map((g) => g); } bind(g) { g.eventMode = 'static'; g.cursor = 'pointer'; g.scalable = true; g.rotatable = true; g.on('selected', this.onSelected, this); } unbind(g) { g.eventMode = 'none'; g.scalable = false; g.rotatable = false; g.off('selected', this.onSelected, this); } onSelected() { const station = this.app.selectedGraphics[0]; this.app.setOptions({ absorbablePositions: buildAbsorbablePositions(station), }); } } export { StationDraw, StationInteraction };