How to traverse the information tree in the secondary development of TE
This article mainly shows you "how to traverse the information tree in the secondary development of TE". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to traverse the information tree in the secondary development of TE".
The information tree control of TE contains the location, presentation, layer and other individual elements of the fly project. In the information tree, it is arranged according to the tree structure. If you want to get all the objects in the tree or find an object in the tree in development, you need to use the development interface to traverse the information tree. In the program, the recursive algorithm is necessary to traverse the tree structure. In the information tree traversal of TE, you need to use the development interface to traverse the tree. This is also needed.
Here is a brief description of how to traverse the information tree in development, based on a js code:
/ / first, specify the root node of the traversal, which can be the root node of the entire project or in the information tree
/ / id of a folder. Callback function can be used in js to perform some external operations.
Function searchGeometries2 (parentNode, callbackFunc) {
/ / EnableRedraw is to control whether refresh is implemented when the content in the information tree changes.
SGWorld.ProjectTree.EnableRedraw (0)
SearchGeometriesLeaf2 (parentNode, callbackFunc)
SGWorld.ProjectTree.EnableRedraw (1)
}
Function searchGeometriesLeaf2 (parentNode, callbackFunc) {
/ / this example is to search for a layer and determine the content of the layer.
If (SGWorld.ProjectTree.IsLayer (parentNode)) / / Layer
{
/ / about feature operations in layers
Var layer = SGWorld.ProjectTree.GetLayer (parentNode)
Var featureGroups = layer.FeatureGroups
For (var I = 0; I < featureGroups.Count; iTunes +) / / Traverse all sub-layers
{
Var featureGroup = featureGroups.Item (I)
Var altitudeType = AltitudeMethodToAltitudeType (featureGroup.GetProperty ("AltitudeMethod"))
Var features = featureGroup.Features
For (var j = 0; j < features.Count; jacks +) {
Var ret
If (featureGroup.GeometryType! = 0)
Ret = callbackFunc (features.Item (j). Geometry, featureGroup.GeometryType, altitudeType)
Else {
If (features.Item (j). Geometry.GeometryType = = 0) / / Point
{
Var position = SGWorld.Creator.CreatePosition (features.Item (j). Geometry.X, features.Item (j). Geometry.Y, features.Item (j) .Geometry.Z)
Ret = callbackFunc (position, featureGroup.GeometryType, altitudeType)
}
}
If (! ret)
Return
}
}
}
Else {
/ / get the node of the next information tree according to the parameters. For later parameters, please see the api document.
Var node = SGWorld.ProjectTree.GetNextItem (parentNode, 11)
While (node! = "") {
/ / determine whether it is a folder or not, and the loop will continue in the folder.
If (SGWorld.ProjectTree.IsGroup (node) | | SGWorld.ProjectTree.IsLayer (node))
/ / Recursive call to continue searching
SearchGeometriesLeaf2 (node, callbackFunc)
Else {
/ / how to handle a single object
Var Object = SGWorld.Creator.GetObject (node)
If (Object! = null) {
Var altitudeType = Object.Position.AltitudeType
Var ret
If (Object.ObjectType = = 1 | | Object.ObjectType = = 2)
Ret = callbackFunc (Object.Geometry, Object.ObjectType, altitudeType, Object.Position)
Else
Ret = callbackFunc (Object.Position, Object.ObjectType, altitudeType, Object.Position)
If (! ret)
Return
}
}
/ / get the node of the next information tree according to the parameters. For later parameters, please see the api document.
Node = SGWorld.ProjectTree.GetNextItem (node, 13)
}
}
}
These are all the contents of the article "how to traverse the information tree in the secondary development of TE". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!