SQL查询之后怎么获取位置信息

0 投票
function onQueryComplete(queryEventArgs) {

    var i, result = queryEventArgs.result;
    if (result && result.features) {
        features = result.features;
        for (i = 0; i < features.length; i++) {
            feature = features[i];
        }
    }

如何获取feature的位置信息?

}
4月 15, 2017 分类:  625次浏览 | 用户: 罗思 (1 分)

1个回答

0 投票

您好,一般思路是通过查询返回的几何对象的boundingBox来定位。代码片段 您参考一下:

/* ---------------------------------------- */
/* SQL查询完成回调函数.                   	*/
/* ---------------------------------------- */
function onQueryComplete(queryEventArgs){

    /* ---------------------------------------- */
    /* 清除选择集.                              	*/
    /* ---------------------------------------- */
    for (var i = 0; i < sceneControl.get_scene().get_layer3Ds().get_count(); i++)    {
        sceneControl.get_scene().get_layer3Ds().get_item(i).get_selection3D().removeAll();
    }

    sceneControl.get_bubbles().removeAll();

    /* ---------------------------------------- */
    /* 添加查询结果为新的选择集.                  	*/
    /* ---------------------------------------- */
    var queryDatasetName = $("#controlPanelFrame").contents().find("#selectLayerList option:selected").text();
    var dataSource = $("#controlPanelFrame").contents().find("#selectLayerList option:selected").val();
    var layer3D = sceneControl.get_scene().get_layer3Ds().get_item(queryDatasetName + "@" + dataSource);
    viewBounds = new SuperMap.Bounds();

    resultFeatures = queryEventArgs.originResult.features;
    for (var m = 0; m < resultFeatures.length; m++) {
        var feature2D = resultFeatures[m];
        var id=feature2D.ID;
        layer3D.get_selection3D().add(id);
        var geoVector = feature2D.geometry;
        var geoType = geoVector.type;
        var dz = 0;

        switch (geoType)
        {
            case "POINT3D":
                break;
            case "LINE3D":
                break;

            case "REGION":
                var geoRegion3D = new SuperMap.Web.Core.GeoRegion3D();
                var pt3Ds = new SuperMap.Web.Core.Point3Ds();
                var pt3D = new SuperMap.Web.Core.Point3D(0,0,0);
                for (var j = 0; j < geoVector.points.length; j++)
                {
                    pt3D.x = geoVector.points[j].x;
                    pt3D.y = geoVector.points[j].y;
                    pt3D.z = 0;
                    pt3Ds.add(pt3D);
                }
                geoRegion3D.addPart(pt3Ds);
                left = geoRegion3D.get_boundingBox().get_lower().get_x();
                bottom = geoRegion3D.get_boundingBox().get_lower().get_y();
                right = geoRegion3D.get_boundingBox().get_upper().get_x();
                top = geoRegion3D.get_boundingBox().get_upper().get_y();
                viewBounds.extend(new SuperMap.Bounds(left, bottom, right, top));
                upper = geoRegion3D.get_boundingBox().get_upper().get_z();
                dz = dz > upper ? dz : upper;
                break;

            case "GEOMODEL":
                var left = geoVector.boundingBox.lower.x;
                var bottom = geoVector.boundingBox.lower.y;
                var right = geoVector.boundingBox.upper.x;
                var top = geoVector.boundingBox.upper.y;
                viewBounds.extend(new SuperMap.Bounds(left, bottom, right, top));
                upper = geoVector.boundingBox.upper.z;
                dz = dz > upper ? dz : upper;
                break;
        }
        /*var feature3d = new SuperMap.Web.Core.Feature3D();
         feature3d.set_geometry(feature2D.geometry);
         var featureBounds = feature3d.get_bounds();*/
    }

    /* ---------------------------------------- */
    /* 调整相机到合适位置.                     	*/
    /* ---------------------------------------- */
    var altitude = calculateAltitudeFromBounds(viewBounds) + dz;
    var camera = sceneControl.get_scene().get_camera();
    var centerLonLat = viewBounds.getCenterLonLat();
    var lookAt =new SuperMap.Web.Realspace.LookAt(centerLonLat.lon, centerLonLat.lat, altitude);
    lookAt.set_tilt(camera.get_tilt());
    lookAt.set_heading(camera.get_heading());
    sceneControl.get_scene().get_flyingOperator().flyToLookAt(lookAt, 2000);

    /* ---------------------------------------- */
    /* 刷新图层.                              	*/
    /* ---------------------------------------- */
    for (var mm = 0; mm < sceneControl.get_scene().get_layer3Ds().get_count(); mm++)
    {
        sceneControl.get_scene().get_layer3Ds().get_item(mm).updateData();
    }
}



function calculateAltitudeFromBounds(bounds){
    var _PI = 3.1415926;
    var _earthRadius = 6378137;
    var altitude = _earthRadius;
    var boundsWidth = bounds.right - bounds.left;
    if (boundsWidth >= 120) {
        altitude = _earthRadius * boundsWidth / 60 - _earthRadius;
    }
    else if (boundsWidth != 0) {
        var angle1 = (boundsWidth / 360) * _PI;
        var height = Math.sin(angle1) * _earthRadius;
        var a = height / Math.tan(angle1);
        var b = height / Math.tan(_PI / 6);
        altitude = a + b - _earthRadius;
    }
    return altitude;
}


4月 16, 2017 用户: 邹涛 名扬四海 (3,389 分)
多谢多谢!
...