67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import { TreeApi } from '@/api/tree'
|
|
import { useTreeNode } from '../views/components/tree/hooks/treeNode'
|
|
import { initMapData } from './initMapData'
|
|
|
|
export const addMapSource = async ({ type, id, sourceName = '未命名对象', opt = {} }, cd: any = null) => {
|
|
const { cusAddNodes } = useTreeNode()
|
|
if (!id) {
|
|
id = new YJ.Tools().randomString()
|
|
}
|
|
//判断是否已有元素
|
|
if (window.earth.entityMap.get(id)) {
|
|
window.earth.entityMap.get(id).remove()
|
|
}
|
|
setTimeout(async () => {
|
|
let options: any = await initMapData(type, opt, cd)
|
|
let selectedNodes = window.treeObj.getSelectedNodes()
|
|
let node = selectedNodes && selectedNodes[selectedNodes.length - 1]
|
|
function getParentId(nd: any) {
|
|
if (nd.sourceType === 'directory') {
|
|
return nd.id
|
|
} else {
|
|
let parentNode = window.treeObj.getNodeByParam("id", nd.parentId, null);
|
|
if (parentNode) {
|
|
return getParentId(parentNode)
|
|
}
|
|
else {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
let parentId
|
|
if (node) {
|
|
parentId = getParentId(node)
|
|
}
|
|
delete options.host
|
|
if (options.attribute && options.attribute.rtmp) {
|
|
delete options.attribute.rtmp
|
|
}
|
|
switch (type) {
|
|
case 'rendezvous':
|
|
case 'attackArrow':
|
|
case 'pincerArrow':
|
|
delete options.label.ground
|
|
delete options.label.position
|
|
break;
|
|
case 'path':
|
|
delete options.label.text
|
|
break;
|
|
}
|
|
console.log('options', options)
|
|
let params: any = {
|
|
id: id,
|
|
sourceName: sourceName,
|
|
sourceType: type,
|
|
// isShow: 1,
|
|
parentId: parentId,
|
|
// "treeIndex": 0,
|
|
params: options
|
|
}
|
|
TreeApi.addOtherSource(params)
|
|
params.params = JSON.stringify(params.params)
|
|
params.isShow = true
|
|
|
|
cusAddNodes(window.treeObj, params.parentId, [params])
|
|
}, 10);
|
|
}
|