运行范例

描述

示范如何使用 SQL 查询服务进行三维数据集查询。

代码 (文件格式为 UTF-8)



    <!DOCTYPE>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="x-ua-compatible" content="IE=8">
        <title>查询服务</title>
        <script type="text/javascript" src="SuperMap.Include.js"></script>
        <script type="text/javascript">
            /**************************** 全局变量定义 start ****************************/
            var scene;
            var sceneControl;
            var layersListControl;
            var fieldsListControl;
            var queryServiceUrl = "http://localhost:8090/iserver/services/data-3D/rest/data";
            var queryDatasetName; //要查询的数据集名称
            var georegion=null;//二维geometry
            /**************************** 全局变量定义 end ****************************/

            /**************************** 加载场景 start ****************************/

            function OnLoad() {
                sceneControl = new SuperMap.Web.UI.Controls.SceneControl($get("sceneControlDiv"), initCallback, failedCallback);
            }

            function initCallback() {
                scene = sceneControl.get_scene();
                var testUrl = "http://localhost:8090/iserver/services/3D-sample/rest/realspace";
                scene.open(testUrl, "scene_query3D");
            }

            function failedCallback() {
                alert("Realspace initialized failed!");
            }
            /**************************** 加载场景 end ****************************/

            function processFailed(e) {
                alert(e.error.errorMsg);
            }

            function onQueryComplete(queryEventArgs) {
                var resultFeatures = queryEventArgs.originResult.features;

                for (var m = 0; m < resultFeatures.length; m++) {
                    var feature2D = resultFeatures[m];

                    var geoVector = feature2D.geometry;
                    var geoType = geoVector.type;
                    var id=feature2D.ID;
                    switch (geoType){
                        case "POINT3D":
                            var geoPt = new SuperMap.Web.Core.GeoPoint3D();
                            geoPt.set_x( geoVector.points[0].x);
                            geoPt.set_y( geoVector.points[0].y)
                            geoPt.set_z( geoVector.points[0].z);
                            var feature3d = new SuperMap.Web.Core.Feature3D();
                            feature3d.set_geometry(geoPt);
                            break;
                        case "LINE3D":
                            var geoLine3d = new SuperMap.Web.Core.GeoLine3D();
                            var pt3ds = new SuperMap.Web.Core.Point3Ds();
                            var pt3d = new SuperMap.Web.Core.Point3D(0,0,0);
                            for(var i=0;i <geoVector.points.length;i++){
                                pt3d.x = geoVector.points[i].x;
                                pt3d.y = geoVector.points[i].y;
                                pt3d.z = geoVector.points[i].z;
                                pt3ds.add(pt3d);
                            }
                            geoLine3d.addPart(pt3ds);
                            var feature3d = new SuperMap.Web.Core.Feature3D();
                            feature3d.set_geometry(geoLine3d);
                            break;}
                    var feature3D=feature3d;
                    var layer3d = scene.get_layer3Ds().get_item(document.getElementById("layerList").selectedIndex);
                    var feature3DInLayer = layer3d.findFeature3DByID(id);
                    var extendHeight = feature3DInLayer.get_style3D().get_extendHeight()
                    var altitudeMode = feature3DInLayer.get_style3D().get_altitudeMode();
                    var resulstStyle3D = new SuperMap.Web.Core.Style3D();
                    resulstStyle3D.set_extendHeight(extendHeight);
                    resulstStyle3D.set_altitudeMode(altitudeMode);
                    resulstStyle3D.set_lineColor(new SuperMap.Web.Core.Color(0, 0, 255, 255))
                    resulstStyle3D.set_fillForeColor(new SuperMap.Web.Core.Color(255, 255, 255, 255))
                    resulstStyle3D.set_markerColor(new SuperMap.Web.Core.Color(255, 0, 0, 255));
                    resulstStyle3D.set_lineWidth(5);
                    resulstStyle3D.set_markerSize(10);
                    feature3D.set_style3D(resulstStyle3D);
                    scene.get_trackingLayer3D().add(feature3D, "feature3D");

                }


                sceneControl.set_sceneAction(new SuperMap.Web.UI.Action3Ds.Pan(sceneControl));
            }
            /**************************** 查询完成时的回调函数 end ****************************/

            /**************************** 执行 SQL 查询 start ****************************/
            function DoSqlQuery() {
                scene.get_trackingLayer3D().removeAll();

                queryDatasetName = document.getElementById("layerList").options[document.getElementById("layerList").selectedIndex].text;
                var attributeFilter = document.getElementById("filterParameterString").value;


                var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;

                getFeatureParam = new SuperMap.REST.FilterParameter({
                    name: queryDatasetName + "@3DDataset",
                    attributeFilter: attributeFilter
                });
                getFeatureBySQLParams = new SuperMap.REST.GetFeaturesBySQLParameters({
                    queryParameter: getFeatureParam,
                    toIndex:-1,
                    datasetNames: ["3DDataset:" + queryDatasetName]
                });
                getFeatureBySQLService = new SuperMap.REST.GetFeaturesBySQLService(queryServiceUrl, {
                    eventListeners: {"processCompleted": onQueryComplete, "processFailed": processFailed}});

                getFeatureBySQLService.processAsync(getFeatureBySQLParams);

            }
            /**************************** 执行 SQL 查询 end ****************************/


            function ClearResult() {
                scene.get_trackingLayer3D().removeAll();
            }
        </script>
    </head>
    <body onload="OnLoad();" style="font-size: 14px">
    <table width="100%">
        <tr>
            <td>
                <label>
                    查询的数据集名称:
                </label>
                <select id="layerList">
                    <option>PipeLine3D</option>
                    <option>PipePoint3D</option>
                </select>
                <label>
                    设置查询过滤条件(例如,SMID>15):
                </label>
                <input id="filterParameterString" type="text"/>
                <input id="btnSqlQuery" type="button" value="SQL 查询" onclick="DoSqlQuery();"/>
                <label id="lbSqlString">
                </label>

                <input id="btnClearResult" type="button" value="清除查询结果" onclick="ClearResult();"/>
            </td>
        </tr>
    </table>
    <div id="sceneControlDiv" style="position: absolute;bottom: 5px;top: 40px;left: 5px;right: 5px;">
    </div>
    </body>
    </html>