skyline 6.6.1 javascript实现遍历树,然后获取图层树中的属性数据

这几天开始研究skyline第一实例就是,单机按钮然后,显示某个图层的数据,虽然实现了功能,但是对这种显示方式,不是很认可的,希望skyline可以改进,下面说一下实例 1.首先用TerraExplorer Pro工具,创建一个fly项目,然后添加一个shp图层,图层命名为“cun”,这里默认测试我没有创建分组,直接图层在根目录下

2.这一步是最关键的一步,就是右键图层属性,设置message属性,设置可以显示字段属性信息,这里如果不设置,显示,javascript是查询不到数据的,这里也是很别扭的地方,一上午没明白,问了群里一位朋友的提示,才了解里。先前如果这里不设置javascript查询的数据是0 3.发布fly文件 4.客户端代码如下,一个html文件 <html>

<head>

    <title>HTML Example</title>

    <script type=”text/javascript”>

        function Init() {//初始化加载地图

            try {

                var flyPath =  “d://new2.fly”;

                // attach callback to the load finished event

                var divobj = window.document.getElementById(“res”);

                SGWorld66.AttachEvent(“OnLoadFinished”, OnProjectLoadFinished);

                SGWorld66.Project.Open(flyPath);

            }

            catch (e) {

                alert(“Error: ” + e.description);

            }         }

        function  GetFeatureAll()  {

                        var  strResult  =  “<table>”;

                        var SGWorld = SGWorld66;

                        var ItemID = SGWorld.ProjectTree.FindItem(“shijie”);

                        if (SGWorld.ProjectTree.IsLayer(ItemID))  // Layer

                        {                          //   var ItemID = SGWorld.ProjectTree.FindItem(“shijie”);

                            //  var obj = SGWorld.ProjectTree.GetLayer(ItemID);

                            // 遍历当前图层中已经在地图上加载的全部对象及其属性

                            //  var pIFeatureGroup = obj.FeatureGroups.Item(0);

                            var layer = SGWorld.ProjectTree.GetLayer(ItemID);

                            layer.Filter = ” 1=1″;

                            var featureGroups = layer.FeatureGroups;

                            for (var i = 0; i < featureGroups.Count; i++) // Traverse all sub-layers

                            {

                                var featureGroup = featureGroups.Item(i);

                                //  var altitudeType = AltitudeMethodToAltitudeType(featureGroup.GetProperty(“Altitude Method”));

                                var features = featureGroup.Features;

                                for (var j = 0; j < features.Count; j++) {

                                      var f1 = features.Item(j);

                                      // var pIFeatureAttribute = f1.FeatureAttributes.GetFeatureAttribute(“RNAME”);

                                      for (var n = 0; n < f1.FeatureAttributes.Count; n++)

                                      {

                                          var pIFeatureAttribute = f1.FeatureAttributes.Item(n);

                                          strResult  =  strResult  +  “<td>”  +  pIFeatureAttribute.Name  +  “*”  +  pIFeatureAttribute.Value  +  “</td>”;

                                      }                                 }

                            }

                        } else {

                        }

                      

                        strResult  =  strResult  +  “</table>”;

                        window.document.getElementById(“result”).innerHTML  =  strResult;

                }

        function OnProjectLoadFinished() {

            alert(“Received project loaded event. Click OK to fly to Washington DC.”);

            var Washington = SGWorld66.Creator.CreatePosition(-77.036667, 38.895111, 1500);

            SGWorld66.Navigate.FlyTo(Washington);

        }

    </script>

</head>

<body onload=”Init()”>

    <input id=”Button1″ type=”button” value=”开始” onclick=”GetFeatureAll()” />

    <div id=”result”></div>

    <object id=”TEInformationWindow” classid=”CLSID:3a4f9193-65a8-11d5-85c1-0001023952c1″ width=”300″ height=”521″></object>

    <object id=”TE” classid=”clsid:3a4f9192-65a8-11d5-85c1-0001023952c1″ style=”width: 600px;height: 600px”></object>

    <object id=”SGWorld66″ classid=”CLSID:3a4f9199-65a8-11d5-85c1-0001023952c1″ style=”visibility: hidden;height: 0″></object>

</body>

</html> 5.这个地方也比较关键,就是在查询之前,必须,在运行界面上点击一个数据,显示数据,才可以查询出数据,这里也是很别扭的,如果不点击地图查看一条数据,依然查不到数据

    原文作者:数据结构之图
    原文地址: https://blog.csdn.net/huyanliang/article/details/73281291
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞