邵佳豪 4 years ago
parent
commit
8c17e54f29
  1. 95
      src/app/working-area/working-area.component.ts

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

@ -83,6 +83,18 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
public copyData: any[] = []; public copyData: any[] = [];
private enterPaintEndButton = PIXI.Sprite.from('assets/images/enterPaintButton.jpg'); private enterPaintEndButton = PIXI.Sprite.from('assets/images/enterPaintButton.jpg');
/**
*
*/
private rectToolGraphics = new PIXI.Graphics();
/**
*
*/
private initialScreenMousePos: PIXI.Point = new PIXI.Point();
/**
*
*/
private finalScreenMousePos: PIXI.Point = new PIXI.Point();
// 根据ID 找到图标 // 根据ID 找到图标
// 根据ID 找到数据 // 根据ID 找到数据
@ -95,6 +107,8 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
this.eventManager.addGlobalEventListener('window', 'keyup', (event: any) => { this.eventManager.addGlobalEventListener('window', 'keyup', (event: any) => {
if (event.keyCode === 17) { if (event.keyCode === 17) {
this.selection.isMultiselection = false; this.selection.isMultiselection = false;
this.rectToolGraphics.visible = false;
this.rectToolGraphics.clear();
} }
if (event.keyCode === 46) { if (event.keyCode === 46) {
this.selection.objects.forEach(item => { this.selection.objects.forEach(item => {
@ -119,9 +133,7 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
}); });
// 测试代码 // 测试代码
this.eventManager.addGlobalEventListener('window', 'keypress', (event: any) => { this.eventManager.addGlobalEventListener('window', 'keypress', (event: any) => {
if (event.keyCode === 97) {
console.log(ObjectID.default.generate());
}
}); });
} }
@ -191,10 +203,6 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
// this.createEnterPaintEndButton(); // this.createEnterPaintEndButton();
// this.backgroundImage.addChild(this.paintingLine); // this.backgroundImage.addChild(this.paintingLine);
this.on('select', obj => { this.on('select', obj => {
// console.log(obj.assetData);
// obj.assetData.Name = '这是我修改了的名字';
// console.log(this.canvasData.originaleveryStoreyData.data[obj.assetData.Id]);
// console.log(this.canvasData.originalcompanyBuildingData.data[obj.assetData.Id]);
if (obj instanceof MultipointIcon) { if (obj instanceof MultipointIcon) {
obj.setPointVisiable(true); obj.setPointVisiable(true);
} else if (obj instanceof PolygonIcon) { } else if (obj instanceof PolygonIcon) {
@ -221,7 +229,18 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
this.refreshPreviewLineSegment(this.currentClickPoint.position, this.circleShadow.position); this.refreshPreviewLineSegment(this.currentClickPoint.position, this.circleShadow.position);
// console.log(this.currentClickPoint.position); if (this.rectToolGraphics.visible === true) {
const init = this.initialScreenMousePos;
const final = this.finalScreenMousePos;
this.rectToolGraphics.clear();
this.rectToolGraphics.lineStyle(2, 0x00ff00, 1);
this.rectToolGraphics.beginFill(0xccccf2, 0.25);
this.rectToolGraphics.drawRect(init.x, init.y, final.x - init.x, final.y - init.y);
this.rectToolGraphics.endFill();
this.rectToolGraphics.closePath();
}
}); });
} }
/** /**
@ -398,19 +417,12 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
this.backgroundImage.sortableChildren = true; this.backgroundImage.sortableChildren = true;
this.backgroundImage this.backgroundImage
.on('mousedown', event => { .on('mousedown', event => {
if (!event.currentTarget.dragging && event.currentTarget.name === this.backgroundImage.name) { if (!event.currentTarget.dragging && this.selection.isMultiselection === false) {
event.currentTarget.data = event.data; event.currentTarget.data = event.data;
// this.oldGroup = this.parentGroup;
// this.parentGroup = dragGroup;
event.currentTarget.dragging = true; event.currentTarget.dragging = true;
// event.currentTarget.scale.x *= 1.1;
// event.currentTarget.scale.y *= 1.1;
event.currentTarget.dragPoint = event.data.getLocalPosition(event.currentTarget.parent); event.currentTarget.dragPoint = event.data.getLocalPosition(event.currentTarget.parent);
event.currentTarget.dragPoint.x -= event.currentTarget.x; event.currentTarget.dragPoint.x -= event.currentTarget.x;
event.currentTarget.dragPoint.y -= event.currentTarget.y; event.currentTarget.dragPoint.y -= event.currentTarget.y;
// tslint:disable-next-line: max-line-length
// 点击背景创建图标
// const pos = this.backgroundImage.toLocal(this.mousePosition);
switch (this.paintMode) { switch (this.paintMode) {
case PaintMode.endPaint: case PaintMode.endPaint:
console.log(this.backgroundImage.toLocal(this.mousePosition)); console.log(this.backgroundImage.toLocal(this.mousePosition));
@ -535,31 +547,47 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
// this.paintingIcon = new PolygonIcon(this.paintPoints, this); // this.paintingIcon = new PolygonIcon(this.paintPoints, this);
break; break;
} }
} else if (!event.currentTarget.dragging && this.selection.isMultiselection === true) {
this.rectToolGraphics.visible = true;
event.currentTarget.dragging = true;
this.initialScreenMousePos = this.backgroundImage.toLocal(this.mousePosition);
this.finalScreenMousePos = this.backgroundImage.toLocal(this.mousePosition);
} }
}) })
.on('mouseup', event => { .on('mouseup', event => {
if (event.currentTarget.dragging && event.currentTarget.name === this.backgroundImage.name) { if (event.currentTarget.dragging) {
event.currentTarget.dragging = false; event.currentTarget.dragging = false;
// this.parentGroup = this.oldGroup;
// event.currentTarget.scale.x /= 1.1;
// event.currentTarget.scale.y /= 1.1;
event.currentTarget.data = null; event.currentTarget.data = null;
} }
if (this.rectToolGraphics.visible === true) {
this.backgroundImage.children.forEach(item => {
if (item instanceof SinglePointIcon
|| item instanceof MultipointIcon
|| item instanceof PolygonIcon) {
if (this.rectToolGraphics.getLocalBounds().contains(item.x, item.y)) {
this.selection.select(item);
}
}
});
this.rectToolGraphics.clear();
this.rectToolGraphics.visible = false;
}
}) })
.on('mouseupoutside', event => { .on('mouseupoutside', event => {
if (event.currentTarget.dragging && event.currentTarget.name === this.backgroundImage.name) { if (event.currentTarget.dragging) {
event.currentTarget.dragging = false; event.currentTarget.dragging = false;
// this.parentGroup = this.oldGroup;
// event.currentTarget.scale.x /= 1.1;
// event.currentTarget.scale.y /= 1.1;
event.currentTarget.data = null; event.currentTarget.data = null;
} }
}) })
.on('mousemove', event => { .on('mousemove', event => {
if (event.currentTarget.dragging && event.currentTarget.name === this.backgroundImage.name) { if (event.currentTarget.dragging && this.selection.isMultiselection === false) {
const newPosition = event.currentTarget.data.getLocalPosition(event.currentTarget.parent); const newPosition = event.currentTarget.data.getLocalPosition(event.currentTarget.parent);
event.currentTarget.x = newPosition.x - event.currentTarget.dragPoint.x; event.currentTarget.x = newPosition.x - event.currentTarget.dragPoint.x;
event.currentTarget.y = newPosition.y - event.currentTarget.dragPoint.y; event.currentTarget.y = newPosition.y - event.currentTarget.dragPoint.y;
} else if (event.currentTarget.dragging && this.selection.isMultiselection === true) {
if (this.rectToolGraphics.visible === true) {
this.finalScreenMousePos = this.backgroundImage.toLocal(this.mousePosition);
}
} }
}).on('rightclick', event => { }).on('rightclick', event => {
event.stopPropagation(); event.stopPropagation();
@ -574,6 +602,7 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
this.createEnterPaintEndButton(); this.createEnterPaintEndButton();
this.backgroundImage.addChild(this.paintingLine); this.backgroundImage.addChild(this.paintingLine);
} }
/** /**
* *
*/ */
@ -635,6 +664,8 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
this.previewLineSegment.visible = false; this.previewLineSegment.visible = false;
this.backgroundImage.addChild(this.currentClickPoint); this.backgroundImage.addChild(this.currentClickPoint);
this.backgroundImage.addChild(this.previewLineSegment); this.backgroundImage.addChild(this.previewLineSegment);
this.backgroundImage.addChild(this.rectToolGraphics);
} }
/** /**
* 线 * 线
@ -1432,17 +1463,21 @@ export class Selection {
* @param obj * @param obj
*/ */
public select(obj: any) { public select(obj: any) {
this.workingArea.emit('select', obj); if (!this.contains(obj)) {
this.objects.push(obj); this.workingArea.emit('select', obj);
this.objects.push(obj);
}
} }
/** /**
* *
* @param obj * @param obj
*/ */
public deselect(obj: any) { public deselect(obj: any) {
this.workingArea.emit('deselect', obj); if (this.contains(obj)) {
const idx = this.objects.findIndex(x => x === obj); this.workingArea.emit('deselect', obj);
this.objects.splice(idx, 1); const idx = this.objects.findIndex(x => x === obj);
this.objects.splice(idx, 1);
}
} }
/** /**
* *

Loading…
Cancel
Save