选区套索内添加图片自动居中
This commit is contained in:
@@ -116,7 +116,7 @@ export class AddLayerCommand extends Command {
|
||||
parentLayer.children.splice(insertIndex, 0, newLayer);
|
||||
|
||||
console.log(
|
||||
`新图层已插入到子图层位置: ${insertIndex} (父图层: ${parentLayer.name})`, newLayer.fabricObjects.length
|
||||
`新图层已插入到子图层位置: ${insertIndex} (父图层: ${parentLayer.name})`
|
||||
);
|
||||
} else {
|
||||
// 当前激活图层是一级图层
|
||||
@@ -2569,7 +2569,6 @@ export class CreateImageLayerCommand extends Command {
|
||||
this.fabricImage = options.fabricImage;
|
||||
this.toolManager = options.toolManager;
|
||||
this.layerName = options.layerName || null;
|
||||
|
||||
this.imageId = generateId("image_");
|
||||
|
||||
// 存储执行过程中的结果
|
||||
@@ -2617,6 +2616,18 @@ export class CreateImageLayerCommand extends Command {
|
||||
this.commands.push(createLayerCmd);
|
||||
this.executedCommands.push(createLayerCmd);
|
||||
|
||||
// 新加功能-选区套索内添加图片自动居中
|
||||
const { parent } = findLayerRecursively(this.layerManager.layers.value, this.newLayerId);
|
||||
if(parent && parent.selectObject){
|
||||
let {top,left,width,height} = parent.selectObject;
|
||||
const ltop = top + height / 2;
|
||||
const lleft = left + width / 2;
|
||||
this.fabricImage.set({
|
||||
top: ltop,
|
||||
left: lleft,
|
||||
})
|
||||
}
|
||||
|
||||
// 2. 添加图片对象到图层命令
|
||||
const addObjectCmd = new AddObjectToLayerCommand({
|
||||
canvas: this.layerManager.canvas,
|
||||
|
||||
Reference in New Issue
Block a user