Browse Source

[优化] 兼容数据

develop
徐振升 4 years ago
parent
commit
30ca66ebc0
  1. 66
      src/app/working-area/working-area.component.ts

66
src/app/working-area/working-area.component.ts

@ -52,6 +52,8 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
// // 确认绘制完成按钮
// public enterPaintEndButton: PIXI.Sprite = PIXI.Sprite.from('assets/images/caiji.jpg');
public outlineFilterBlue = new OutlineFilter(2, 0x00ff00);
// 当前要创建的数据
public currentData: any = null;
ngOnInit(): void {
this.eventManager.addGlobalEventListener('window', 'keydown', (event: any) => {
// console.log('按下了' + event.keyCode);
@ -131,10 +133,8 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
this.on('select', obj => {
if (obj instanceof MultipointIcon) {
console.log('选定多点图形:' + obj);
obj.setPointVisiable(true);
} else if (obj instanceof PolygonIcon) {
console.log('选定多边形:' + obj);
obj.setPointVisiable(true);
} else {
obj.filters = [this.outlineFilterBlue];
@ -142,28 +142,13 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
});
this.on('deselect', obj => {
if (obj instanceof MultipointIcon) {
console.log('取消选定多点图形:' + obj);
obj.setPointVisiable(false);
} else if (obj instanceof PolygonIcon) {
console.log('取消选定多边形:' + obj);
obj.setPointVisiable(false);
} else {
obj.filters = [];
}
});
this.on('deselectAll', objects => {
objects.forEach(element => {
if (element instanceof MultipointIcon) {
console.log('取消全部选定多点图形:' + element);
element.setPointVisiable(false);
} else if (element instanceof PolygonIcon) {
console.log('取消全部选定多边形:' + element);
element.setPointVisiable(false);
} else {
element.filters = [];
}
});
});
this.app.ticker.add((delta) => {
this.mousePosition = this.app.renderer.plugins.interaction.mouse.global;
@ -185,7 +170,8 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
* @param height todo
* @param alpha todo
*/
private createSinglePointIcon(source: PIXI.Texture, x: number, y: number, width: number, height: number, alpha: number): PIXI.Sprite {
private createSinglePointIcon(source: PIXI.Texture, x: number, y: number, width: number, height: number,
alpha: number, name: string): PIXI.Sprite {
const singlePointIcon = new PIXI.Sprite(source);
singlePointIcon.x = x;
singlePointIcon.y = y;
@ -194,10 +180,11 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
singlePointIcon.alpha = alpha;
singlePointIcon.anchor.set(0.5);
singlePointIcon.interactive = true;
singlePointIcon.name = name;
singlePointIcon
.on('mousedown', event => {
event.stopPropagation();
console.log(event);
event.currentTarget.data = event.data;
event.currentTarget.alpha = 0.5;
event.currentTarget.dragging = true;
@ -335,14 +322,14 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
* @param points
*/
private createLineIconTest(texture: PIXI.Texture, points: PIXI.Point[]) {
const icon = new MultipointIcon(texture, points, this);
const icon = new MultipointIcon(texture, points, this, this.currentData.name);
}
/**
*
* @param points
*/
private createPolygonIconTest(points: PIXI.Point[]) {
const icon = new PolygonIcon(points, this);
const icon = new PolygonIcon(points, this, this.currentData.name);
}
/**
*
@ -396,7 +383,7 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
break;
case PaintMode.singlePointIcon:
// tslint:disable-next-line: max-line-length
this.createSinglePointIcon(this.previewSinglePointIcon.texture, this.previewSinglePointIcon.x, this.previewSinglePointIcon.y, 32, 32, 1);
this.createSinglePointIcon(this.previewSinglePointIcon.texture, this.previewSinglePointIcon.x, this.previewSinglePointIcon.y, 32, 32, 1, this.currentData.name);
break;
case PaintMode.lineIcon:
this.previewLineSegment.visible = true;
@ -410,7 +397,7 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
if (this.paintingIcon !== null) {
this.backgroundImage.removeChild(this.paintingIcon);
}
this.paintingIcon = new MultipointIcon(this.previewSinglePointIcon.texture, this.paintPoints, this);
this.paintingIcon = new MultipointIcon(this.previewSinglePointIcon.texture, this.paintPoints, this, this.currentData.name);
break;
case PaintMode.polygonIcon:
this.previewLineSegment.visible = true;
@ -540,12 +527,13 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
*
*/
public beginPaint(data: any) {
switch (data.interactiveMode) {
this.currentData = data;
switch (this.currentData.interactiveMode) {
case 0:
this.beginPaintSinglePointIcon(data.imageUrl);
this.beginPaintSinglePointIcon();
break;
case 1:
this.beginPaintLineIcon(data.imageUrl);
this.beginPaintLineIcon();
break;
case 2:
this.beginPaintPolygonIcon();
@ -554,12 +542,11 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
}
/**
*
* @param imageUri
*/
private beginPaintSinglePointIcon(imageUri: string): void {
private beginPaintSinglePointIcon(): void {
this.cancelPaint();
this.paintMode = PaintMode.singlePointIcon;
this.changePreviewSinglePointIcon(imageUri);
this.changePreviewSinglePointIcon(this.currentData.imageUrl);
}
/**
*
@ -571,12 +558,11 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
}
/**
*
* @param imageUri
*/
private beginPaintLineIcon(imageUri: string): void {
private beginPaintLineIcon(): void {
this.cancelPaint();
this.paintMode = PaintMode.lineIcon;
this.previewSinglePointIcon.texture = PIXI.Texture.from(imageUri);
this.previewSinglePointIcon.texture = PIXI.Texture.from(this.currentData.imageUrl);
this.circleShadow.visible = true;
}
/**
@ -621,7 +607,7 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
case PaintMode.polygonIcon:
this.paintingLine.clear();
if (this.paintPoints.length >= 3) {
const polygonIcon = new PolygonIcon(this.paintPoints, this);
const polygonIcon = new PolygonIcon(this.paintPoints, this, this.currentData.name);
}
break;
}
@ -650,8 +636,9 @@ export class MultipointIcon extends PIXI.Container {
* @param texture
* @param points
*/
constructor(texture: PIXI.Texture, points: PIXI.Point[], private workingArea: WorkingAreaComponent) {
constructor(texture: PIXI.Texture, points: PIXI.Point[], private workingArea: WorkingAreaComponent, name: string) {
super();
this.name = name;
this.pointsData = points;
this.workingArea.backgroundImage.addChild(this);
// 画线图标
@ -817,8 +804,9 @@ export class PolygonIcon extends PIXI.Container {
*
* @param points
*/
constructor(private points: PIXI.Point[], private workingArea: WorkingAreaComponent) {
constructor(private points: PIXI.Point[], private workingArea: WorkingAreaComponent, name: string) {
super();
this.name = name;
this.workingArea.backgroundImage.addChild(this);
this.sortableChildren = true;
// 画点
@ -992,7 +980,9 @@ export class Selection {
*
*/
public deselectAll() {
this.workingArea.emit('deselectAll', this.objects);
this.objects.forEach(item => {
this.workingArea.emit('deselect', item);
});
this.objects.splice(0, this.objects.length);
}
/**
@ -1012,6 +1002,8 @@ export class Selection {
* @param objects
*/
public selectAll(objects: any[]) {
this.objects.forEach(item => {
this.select(item);
});
}
}

Loading…
Cancel
Save