本文整理汇总了TypeScript中app/model/layers.LayerUtil.findParent方法的典型用法代码示例。如果您正苦于以下问题:TypeScript LayerUtil.findParent方法的具体用法?TypeScript LayerUtil.findParent怎么用?TypeScript LayerUtil.findParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app/model/layers.LayerUtil
的用法示例。
在下文中一共展示了LayerUtil.findParent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: while
tempSelLayers = tempSelLayers.filter(layer => {
if (layer instanceof VectorLayer) {
return false;
}
let p = LayerUtil.findParent(vl, layer.id);
while (p) {
if (_.find(tempSelLayers, l => l.id === p.id)) {
return false;
}
p = LayerUtil.findParent(vl, p.id);
}
return true;
});
示例2: swapLayers
/**
* Replaces an existing layer in the tree with a new layer. Note that
* this method assumes that both layers still have the same children layers.
*/
swapLayers(layerId: string, newLayer: Layer) {
if (layerId === newLayer.id) {
this.updateLayer(newLayer);
return;
}
const vl = this.getVectorLayer();
const parent = LayerUtil.findParent(vl, layerId).clone();
const layerIndex = _.findIndex(parent.children, l => l.id === layerId);
const children = [...parent.children];
children.splice(layerIndex, 1, newLayer);
parent.children = children;
const actions: Action[] = [
new SetVectorLayer(LayerUtil.updateLayer(vl, parent)),
...this.buildCleanupLayerIdActions(layerId),
];
const animation = this.getAnimation();
const oldLayerBlocks = animation.blocks.filter(b => b.layerId === layerId);
const newAnimatableProperties = new Set(newLayer.animatableProperties.keys());
// Preserve any blocks that are still animatable with the new layer.
const newLayerBlocks = oldLayerBlocks
.filter(b => newAnimatableProperties.has(b.propertyName))
.map(b => {
b = b.clone();
b.layerId = newLayer.id;
return b;
});
const newAnimation = animation.clone();
newAnimation.blocks = [
...animation.blocks.filter(b => b.layerId !== layerId),
...newLayerBlocks,
];
actions.push(new SetAnimation(newAnimation));
this.store.dispatch(new BatchAction(...actions));
}
示例3:
tempSelLayers.filter(layer => layer instanceof GroupLayer).forEach(groupLayer => {
// Move children into parent.
const parent = LayerUtil.findParent(vl, groupLayer.id).clone();
const indexInParent = Math.max(
0,
_.findIndex(parent.children, l => l.id === groupLayer.id),
);
const newChildren = [...parent.children];
newChildren.splice(indexInParent, 0, ...groupLayer.children);
parent.children = newChildren;
vl = LayerUtil.updateLayer(vl, parent);
newSelectedLayers.splice(0, 0, ...groupLayer.children);
// Delete the parent.
vl = LayerUtil.removeLayers(vl, groupLayer.id);
});
示例4: addLayer
/**
* Adds a layer to the vector tree.
*/
addLayer(layer: Layer) {
const vl = this.getVectorLayer();
const selectedLayers = this.getSelectedLayers();
if (selectedLayers.length === 1) {
const selectedLayer = selectedLayers[0];
if (!(selectedLayer instanceof VectorLayer)) {
// Add the new layer as a sibling to the currently selected layer.
const parent = LayerUtil.findParent(vl, selectedLayer.id).clone();
parent.children = [...parent.children, layer];
this.updateLayer(parent);
return;
}
}
const vectorLayer = vl.clone();
vectorLayer.children = [...vectorLayer.children, layer];
this.updateLayer(vectorLayer);
}
示例5: groupOrUngroupSelectedLayers
/**
* Groups or ungroups the selected layers.
*/
groupOrUngroupSelectedLayers(shouldGroup: boolean) {
let selectedLayerIds = this.getSelectedLayerIds();
if (!selectedLayerIds.size) {
return;
}
let vl = this.getVectorLayer();
// Sort selected layers by order they appear in tree.
let tempSelLayers = Array.from(selectedLayerIds).map(id => vl.findLayerById(id));
const selLayerOrdersMap: Dictionary<number> = {};
let n = 0;
vl.walk(layer => {
if (_.find(tempSelLayers, l => l.id === layer.id)) {
selLayerOrdersMap[layer.id] = n;
n++;
}
});
tempSelLayers.sort((a, b) => selLayerOrdersMap[a.id] - selLayerOrdersMap[b.id]);
if (shouldGroup) {
// Remove any layers that are descendants of other selected layers,
// and remove the vectorLayer itself if selected.
tempSelLayers = tempSelLayers.filter(layer => {
if (layer instanceof VectorLayer) {
return false;
}
let p = LayerUtil.findParent(vl, layer.id);
while (p) {
if (_.find(tempSelLayers, l => l.id === p.id)) {
return false;
}
p = LayerUtil.findParent(vl, p.id);
}
return true;
});
if (!tempSelLayers.length) {
return;
}
// Find destination parent and insertion point.
const firstSelectedLayerParent = LayerUtil.findParent(vl, tempSelLayers[0].id).clone();
const firstSelectedLayerIndexInParent = _.findIndex(
firstSelectedLayerParent.children,
l => l.id === tempSelLayers[0].id,
);
// Remove all selected items from their parents and move them into a new parent.
const newGroup = new GroupLayer({
name: LayerUtil.getUniqueLayerName([vl], 'group'),
children: tempSelLayers,
});
const parentChildren = [...firstSelectedLayerParent.children];
parentChildren.splice(firstSelectedLayerIndexInParent, 0, newGroup);
_.remove(parentChildren, child =>
_.find(tempSelLayers, selectedLayer => selectedLayer.id === child.id),
);
firstSelectedLayerParent.children = parentChildren;
vl = LayerUtil.updateLayer(vl, firstSelectedLayerParent);
selectedLayerIds = new Set([newGroup.id]);
} else {
// Ungroup selected groups layers.
const newSelectedLayers: Layer[] = [];
tempSelLayers.filter(layer => layer instanceof GroupLayer).forEach(groupLayer => {
// Move children into parent.
const parent = LayerUtil.findParent(vl, groupLayer.id).clone();
const indexInParent = Math.max(
0,
_.findIndex(parent.children, l => l.id === groupLayer.id),
);
const newChildren = [...parent.children];
newChildren.splice(indexInParent, 0, ...groupLayer.children);
parent.children = newChildren;
vl = LayerUtil.updateLayer(vl, parent);
newSelectedLayers.splice(0, 0, ...groupLayer.children);
// Delete the parent.
vl = LayerUtil.removeLayers(vl, groupLayer.id);
});
selectedLayerIds = new Set(newSelectedLayers.map(l => l.id));
}
this.store.dispatch(
new BatchAction(new SetVectorLayer(vl), new SetSelectedLayers(selectedLayerIds)),
);
}
示例6: flattenGroupLayer
/**
* Merges the specified group layer into its children layers.
* TODO: make it possible to merge groups that contain animation blocks?
*/
flattenGroupLayer(layerId: string) {
const vl = this.getVectorLayer();
const layer = vl.findLayerById(layerId) as GroupLayer;
if (!layer.children.length) {
return;
}
const layerTransform = Matrix.flatten(LayerUtil.getCanvasTransformsForGroupLayer(layer));
const layerChildren = layer.children.map((l: GroupLayer | PathLayer | ClipPathLayer): Layer => {
if (l instanceof GroupLayer) {
const flattenedTransform = Matrix.flatten([
layerTransform,
...LayerUtil.getCanvasTransformsForGroupLayer(l),
]);
const { sx, sy } = flattenedTransform.getScaling();
const degrees = flattenedTransform.getRotation();
const { tx, ty } = flattenedTransform.getTranslation();
const newLayer = l.clone();
newLayer.pivotX = 0;
newLayer.pivotY = 0;
newLayer.translateX = tx;
newLayer.translateY = ty;
newLayer.rotation = degrees;
newLayer.scaleX = sx;
newLayer.scaleY = sy;
return newLayer;
}
const path = l.pathData;
if (!path || !l.pathData.getPathString()) {
return l;
}
const clonedLayer = l.clone();
clonedLayer.pathData = path
.mutate()
.transform(layerTransform)
.build();
return clonedLayer;
});
const layerChildrenIds = new Set(layerChildren.map(l => l.id));
const parent = LayerUtil.findParent(vl, layerId).clone();
const children = [...parent.children];
children.splice(_.findIndex(parent.children, l => l.id === layerId), 1, ...layerChildren);
parent.children = children;
const actions: Action[] = [
new SetVectorLayer(LayerUtil.updateLayer(vl, parent)),
...this.buildCleanupLayerIdActions(layerId),
];
const newAnimation = this.getAnimation().clone();
// TODO: show a dialog if the user is about to unknowingly delete any blocks?
newAnimation.blocks = newAnimation.blocks.filter(b => b.layerId !== layerId);
// TODO: also attempt to merge children group animation blocks?
newAnimation.blocks = newAnimation.blocks.map(b => {
if (!(b instanceof PathAnimationBlock) || !layerChildrenIds.has(b.layerId)) {
return b;
}
const block = b.clone();
block.fromValue = block.fromValue
.mutate()
.transform(layerTransform)
.build();
block.toValue = block.toValue
.mutate()
.transform(layerTransform)
.build();
return block;
});
actions.push(new SetAnimation(newAnimation));
this.store.dispatch(new BatchAction(...actions));
}