分隔符
This commit is contained in:
parent
409d78ca79
commit
d677196a5b
5
src/packages/CategoryType.ts
Normal file
5
src/packages/CategoryType.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export enum CategoryType {
|
||||
JK = 'JK', // 交控(11)
|
||||
TH = 'TH', // 通号(12)
|
||||
ZDWX = 'ZDWX', // 浙大网新
|
||||
}
|
94
src/packages/separator/Separator.ts
Normal file
94
src/packages/separator/Separator.ts
Normal file
@ -0,0 +1,94 @@
|
||||
import { Color, Graphics } from 'pixi.js';
|
||||
import { JlGraphic, JlGraphicTemplate } from 'jl-graphic';
|
||||
import { ISeparatorData, SeparatorConstsMap, separatorTypeEnum } from './SeparatorConfig';
|
||||
import { CategoryType } from '../CategoryType';
|
||||
|
||||
let SeparatorConsts = {
|
||||
height: 12,
|
||||
lineWidth: 2,
|
||||
lineColor: '0xFFFFFF',
|
||||
circleColor: '0xEF0200',
|
||||
radius: 5,
|
||||
}
|
||||
|
||||
export class Separator extends JlGraphic {
|
||||
static Type = 'Separator';
|
||||
rectGraphic: Graphics = new Graphics();
|
||||
circleGraphic: Graphics = new Graphics();
|
||||
private categoryType: CategoryType
|
||||
constructor(categoryType: CategoryType) {
|
||||
super(Separator.Type);
|
||||
this.addChild(this.rectGraphic);
|
||||
this.addChild(this.circleGraphic);
|
||||
this.categoryType = categoryType
|
||||
this.getConstDatas();
|
||||
}
|
||||
get datas(): ISeparatorData {
|
||||
return this.getDatas<ISeparatorData>();
|
||||
}
|
||||
|
||||
getConstDatas():void {
|
||||
const constData = SeparatorConstsMap.get(this.categoryType)
|
||||
if (constData) {
|
||||
SeparatorConsts =constData
|
||||
}
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.rectGraphic.clear();
|
||||
this.circleGraphic.clear();
|
||||
}
|
||||
doRepaint(): void {
|
||||
this.clear();
|
||||
const rectGraphic = this.rectGraphic;
|
||||
if (!this.datas.separatorType) {
|
||||
this.datas.separatorType = separatorTypeEnum.endA;
|
||||
}
|
||||
const typeArr = ['section', 'turnout'];
|
||||
if (typeArr.includes(this.datas.separatorType)) {
|
||||
rectGraphic.lineStyle(
|
||||
SeparatorConsts.lineWidth,
|
||||
new Color(SeparatorConsts.lineColor)
|
||||
);
|
||||
rectGraphic.moveTo(0, -SeparatorConsts.height / 2);
|
||||
rectGraphic.lineTo(0, SeparatorConsts.height / 2);
|
||||
if (this.datas.separatorType == 'turnout') {
|
||||
this.circleGraphic.lineStyle(1, SeparatorConsts.circleColor);
|
||||
this.circleGraphic.drawCircle(0, 0, SeparatorConsts.radius);
|
||||
}
|
||||
}
|
||||
const endTypeArr = ['endA', 'endB'];
|
||||
if (endTypeArr.includes(this.datas.separatorType)) {
|
||||
let d = SeparatorConsts.radius;
|
||||
if (this.datas.separatorType == 'endB') {
|
||||
d = -d;
|
||||
}
|
||||
rectGraphic.lineStyle(
|
||||
SeparatorConsts.lineWidth,
|
||||
new Color(SeparatorConsts.lineColor)
|
||||
);
|
||||
rectGraphic.moveTo(0, 0);
|
||||
rectGraphic.lineTo(-d, 0);
|
||||
rectGraphic.lineTo(-d, -d);
|
||||
rectGraphic.lineTo(-d * 3, -d);
|
||||
rectGraphic.moveTo(-d, 0);
|
||||
rectGraphic.lineTo(-d, d);
|
||||
rectGraphic.lineTo(-d * 3, d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class SeparatorTemplate extends JlGraphicTemplate<Separator> {
|
||||
categoryType:CategoryType;
|
||||
constructor(dataTemplate: ISeparatorData,gategoryConsts: CategoryType) {
|
||||
super(Separator.Type, {
|
||||
dataTemplate,
|
||||
});
|
||||
this.categoryType = gategoryConsts;
|
||||
}
|
||||
new(): Separator {
|
||||
const separator = new Separator(this.categoryType);
|
||||
separator.loadData(this.datas);
|
||||
return separator;
|
||||
}
|
||||
}
|
44
src/packages/separator/SeparatorConfig.ts
Normal file
44
src/packages/separator/SeparatorConfig.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import { GraphicData } from "jl-graphic";
|
||||
import { CategoryType } from "../CategoryType";
|
||||
|
||||
export enum separatorTypeEnum {
|
||||
turnout = 'turnout', // 道岔分隔符
|
||||
endA = 'endA', // A端尽头分隔符
|
||||
endB = 'endB', // B端尽头分隔符
|
||||
section = 'section', // 区段分隔符
|
||||
}
|
||||
|
||||
export interface SeparatorConstsConfig{
|
||||
height: number,
|
||||
lineWidth: number,
|
||||
lineColor: string,
|
||||
circleColor: string,
|
||||
radius: number,
|
||||
}
|
||||
|
||||
const THConsts = {
|
||||
height: 12,
|
||||
lineWidth: 2,
|
||||
lineColor: '0xFFFFFF',
|
||||
circleColor: '0xEF0200',
|
||||
radius: 5,
|
||||
};
|
||||
const JKConsts = {
|
||||
height: 12,
|
||||
lineWidth: 2,
|
||||
lineColor: '0x617799',
|
||||
circleColor: '0xEF0200',
|
||||
radius: 5,
|
||||
};
|
||||
|
||||
export const SeparatorConstsMap = new Map<CategoryType, SeparatorConstsConfig>([[CategoryType.JK,JKConsts],[CategoryType.TH,THConsts]])
|
||||
|
||||
export interface ISeparatorData extends GraphicData {
|
||||
get code(): string; // 编号
|
||||
set code(v: string);
|
||||
get separatorType(): string; // 类型
|
||||
set separatorType(v: string);
|
||||
clone(): ISeparatorData;
|
||||
copyFrom(data: ISeparatorData): void;
|
||||
eq(other: ISeparatorData): boolean;
|
||||
}
|
Loading…
Reference in New Issue
Block a user