本文整理汇总了TypeScript中app/model/layers.LayerUtil.getUniqueLayerName方法的典型用法代码示例。如果您正苦于以下问题:TypeScript LayerUtil.getUniqueLayerName方法的具体用法?TypeScript LayerUtil.getUniqueLayerName怎么用?TypeScript LayerUtil.getUniqueLayerName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app/model/layers.LayerUtil
的用法示例。
在下文中一共展示了LayerUtil.getUniqueLayerName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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)),
);
}