search.js 2.24 KB



/**
 * 获取传入的对象的自身的属性值
 * @param {*} teobj 选中的要素对象
 */
function getObjectAttributes(teobj) {
    var msgObj = {};
    if (teobj.ObjectType === 33) //OT_FEATURE = 33
    {
        for (var j = 0; j < teobj.FeatureAttributes.Count; j++) {
            var pIFeatureAttribute = teobj.FeatureAttributes.Item(j);
            msgObj[pIFeatureAttribute.Name] = pIFeatureAttribute.Value;
        }
        return msgObj;
    } else {
        msgObj.error = true;
    }

}

var layersList = [];
//遍历工程树,将所有的MeshLayer和FeatureLayer存入layerList
function ScanTree() {
    try {
        layersList = [];
        var sgworld = new CreateSGObj();
        // root is the first visible item in tree.
        //获取根节点ID
        var root = sgworld.ProjectTree.GetNextItem("", 18 /* ItemCode.ROOT*/);
        //如果获取的根节点和隐藏组的节点相同,那么获取下一个对象
        if (sgworld.ProjectTree.GetItemName(root) == sgworld.ProjectTree.HiddenGroupName)
            root = sgworld.ProjectTree.GetNextItem(root, 13 /* ItemCode.NEXT*/);
        BuildTreeRecursive(root);//根据根节点来遍历目录树
    }
    catch (ex) {
        alert("Unexpected error: " + ex.description);
    }
}
function BuildTreeRecursive(current) {
    var sgworld = new CreateSGObj();
    //如果提供的节点ID存在
    while (current) {
        // 获取节点名称
        var currentName = sgworld.ProjectTree.GetItemName(current);
        // 如果当前节点是一个组, 获取该节点的第一个子节点;
        if (sgworld.ProjectTree.IsGroup(current)) {
            //child 是第一个子节点
            var child = sgworld.ProjectTree.GetNextItem(current, 11 /* ItemCode.CHILD */);
            BuildTreeRecursive(child);//进行递归
        }
        //如果类型是IFeatureLayer或者IMeshLayer,将ID存入到layersList中
        if (sgworld.ProjectTree.GetObject(current).ObjectType == 36 || sgworld.ProjectTree.GetObject(current).ObjectType == 38) {
            layersList.push({ id: current, name: currentName });
        }

        // 获取当前节点的下一个兄弟节点
        current = sgworld.ProjectTree.GetNextItem(current, 13 /* ItemCode.NEXT*/);

    }
    //return result;

}