|
@@ -46,24 +46,28 @@ export class SZoneLegendItem extends SPolygonItem {
|
|
|
this._status = value;
|
|
|
// 如果状态为show则需清栈
|
|
|
if (value == SItemStatus.Normal) {
|
|
|
- // 计算文本位置
|
|
|
- let x: number = this.getPointList.reduce((pre, cur, index, arr) => {
|
|
|
- return pre + (cur.x / arr.length)
|
|
|
- }, 0),
|
|
|
- y: number = this.getPointList.reduce((pre, cur, index, arr) => {
|
|
|
- return pre + (cur.y / arr.length)
|
|
|
- }, 0);
|
|
|
- this.textItem.moveTo(x, y);
|
|
|
+ // 切换显示状态显示文本
|
|
|
this.showText = true;
|
|
|
+ // 切换显示状态不可移动文本
|
|
|
+ this.textItem.moveable = false;
|
|
|
+
|
|
|
if (this.undoStack) {
|
|
|
this.undoStack.clear();
|
|
|
}
|
|
|
} else if (value == SItemStatus.Edit) {
|
|
|
+ // 切换编辑状态显示文本
|
|
|
this.showText = true;
|
|
|
+ // 切换编辑状态可移动文本
|
|
|
+ this.textItem.moveable = true;
|
|
|
} else if (value == SItemStatus.Create) {
|
|
|
+ // 切换创建状态不显示文本
|
|
|
this.showText = false;
|
|
|
+ // 切换创建状态不可移动文本
|
|
|
+ this.textItem.moveable = false;
|
|
|
}
|
|
|
this.update();
|
|
|
+ console.log("多边形item", this);
|
|
|
+ console.log("文本item", this.textItem);
|
|
|
};
|
|
|
|
|
|
/** 是否显示文字 */
|
|
@@ -99,10 +103,10 @@ export class SZoneLegendItem extends SPolygonItem {
|
|
|
this.setPointList = [];
|
|
|
let setPointList: SPoint[];
|
|
|
if (data.OutLine) {
|
|
|
- if (data.OutLine[0][0] instanceof SPoint) {
|
|
|
- this.setPointList = data.OutLine[0];
|
|
|
+ if (data.OutLine[0] instanceof SPoint) {
|
|
|
+ this.setPointList = data.OutLine;
|
|
|
} else {
|
|
|
- setPointList = data.OutLine[0].map(i => {
|
|
|
+ setPointList = data.OutLine.map(i => {
|
|
|
return (new SPoint(i.X, i.Y))
|
|
|
})
|
|
|
this.setPointList = setPointList;
|
|
@@ -121,17 +125,39 @@ export class SZoneLegendItem extends SPolygonItem {
|
|
|
if (data.Properties.fillColor) {
|
|
|
this.fillColor = data.Properties.fillColor.includes('#') ? new SColor(data.Properties.fillColor) : new SColor(hexify(data.Properties.fillColor))
|
|
|
}
|
|
|
+ if (data.Properties.TextPos) {
|
|
|
+ this.textItem.moveTo(data.Properties.TextPos.x, data.Properties.TextPos.y);
|
|
|
+ }
|
|
|
// if( data.Properties.LineDash){
|
|
|
// this.LineDash =this._legend.Properties.LineDash
|
|
|
// }
|
|
|
- console.log(this);
|
|
|
}
|
|
|
+ // 监听多边形创建完成事件,并动态计算文本位置
|
|
|
+ this.connect("finishCreated",this, () => {
|
|
|
+ // 计算文本位置
|
|
|
+ let x: number = this.getPointList.reduce((pre, cur, index, arr) => {
|
|
|
+ return pre + (cur.x / arr.length)
|
|
|
+ }, 0),
|
|
|
+ y: number = this.getPointList.reduce((pre, cur, index, arr) => {
|
|
|
+ return pre + (cur.y / arr.length)
|
|
|
+ }, 0);
|
|
|
+ this.textItem.moveTo(x, y);
|
|
|
+ })
|
|
|
}
|
|
|
+
|
|
|
toData(): any {
|
|
|
+ this.data.Pos = {X: this.x, Y: this.y};
|
|
|
+ this.data.Properties.Text = this.text;
|
|
|
this.data.Properties.fillColor = this.fillColor.value;
|
|
|
this.data.Properties.strokeColor = this.strokeColor.value;
|
|
|
this.data.Properties.lineWidth = this.lineWidth;
|
|
|
- this.data.OutLine = [this.getPointList];
|
|
|
+ this.data.OutLine = this.getPointList.map(pos => {
|
|
|
+ return {
|
|
|
+ X: pos.x,
|
|
|
+ Y: pos.y
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.data.Properties.TextPos = this.textItem.pos;
|
|
|
return this.data;
|
|
|
}
|
|
|
|