站台初提交,待完善
This commit is contained in:
parent
b0361df600
commit
eb7bf48ada
34
components/Platform/Platform.d.ts
vendored
Normal file
34
components/Platform/Platform.d.ts
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { JlGraphic, JlGraphicTemplate } from "jl-graphic";
|
||||||
|
import { Container, Graphics } from 'pixi.js';
|
||||||
|
import { CategoryType, DoorConstsConfig, IPlatformData, IPlatformState, PlatformConstsConfig } from './PlatformConfig';
|
||||||
|
declare class RectGraphic extends Container {
|
||||||
|
static Type: string;
|
||||||
|
rectGraphic: Graphics;
|
||||||
|
constructor();
|
||||||
|
draw(platformConsts: PlatformConstsConfig): void;
|
||||||
|
clear(): void;
|
||||||
|
}
|
||||||
|
declare class DoorGraphic extends Container {
|
||||||
|
static Type: string;
|
||||||
|
doorGraphic: Graphics;
|
||||||
|
doorCloseGraphic: Graphics;
|
||||||
|
constructor();
|
||||||
|
draw(platformConsts: PlatformConstsConfig, doorConstsConfig: DoorConstsConfig): void;
|
||||||
|
clear(): void;
|
||||||
|
}
|
||||||
|
export declare class Platform extends JlGraphic {
|
||||||
|
static Type: string;
|
||||||
|
private categoryType;
|
||||||
|
rectGraphic: RectGraphic;
|
||||||
|
doorGraphic: DoorGraphic;
|
||||||
|
constructor(categoryType: CategoryType);
|
||||||
|
get datas(): IPlatformData;
|
||||||
|
get states(): IPlatformState;
|
||||||
|
doRepaint(): void;
|
||||||
|
}
|
||||||
|
export declare class PlatformTemplate extends JlGraphicTemplate<Platform> {
|
||||||
|
categoryType: CategoryType;
|
||||||
|
constructor(dataTemplate: IPlatformData, stateTemplate: IPlatformState, gategoryConsts: CategoryType);
|
||||||
|
new(): Platform;
|
||||||
|
}
|
||||||
|
export {};
|
101
components/Platform/Platform.js
Normal file
101
components/Platform/Platform.js
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
import { JlGraphic, JlGraphicTemplate, getRectangleCenter } from 'jl-graphic';
|
||||||
|
import { Container, Graphics, Color, Rectangle } from 'pixi.js';
|
||||||
|
import { platformConstsMap } from './PlatformConfig.js';
|
||||||
|
|
||||||
|
class RectGraphic extends Container {
|
||||||
|
static Type = 'RectPlatForm';
|
||||||
|
rectGraphic;
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.rectGraphic = new Graphics();
|
||||||
|
this.addChild(this.rectGraphic);
|
||||||
|
}
|
||||||
|
draw(platformConsts) {
|
||||||
|
const rectGraphic = this.rectGraphic;
|
||||||
|
const fillColor = platformConsts.rectColor;
|
||||||
|
rectGraphic
|
||||||
|
.clear()
|
||||||
|
.lineStyle(platformConsts.lineWidth, new Color(fillColor))
|
||||||
|
.beginFill(fillColor, 1)
|
||||||
|
.drawRect(0, 0, platformConsts.width, platformConsts.height).endFill;
|
||||||
|
rectGraphic.pivot = getRectangleCenter(new Rectangle(0, 0, platformConsts.width, platformConsts.height));
|
||||||
|
}
|
||||||
|
clear() {
|
||||||
|
this.rectGraphic.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class DoorGraphic extends Container {
|
||||||
|
static Type = 'Door';
|
||||||
|
doorGraphic;
|
||||||
|
doorCloseGraphic;
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.doorGraphic = new Graphics();
|
||||||
|
this.doorCloseGraphic = new Graphics();
|
||||||
|
this.addChild(this.doorGraphic);
|
||||||
|
this.addChild(this.doorCloseGraphic);
|
||||||
|
}
|
||||||
|
draw(platformConsts, doorConstsConfig) {
|
||||||
|
const doorGraphic = this.doorGraphic;
|
||||||
|
const doorCloseGraphic = this.doorCloseGraphic;
|
||||||
|
let lineColor = doorConstsConfig.doorGreen;
|
||||||
|
doorGraphic.clear()
|
||||||
|
.lineStyle(platformConsts.lineWidth, new Color(lineColor))
|
||||||
|
.moveTo(-platformConsts.width / 2 - platformConsts.lineWidth / 2, 0)
|
||||||
|
.lineTo(-doorConstsConfig.doorOpenSpacing, 0)
|
||||||
|
.moveTo(doorConstsConfig.doorOpenSpacing, 0)
|
||||||
|
.lineTo(platformConsts.width / 2 + platformConsts.lineWidth / 2, 0);
|
||||||
|
//屏蔽门闭合
|
||||||
|
doorCloseGraphic.clear()
|
||||||
|
.lineStyle(platformConsts.lineWidth, new Color(lineColor))
|
||||||
|
.moveTo(-doorConstsConfig.doorOpenSpacing, 0)
|
||||||
|
.lineTo(doorConstsConfig.doorOpenSpacing, 0);
|
||||||
|
}
|
||||||
|
clear() {
|
||||||
|
this.doorGraphic.clear();
|
||||||
|
this.doorCloseGraphic.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Platform extends JlGraphic {
|
||||||
|
static Type = 'Platform';
|
||||||
|
categoryType;
|
||||||
|
rectGraphic = new RectGraphic();
|
||||||
|
doorGraphic = new DoorGraphic();
|
||||||
|
constructor(categoryType) {
|
||||||
|
super(Platform.Type);
|
||||||
|
this.categoryType = categoryType;
|
||||||
|
this.addChild(this.rectGraphic);
|
||||||
|
this.addChild(this.doorGraphic);
|
||||||
|
}
|
||||||
|
get datas() {
|
||||||
|
return this.getDatas();
|
||||||
|
}
|
||||||
|
get states() {
|
||||||
|
return this.getStates();
|
||||||
|
}
|
||||||
|
doRepaint() {
|
||||||
|
this.doorGraphic.clear();
|
||||||
|
const platformConsts = platformConstsMap.get(this.categoryType);
|
||||||
|
if (platformConsts) {
|
||||||
|
this.rectGraphic.draw(platformConsts);
|
||||||
|
if (platformConsts.doorGraphic) {
|
||||||
|
this.doorGraphic.draw(platformConsts, platformConsts.doorGraphic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class PlatformTemplate extends JlGraphicTemplate {
|
||||||
|
categoryType;
|
||||||
|
constructor(dataTemplate, stateTemplate, gategoryConsts) {
|
||||||
|
super(Platform.Type, { dataTemplate, stateTemplate });
|
||||||
|
this.categoryType = gategoryConsts;
|
||||||
|
}
|
||||||
|
new() {
|
||||||
|
const g = new Platform(this.categoryType);
|
||||||
|
g.loadData(this.datas);
|
||||||
|
g.loadState(this.states);
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Platform, PlatformTemplate };
|
30
components/Platform/PlatformConfig.d.ts
vendored
Normal file
30
components/Platform/PlatformConfig.d.ts
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { GraphicData, GraphicState } from "jl-graphic";
|
||||||
|
export declare enum CategoryType {
|
||||||
|
JK = "JK",// 交控(11)
|
||||||
|
TH = "TH",// 通号(12)
|
||||||
|
ZDWX = "ZDWX"
|
||||||
|
}
|
||||||
|
export interface PlatformConstsConfig {
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
lineWidth: number;
|
||||||
|
rectColor: string;
|
||||||
|
doorGraphic?: DoorConstsConfig;
|
||||||
|
}
|
||||||
|
export interface DoorConstsConfig {
|
||||||
|
doorOpenSpacing: number;
|
||||||
|
doorGreen: string;
|
||||||
|
}
|
||||||
|
export declare const platformConstsMap: Map<CategoryType, PlatformConstsConfig>;
|
||||||
|
export interface IPlatformData extends GraphicData {
|
||||||
|
code: string;
|
||||||
|
refStation: string;
|
||||||
|
refSection: string;
|
||||||
|
refEsbRelayCode?: string;
|
||||||
|
clone(): IPlatformData;
|
||||||
|
copyFrom(data: IPlatformData): void;
|
||||||
|
eq(other: IPlatformData): boolean;
|
||||||
|
}
|
||||||
|
export interface IPlatformState extends GraphicState {
|
||||||
|
id?: number;
|
||||||
|
}
|
25
components/Platform/PlatformConfig.js
Normal file
25
components/Platform/PlatformConfig.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
var CategoryType;
|
||||||
|
(function (CategoryType) {
|
||||||
|
CategoryType["JK"] = "JK";
|
||||||
|
CategoryType["TH"] = "TH";
|
||||||
|
CategoryType["ZDWX"] = "ZDWX";
|
||||||
|
})(CategoryType || (CategoryType = {}));
|
||||||
|
const jkConsts = {
|
||||||
|
width: 80,
|
||||||
|
height: 30,
|
||||||
|
lineWidth: 3,
|
||||||
|
rectColor: '0xffffff',
|
||||||
|
};
|
||||||
|
const thConsts = {
|
||||||
|
width: 90,
|
||||||
|
height: 20,
|
||||||
|
lineWidth: 3,
|
||||||
|
rectColor: '#f00',
|
||||||
|
doorGraphic: {
|
||||||
|
doorOpenSpacing: 15,
|
||||||
|
doorGreen: '0x00FF00',
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const platformConstsMap = new Map([[CategoryType.JK, jkConsts], [CategoryType.TH, thConsts]]);
|
||||||
|
|
||||||
|
export { CategoryType, platformConstsMap };
|
180
src/packages/Platform/Platform.ts
Normal file
180
src/packages/Platform/Platform.ts
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
import { GraphicState, JlGraphic, JlGraphicTemplate, distance2, getRectangleCenter } from "jl-graphic";
|
||||||
|
import { Container,Graphics,Rectangle,Color } from 'pixi.js'
|
||||||
|
import {CategoryType, DoorConstsConfig, IPlatformData, IPlatformState, PlatformConstsConfig, platformConstsMap }from './PlatformConfig'
|
||||||
|
|
||||||
|
class RectGraphic extends Container {
|
||||||
|
static Type = 'RectPlatForm';
|
||||||
|
rectGraphic: Graphics;
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.rectGraphic = new Graphics();
|
||||||
|
this.addChild(this.rectGraphic);
|
||||||
|
}
|
||||||
|
draw(platformConsts: PlatformConstsConfig): void {
|
||||||
|
const rectGraphic = this.rectGraphic;
|
||||||
|
const fillColor = platformConsts.rectColor;
|
||||||
|
rectGraphic
|
||||||
|
.clear()
|
||||||
|
.lineStyle(platformConsts.lineWidth, new Color(fillColor))
|
||||||
|
.beginFill(fillColor, 1)
|
||||||
|
.drawRect(0, 0, platformConsts.width, platformConsts.height).endFill;
|
||||||
|
rectGraphic.pivot = getRectangleCenter(
|
||||||
|
new Rectangle(0, 0, platformConsts.width, platformConsts.height)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
clear(): void {
|
||||||
|
this.rectGraphic.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DoorGraphic extends Container {
|
||||||
|
static Type = 'Door';
|
||||||
|
doorGraphic: Graphics;
|
||||||
|
doorCloseGraphic: Graphics;
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.doorGraphic = new Graphics();
|
||||||
|
this.doorCloseGraphic = new Graphics();
|
||||||
|
this.addChild(this.doorGraphic);
|
||||||
|
this.addChild(this.doorCloseGraphic);
|
||||||
|
}
|
||||||
|
draw(platformConsts: PlatformConstsConfig,doorConstsConfig:DoorConstsConfig): void {
|
||||||
|
const doorGraphic = this.doorGraphic;
|
||||||
|
const doorCloseGraphic = this.doorCloseGraphic;
|
||||||
|
let lineColor = doorConstsConfig.doorGreen;
|
||||||
|
doorGraphic.clear()
|
||||||
|
.lineStyle(platformConsts.lineWidth, new Color(lineColor))
|
||||||
|
.moveTo(
|
||||||
|
-platformConsts.width / 2 - platformConsts.lineWidth / 2,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
.lineTo(-doorConstsConfig.doorOpenSpacing, 0)
|
||||||
|
.moveTo(doorConstsConfig.doorOpenSpacing, 0)
|
||||||
|
.lineTo(
|
||||||
|
platformConsts.width / 2 + platformConsts.lineWidth / 2,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
//屏蔽门闭合
|
||||||
|
doorCloseGraphic.clear()
|
||||||
|
.lineStyle(platformConsts.lineWidth, new Color(lineColor))
|
||||||
|
.moveTo(-doorConstsConfig.doorOpenSpacing, 0)
|
||||||
|
.lineTo(doorConstsConfig.doorOpenSpacing, 0)
|
||||||
|
}
|
||||||
|
clear(): void {
|
||||||
|
this.doorGraphic.clear();
|
||||||
|
this.doorCloseGraphic.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Platform extends JlGraphic {
|
||||||
|
static Type = 'Platform';
|
||||||
|
private categoryType:CategoryType
|
||||||
|
rectGraphic: RectGraphic = new RectGraphic();
|
||||||
|
doorGraphic: DoorGraphic = new DoorGraphic();
|
||||||
|
constructor(categoryType:CategoryType) {
|
||||||
|
super(Platform.Type);
|
||||||
|
this.categoryType = categoryType
|
||||||
|
this.addChild(this.rectGraphic);
|
||||||
|
this.addChild(this.doorGraphic);
|
||||||
|
}
|
||||||
|
|
||||||
|
get datas() {
|
||||||
|
return this.getDatas<IPlatformData>();
|
||||||
|
}
|
||||||
|
get states(): IPlatformState {
|
||||||
|
return this.getStates<IPlatformState>();
|
||||||
|
}
|
||||||
|
doRepaint(): void {
|
||||||
|
this.doorGraphic.clear();
|
||||||
|
const platformConsts=platformConstsMap.get(this.categoryType)
|
||||||
|
if(platformConsts){
|
||||||
|
this.rectGraphic.draw(platformConsts);
|
||||||
|
if(platformConsts.doorGraphic){
|
||||||
|
this.doorGraphic.draw(platformConsts,platformConsts.doorGraphic)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* buildRelation() {
|
||||||
|
const stationas = this.queryStore.queryByType<Station>(Station.Type);
|
||||||
|
for (let i = 0; i < stationas.length; i++) {
|
||||||
|
const sP = stationas[i].localBoundsToCanvasPoints();
|
||||||
|
if (this.x > sP[0].x && this.x < sP[1].x) {
|
||||||
|
this.relationManage.addRelation(this, stationas[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const sections = this.queryStore.queryByType<Section>(Section.Type);
|
||||||
|
const minDistanceRefSections: Section[] = [];
|
||||||
|
sections.forEach((section) => {
|
||||||
|
const sP = section.localBoundsToCanvasPoints();
|
||||||
|
if (this.x > sP[0].x && this.x < sP[1].x) {
|
||||||
|
minDistanceRefSections.push(section);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (minDistanceRefSections) {
|
||||||
|
const refSection = minDistanceRefSections.reduce((prev, cur) => {
|
||||||
|
return distance2(
|
||||||
|
prev.localToCanvasPoint(getRectangleCenter(prev.getLocalBounds())),
|
||||||
|
this.position
|
||||||
|
) >
|
||||||
|
distance2(
|
||||||
|
cur.localToCanvasPoint(getRectangleCenter(cur.getLocalBounds())),
|
||||||
|
this.position
|
||||||
|
)
|
||||||
|
? cur
|
||||||
|
: prev;
|
||||||
|
});
|
||||||
|
this.relationManage.deleteRelationOfGraphicAndOtherType(
|
||||||
|
this,
|
||||||
|
Section.Type
|
||||||
|
);
|
||||||
|
this.relationManage.addRelation(this, refSection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
saveRelations() {
|
||||||
|
const refStation = this.relationManage
|
||||||
|
.getRelationsOfGraphicAndOtherType(this, Station.Type)
|
||||||
|
.map((relation) => relation.getOtherGraphic<Station>(this).datas.id);
|
||||||
|
if (refStation.length) {
|
||||||
|
this.datas.refStation = refStation[0];
|
||||||
|
}
|
||||||
|
const refSection = this.relationManage
|
||||||
|
.getRelationsOfGraphicAndOtherType(this, Section.Type)
|
||||||
|
.map((relation) => relation.getOtherGraphic<Section>(this).datas.id);
|
||||||
|
if (refSection.length) {
|
||||||
|
this.datas.refSection = refSection[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadRelations() {
|
||||||
|
if (this.datas.refStation) {
|
||||||
|
this.relationManage.addRelation(
|
||||||
|
this,
|
||||||
|
this.queryStore.queryById<Platform>(this.datas.refStation)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (this.datas.refSection) {
|
||||||
|
this.relationManage.addRelation(
|
||||||
|
this,
|
||||||
|
this.queryStore.queryById<Platform>(this.datas.refSection)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} */
|
||||||
|
}
|
||||||
|
|
||||||
|
export class PlatformTemplate extends JlGraphicTemplate<Platform> {
|
||||||
|
categoryType:CategoryType;
|
||||||
|
constructor(
|
||||||
|
dataTemplate: IPlatformData,
|
||||||
|
stateTemplate: IPlatformState,
|
||||||
|
gategoryConsts: CategoryType
|
||||||
|
) {
|
||||||
|
super(Platform.Type, { dataTemplate, stateTemplate });
|
||||||
|
this.categoryType = gategoryConsts;
|
||||||
|
}
|
||||||
|
new(): Platform {
|
||||||
|
const g = new Platform(this.categoryType);
|
||||||
|
g.loadData(this.datas);
|
||||||
|
g.loadState(this.states);
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
}
|
56
src/packages/Platform/PlatformConfig.ts
Normal file
56
src/packages/Platform/PlatformConfig.ts
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import { GraphicData, GraphicState } from "jl-graphic";
|
||||||
|
|
||||||
|
export enum CategoryType {
|
||||||
|
JK = 'JK', // 交控(11)
|
||||||
|
TH = 'TH', // 通号(12)
|
||||||
|
ZDWX = 'ZDWX', // 浙大网新
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PlatformConstsConfig{
|
||||||
|
width: number,
|
||||||
|
height: number,
|
||||||
|
lineWidth: number,
|
||||||
|
rectColor: string, //站台颜色
|
||||||
|
doorGraphic?:DoorConstsConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DoorConstsConfig{
|
||||||
|
doorOpenSpacing:number,
|
||||||
|
doorGreen:string,
|
||||||
|
}
|
||||||
|
|
||||||
|
const jkConsts = {
|
||||||
|
width: 80,
|
||||||
|
height: 30,
|
||||||
|
lineWidth: 3,
|
||||||
|
rectColor: '0xffffff',
|
||||||
|
};
|
||||||
|
|
||||||
|
const thConsts = {
|
||||||
|
width: 90,
|
||||||
|
height: 20,
|
||||||
|
lineWidth: 3,
|
||||||
|
rectColor: '#f00',
|
||||||
|
doorGraphic:{
|
||||||
|
doorOpenSpacing: 15,
|
||||||
|
doorGreen:'0x00FF00',
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const platformConstsMap = new Map<CategoryType, PlatformConstsConfig>([[CategoryType.JK,jkConsts],[CategoryType.TH,thConsts]])
|
||||||
|
|
||||||
|
export interface IPlatformData extends GraphicData {
|
||||||
|
code: string;
|
||||||
|
refStation: string;
|
||||||
|
refSection: string;
|
||||||
|
refEsbRelayCode?: string;
|
||||||
|
/* get type(): graphicData.Platform.TypeOfPlatform; //站台上下行
|
||||||
|
set type(v: graphicData.Platform.TypeOfPlatform); */
|
||||||
|
clone(): IPlatformData;
|
||||||
|
copyFrom(data: IPlatformData): void;
|
||||||
|
eq(other: IPlatformData): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IPlatformState extends GraphicState {
|
||||||
|
id?: number;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user