|
|
|
@ -104,9 +104,15 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
|
|
|
|
|
// this.lineIconShadow.lineTo(100, 100);
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建单点图标
|
|
|
|
|
/// <summary>
|
|
|
|
|
/** |
|
|
|
|
* 创建单点图标 |
|
|
|
|
* @param source |
|
|
|
|
* @param x |
|
|
|
|
* @param y |
|
|
|
|
* @param width |
|
|
|
|
* @param height |
|
|
|
|
* @param alpha |
|
|
|
|
*/ |
|
|
|
|
private createSinglePointIcon(source: PIXI.Texture, x: number, y: number, width: number, height: number, alpha: number): PIXI.Sprite { |
|
|
|
|
const singlePointIcon = new PIXI.Sprite(source); |
|
|
|
|
singlePointIcon.x = x; |
|
|
|
@ -245,14 +251,18 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
// 测试创建
|
|
|
|
|
/** |
|
|
|
|
* 测试创建 |
|
|
|
|
* @param texture 测试创建 |
|
|
|
|
* @param points 点集合 |
|
|
|
|
*/ |
|
|
|
|
private createLineIconTest(texture: PIXI.Texture, points: PIXI.Point[]) { |
|
|
|
|
const icon = new MultipointIcon(texture, points); |
|
|
|
|
this.backgroundImage.addChild(icon); |
|
|
|
|
} |
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建背景图
|
|
|
|
|
/// <summary>
|
|
|
|
|
/** |
|
|
|
|
* 创建背景图 |
|
|
|
|
*/ |
|
|
|
|
private createBackgroundImage(): void { |
|
|
|
|
this.backgroundImage = PIXI.Sprite.from('assets/images/noImg.png'); |
|
|
|
|
this.backgroundImage.anchor.set(0.5); |
|
|
|
@ -324,10 +334,11 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
|
|
|
|
|
}); |
|
|
|
|
this.app.stage.addChild(this.backgroundImage); |
|
|
|
|
} |
|
|
|
|
/// <summary>
|
|
|
|
|
/// 替换背景图
|
|
|
|
|
/// 参数{source:string} 可以是一个url地址,也可以是本地assets下的一个图片路径
|
|
|
|
|
/// <summary>
|
|
|
|
|
/** |
|
|
|
|
* 替换背景图 |
|
|
|
|
* @param imageUri 可以是一个url地址,也可以是本地assets下的一个图片路径 |
|
|
|
|
* @param imageAngle 图片旋转角度 |
|
|
|
|
*/ |
|
|
|
|
public changeBackgroundImage(imageUri: string, imageAngle: number): void { |
|
|
|
|
this.backgroundImage.texture = PIXI.Texture.from(imageUri); |
|
|
|
|
this.backgroundImage.angle = imageAngle; |
|
|
|
@ -335,13 +346,14 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
|
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 设置背景图角度 |
|
|
|
|
* @param imageAngle 角度值 |
|
|
|
|
*/ |
|
|
|
|
public setBackgroundAngle(imageAngle: number) { |
|
|
|
|
this.backgroundImage.angle = imageAngle; |
|
|
|
|
} |
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建单点图标影子
|
|
|
|
|
/// <summary>
|
|
|
|
|
/** |
|
|
|
|
* 创建单点图标影子 |
|
|
|
|
*/ |
|
|
|
|
private createSinglePointIconShadow(): void { |
|
|
|
|
this.singlePointIconShadow = PIXI.Sprite.from('assets/images/noImg.png'); |
|
|
|
|
this.singlePointIconShadow.width = 32; |
|
|
|
@ -351,43 +363,50 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
|
|
|
|
|
this.singlePointIconShadow.visible = false; |
|
|
|
|
this.app.stage.addChild(this.singlePointIconShadow); |
|
|
|
|
} |
|
|
|
|
/// <summary>
|
|
|
|
|
/// 改变单点图标影子
|
|
|
|
|
/// <summary>
|
|
|
|
|
private changeSinglePointIconShadow(source: string): void { |
|
|
|
|
this.singlePointIconShadow.texture = PIXI.Texture.from(source); |
|
|
|
|
/** |
|
|
|
|
* 改变单点图标影子 |
|
|
|
|
* @param uri 图片地址 |
|
|
|
|
*/ |
|
|
|
|
private changeSinglePointIconShadow(uri: string): void { |
|
|
|
|
this.singlePointIconShadow.texture = PIXI.Texture.from(uri); |
|
|
|
|
this.singlePointIconShadow.visible = true; |
|
|
|
|
} |
|
|
|
|
/// <>
|
|
|
|
|
/// 创建线图标影子
|
|
|
|
|
/// <>
|
|
|
|
|
/** |
|
|
|
|
* 创建线图标影子 |
|
|
|
|
*/ |
|
|
|
|
private createLineIconShadow() { |
|
|
|
|
this.app.stage.addChild(this.lineIconShadow); |
|
|
|
|
} |
|
|
|
|
/// <summary>
|
|
|
|
|
/// 开始绘画单点图标
|
|
|
|
|
/// <summary>
|
|
|
|
|
public beginPaintSinglePointIcon(source: string): void { |
|
|
|
|
/** |
|
|
|
|
* 开始绘画单点图标 |
|
|
|
|
* @param imageUri 图片路径 |
|
|
|
|
*/ |
|
|
|
|
public beginPaintSinglePointIcon(imageUri: string): void { |
|
|
|
|
this.cancelPaint(); |
|
|
|
|
this.paintMode = PaintMode.SinglePointIcon; |
|
|
|
|
this.changeSinglePointIconShadow(source); |
|
|
|
|
this.changeSinglePointIconShadow(imageUri); |
|
|
|
|
} |
|
|
|
|
// 开始绘画多边形
|
|
|
|
|
public beginPaintPolygonIcon(source: string): void { |
|
|
|
|
/** |
|
|
|
|
* 开始绘画多边形 |
|
|
|
|
*/ |
|
|
|
|
public beginPaintPolygonIcon(): void { |
|
|
|
|
this.cancelPaint(); |
|
|
|
|
this.paintMode = PaintMode.PolygonIcon; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
// 开始绘画线
|
|
|
|
|
public beginPaintLineIcon(source: string): void { |
|
|
|
|
/** |
|
|
|
|
* 开始绘制多点图标 |
|
|
|
|
* @param imageUri 图片路径 |
|
|
|
|
*/ |
|
|
|
|
public beginPaintLineIcon(imageUri: string): void { |
|
|
|
|
this.cancelPaint(); |
|
|
|
|
this.paintMode = PaintMode.LineIcon; |
|
|
|
|
this.changeSinglePointIconShadow(source); |
|
|
|
|
this.changeSinglePointIconShadow(imageUri); |
|
|
|
|
// this.lineIconShadow.lineStyle(1, 0xffd900, 1);
|
|
|
|
|
} |
|
|
|
|
/// <summary>
|
|
|
|
|
/// 取消绘画
|
|
|
|
|
/// <summary>
|
|
|
|
|
/** |
|
|
|
|
* 取消绘画 |
|
|
|
|
*/ |
|
|
|
|
private cancelPaint(): void { |
|
|
|
|
switch (this.paintMode) { |
|
|
|
|
case PaintMode.PaintEnd: |
|
|
|
@ -405,24 +424,25 @@ export class WorkingAreaComponent implements OnInit, AfterViewInit {
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/// <summary>
|
|
|
|
|
/// 画圆
|
|
|
|
|
/// <summary>
|
|
|
|
|
/** |
|
|
|
|
* 画圆 |
|
|
|
|
* @param x 半径 |
|
|
|
|
*/ |
|
|
|
|
paintShadowCircle(x: number): void { |
|
|
|
|
this.circleShadow.beginFill(0xFFCC5A); |
|
|
|
|
this.circleShadow.drawCircle(0, 0, x); |
|
|
|
|
this.app.stage.addChild(this.circleShadow); |
|
|
|
|
} |
|
|
|
|
/// <summary>
|
|
|
|
|
/// 取消画圆
|
|
|
|
|
/// <summary>
|
|
|
|
|
/** |
|
|
|
|
* 取消画圆 |
|
|
|
|
*/ |
|
|
|
|
cancelPaintShadowCircle(): void { |
|
|
|
|
this.app.stage.removeChild(this.circleShadow); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/// <summary>
|
|
|
|
|
/// 绘制模式
|
|
|
|
|
/// <summary>
|
|
|
|
|
/** |
|
|
|
|
* 绘制模式 |
|
|
|
|
*/ |
|
|
|
|
enum PaintMode { |
|
|
|
|
SinglePointIcon, |
|
|
|
|
LineIcon, |
|
|
|
@ -431,17 +451,21 @@ enum PaintMode {
|
|
|
|
|
PaintEnd, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// 多点图标
|
|
|
|
|
/** |
|
|
|
|
* 多点连线 |
|
|
|
|
*/ |
|
|
|
|
class MultipointIcon extends PIXI.Container { |
|
|
|
|
public pointsData: PIXI.Point[]; |
|
|
|
|
public pointsGraphics: PIXI.Graphics[] = []; |
|
|
|
|
public iconsTilingSprite: PIXI.TilingSprite[] = []; |
|
|
|
|
/** |
|
|
|
|
* 初始化 |
|
|
|
|
* |
|
|
|
|
* @param texture 图片素材 |
|
|
|
|
* @param points 点集合 |
|
|
|
|
*/ |
|
|
|
|
constructor(texture: PIXI.Texture, data: PIXI.Point[]) { |
|
|
|
|
constructor(texture: PIXI.Texture, points: PIXI.Point[]) { |
|
|
|
|
super(); |
|
|
|
|
this.pointsData = data; |
|
|
|
|
this.pointsData = points; |
|
|
|
|
// 画线图标
|
|
|
|
|
for (let i = 0, count = this.pointsData.length - 1; i < count; i++) { |
|
|
|
|
const pointA = this.pointsData[i]; |
|
|
|
@ -584,8 +608,8 @@ class MultipointIcon extends PIXI.Container {
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 设置原点显示状态 |
|
|
|
|
* value: Boolean |
|
|
|
|
* 设置点显示状态 |
|
|
|
|
* @param value 显示状态 |
|
|
|
|
*/ |
|
|
|
|
public setPointVisiable(value: boolean) { |
|
|
|
|
this.pointsGraphics.forEach((item) => { |
|
|
|
@ -593,3 +617,51 @@ class MultipointIcon extends PIXI.Container {
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface IEventData { |
|
|
|
|
// 事件唯一ID
|
|
|
|
|
uuid: number; |
|
|
|
|
callback: (data: any) => void; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 简单消息分发 |
|
|
|
|
*/ |
|
|
|
|
export default class Event { |
|
|
|
|
|
|
|
|
|
public static eventUuid = 0; |
|
|
|
|
|
|
|
|
|
public static eventList: { [eventName: string]: IEventData[] } = {}; |
|
|
|
|
|
|
|
|
|
public static register(eventName: string, callback: (data: any) => void): number { |
|
|
|
|
this.eventUuid = this.eventUuid + 1; |
|
|
|
|
|
|
|
|
|
if (this.eventList[eventName] === undefined) { |
|
|
|
|
this.eventList[eventName] = []; |
|
|
|
|
} |
|
|
|
|
this.eventList[eventName][this.eventUuid] = { uuid: this.eventUuid, callback }; |
|
|
|
|
|
|
|
|
|
return this.eventUuid; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static unregister(eventName: string, tag: number) { |
|
|
|
|
if (tag == null) { |
|
|
|
|
this.eventList[eventName] = undefined; |
|
|
|
|
} else { |
|
|
|
|
if (this.eventList[eventName] !== undefined && this.eventList[eventName][tag] !== undefined) { |
|
|
|
|
this.eventList[eventName][tag] = undefined; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static dispatch(eventName: string, data: any) { |
|
|
|
|
const eventList: IEventData[] = this.eventList[eventName]; |
|
|
|
|
if (eventList !== undefined) { |
|
|
|
|
for (const key in eventList) { |
|
|
|
|
if (eventList[key].callback !== undefined) { |
|
|
|
|
eventList[key].callback(data); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|