• 基于Skyline的TerraExplorer6.1.1如何通过二次开发实现矢量图层的空间查询和属性查询


    说明:先准备好一个FLY工程文件,其中要加载一个相对标准的SHP文件,自己参考其他部分实现绘制几何对象的方法;

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script type="text/javascript" language="javascript">
            
    //遍历整个图层 
            //zhaohe.2012.09.25.
            function GetFeatureAll() {
                
    var strResult = "<table>";
                
    var SGWorld = CreateSGObj();
                
    var ItemID = SGWorld.ProjectTree.FindItem("Fairfax_zones");
                
    var obj = SGWorld.ProjectTree.GetLayer(ItemID);
                
    // 遍历当前图层中已经在地图上加载的全部对象及其属性
                var pIFeatureGroup = obj.FeatureGroups(0);
                
    for (var i = 0; i < pIFeatureGroup.Count; i++) {
                    strResult 
    = strResult + "<tr>";
                    
    var pIFeature = pIFeatureGroup.Item(i);
                    
    for (var j = 0; j < pIFeature.FeatureAttributes.Count; j++) {
                        
    var pIFeatureAttribute = pIFeature.FeatureAttributes.Item(j);
                        strResult 
    = strResult + "<td>" + pIFeatureAttribute.Name + "*" + pIFeatureAttribute.Value + "</td>";
                    }
                    strResult 
    = strResult + "</tr>";
                }
                strResult 
    = strResult + "</table>";
                window.document.getElementById(
    "result").innerHTML = strResult;
            }

            
    //多边形查询
            //zhaohe.2012.09.25.
            function GetFeatureWithPoly() {
                
    var strResult = "<table>";
                
    var SGWorld = CreateSGObj();
                
    var ItemID = SGWorld.ProjectTree.FindItem("Fairfax_zones");
                
    var obj = SGWorld.ProjectTree.GetLayer(ItemID);
                
    // 遍历多边形内选中的对象及其属性
                var qItemID = SGWorld.ProjectTree.GetNextItem(010);
                
    var qobj = SGWorld.ProjectTree.GetObject(qItemID);
                
    var queryGeometry = qobj.Geometry;
                
    var resFeatures = obj.ExecuteSpatialQuery(queryGeometry, 1);
                
    for (var i = 0; i < resFeatures.Count; i++) {
                    strResult 
    = strResult + "<tr>";
                    
    var pIFeature = resFeatures.Item(i);
                    
    for (var j = 0; j < pIFeature.FeatureAttributes.Count; j++) {
                        
    var pIFeatureAttribute = pIFeature.FeatureAttributes.Item(j);
                        strResult 
    = strResult + "<td>" + pIFeatureAttribute.Name + "*" + pIFeatureAttribute.Value + "</td>";
                    }
                    strResult 
    = strResult + "</tr>";
                }
                strResult 
    = strResult + "</table>";
                window.document.getElementById(
    "result").innerHTML = strResult;
            }

            
    //属性查询
            //zhaohe.2012.09.25.
            function GetFeatureWithPro() {
                
    var SGWorld = CreateSGObj();
                
    var ItemID = SGWorld.ProjectTree.FindItem("Fairfax_zones");
                
    var obj = SGWorld.ProjectTree.GetLayer(ItemID);
                
    var clause = window.document.getElementById("Text1").value;
                
    if (clause == "") {
                    obj.Filter 
    = clause;
                    obj.Streaming 
    = 1;
                    obj.Refresh();
                }
                
    else {
                    obj.Filter 
    = clause;
                    obj.Streaming 
    = 0;
                    obj.Refresh();
                }
                GetFeatureAll();
            }

            
    /*  
            功能:   创建sgworld对象
            备注:   赵贺 2011.04.01.
            
    */
            
    function CreateSGObj() {
                
    var obj = $("sgworld");
                
    if (obj == null) {
                    obj 
    = document.createElement('object');
                    document.body.appendChild(obj);
                    obj.name 
    = "sgworld";
                    obj.id 
    = "sgworld";
                    obj.classid 
    = "CLSID:3a4f91b0-65a8-11d5-85c1-0001023952c1";
                }
                
    return obj;
            }
            
    function $(id) {
                
    return window.document.getElementById(id);
            }
        
    </script>
    </head>
    <body>
        <table>
            <tr>
                <td colspan="4">
                    <input id="Button1" type="button" value="全部Feature" onclick="GetFeatureAll()" />
                    <input id="Button2" type="button" value="空间查询" onclick="GetFeatureWithPoly()" />
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <input id="Text1" type="text" value="Class=3" />
                    <input id="Button6" type="button" value="属性查询" onclick="GetFeatureWithPro()" />
                </td>
            </tr>
            <tr>
                <td>
                    <div id="result">
                    </div>
                </td>
            </tr>
        </table>
    </body>
    </html>
  • 相关阅读:
    java学习 hashmap(2)
    HITcsapp大作业 程序人生
    java学习之hashmap
    java学习笔记之高精度
    java 数论之FFT/NTT及多项式运算模板
    如何下载微信公众号的视频到本地
    win10家庭版通过gpedit.msc找不到组策略的解决方案
    uni-app
    elementui el-date-picker 选择一个月范围
    CommonJS规范的require与es6规范的import的区别
  • 原文地址:https://www.cnblogs.com/yitianhe/p/2701743.html
Copyright © 2020-2023  润新知