1. 程式人生 > >SkylineGlobe 7.0版本 矢量數據查詢示例代碼

SkylineGlobe 7.0版本 矢量數據查詢示例代碼

pan win count lte result dtd end form lsi

在Pro7.0.0和7.0.1環境下測試可用。

<!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">
        //
執行ExecuteQuery方法 //zhaohe.2017.09.18. function GetFeatureAll() { try { var strResult = "<table>"; var sg = CSGWorld(); //var sg = TerraExplorer3DWindowEx.CreateInstance("TerraExplorerX.SGWorld70"); var
ItemID = sg.ProjectTree.FindItem("_縣級城市名稱.398244"); var obj = sg.ProjectTree.GetLayer(ItemID); //查詢條件 var attributeFilter = window.document.getElementById("Text1").value; //最大查詢數 var numOfFeatures = -1;
//查詢起始feature的id var fromDataSourFeaId = ""; var geometry = sg.Creator.GeometryCreator.CreatePolygonGeometry(null); var pIFeatureGroup = obj.ExecuteQuery(attributeFilter, numOfFeatures, fromDataSourFeaId, geometry); // 遍歷當前圖層中符合查詢條件的全部對象及其屬性 alert(pIFeatureGroup.Count); for (var i = 0; i < pIFeatureGroup.Count; i++) { var pIFeature11 = pIFeatureGroup.Item(i); sg.Navigate.FlyTo(pIFeature11.ID, 0); //alert(pIFeature11.Geometry.Wks.ExportToWKT()); //alert(pIFeature11.Geometry.X); } 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 style=‘cursor:pointer;‘><a id="+pIFeature.ID+" onclick= \"JJJ\(this.id)\">" + pIFeatureAttribute.Name + "*" + pIFeatureAttribute.Value + "</a></td>"; } strResult = strResult + "</tr>"; } strResult = strResult + "</table>"; window.document.getElementById("result").innerHTML = strResult; } catch (e) { alert(e); } } //GetCurrentFeatures 獲取當前已經加載的Feature對象 //zhaohe.2017.09.18. function GetCurrentFeatures() { var strResult = "<table>"; var sg = CSGWorld(); var ItemID = sg.ProjectTree.FindItem("_縣級城市名稱.398244"); var obj = sg.ProjectTree.GetLayer(ItemID); // 遍歷當前圖層中已經在地圖上加載的全部對象及其屬性 var pIFeatureGroup = obj.FeatureGroups(0).GetCurrentFeatures(); alert(pIFeatureGroup.Count); for (var i = 0; i < pIFeatureGroup.Count; i++) { strResult = strResult + "<tr>"; var pIFeature = pIFeatureGroup.Item(i); //sg.Navigate.FlyTo(pIFeature.ID, 0); //break; 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.2015.06.23. function GetFeatureWithPoly() { var strResult = "<table>"; var SGWorld = CSGWorld(); var ItemID = SGWorld.ProjectTree.FindItem("_縣級城市名稱.398244"); var obj = SGWorld.ProjectTree.GetLayer(ItemID); // 遍歷多邊形內選中的對象及其屬性 var qItemID = SGWorld.ProjectTree.GetNextItem("", 10); // 在地圖上創建一個Polygon,並選中這個對象 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.2015.06.23. function GetFeatureWithPro() { var SGWorld = CSGWorld(); var ItemID = SGWorld.ProjectTree.FindItem("_縣級城市名稱.398244"); 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(); } function JJJ(id) { var SGWorld = CSGWorld(); SGWorld.Navigate.FlyTo(id, 0); } // SGWorld70 function CSGWorld() { try { var obj = document.getElementById("SGWorld"); if (obj == null) { obj = document.createElement(object); obj.setAttribute("name", "SGWorld"); obj.setAttribute("id", "SGWorld"); obj.style.height = "1px"; obj.style.width = "1px"; obj.setAttribute("classid", "CLSID:3A4F919A-65A8-11D5-85C1-0001023952C1"); document.body.appendChild(obj); } return obj; } catch (e) { alert(e); } } </script> </head> <body> <table> <tr> <td colspan="4" > <input id="Button1" type="button" value="全部Feature" onclick="GetFeatureAll()" /> <input id="Button3" type="button" value="當前地圖上已經加載的對象" onclick="GetCurrentFeatures()" /> <input id="Button2" type="button" value="空間查詢" onclick="GetFeatureWithPoly()" /> </td> </tr> <tr> <td colspan="4"> <input id="Text1" type="text" value="OBJECTID < 12" /> <input id="Button6" type="button" value="屬性查詢" onclick="GetFeatureWithPro()" /> </td> </tr> <tr> <td> <div id="result"> </div> </td> </tr> </table> <!--<object id="TerraExplorer3DWindowEx" classid="CLSID:3a4f9196-65a8-11d5-85c1-0001023952c1" style="width: 80%; height: 560px;"></object>--> <object id="TerraExplorer3DWindow" classid="CLSID:3a4f9192-65a8-11d5-85c1-0001023952c1" style="width:500px;height:400px;"></object> <object id="TerraExplorerInformationWindow" classid="CLSID:3a4f9193-65a8-11d5-85c1-0001023952c1" style="width:300px;height:400px;"></object> </body> </html>

SkylineGlobe 7.0版本 矢量數據查詢示例代碼