在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>
时间: 2024-10-12 05:19:03