首页 / 浏览问题 / WebGIS / 问题详情
SuperMap iClient3D进行单体化
7EXP 2024年04月28日
我修改了咱们的示例代码,现在会显示模型,但是没有单体化效果,有大神可以帮我看看吗?

<script>

    function onload(Cesium) {

        var viewer = new Cesium.Viewer('cesiumContainer');

        var scene = viewer.scene;

        scene.lightSource.ambientLightColor = new Cesium.Color(0.65, 0.65, 0.65, 1);

        var camera = scene.camera;

        var dataServiceUrl = 'http://localhost:8090/iserver/services/data-ChaXun/rest/data/featureResults.rjson?returnContent=true'; // 数据服务URL

        var dataSourceName = '查询'; // 数据源名称

        var dataSetName = '兴趣点'; // 数据集名称

        // 加载倾斜摄影图层

        var promise = scene.addS3MTilesLayerByScp('http://localhost:8090/iserver/services/3D-ChaXun/rest/realspace/datas/Combine/config', {

            name: 'Combine'

        });

        promise.then(function (obliqueLayers) {

            camera.setView({ // 先定位,开始渲染定位区域的倾斜

                destination: new Cesium.Cartesian3.fromDegrees(105.05322545224173,35.692735895610219, 1950.0),

                orientation: {

                    heading: 4.39611370540786,

                    pitch: -0.43458664812464143,

                    roll: 2.0174972803488345e-11

                }

            });

            var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);

            handler.setInputAction(function (e) {

                // 首先移除之前添加标识实体

                viewer.entities.removeById('identify-area');

                // 获取点击位置笛卡尔坐标

                var position = scene.pickPosition(e.position);

                // 从笛卡尔坐标获取经纬度

                var cartographic = Cesium.Cartographic.fromCartesian(position);

                var longitude = Cesium.Math.toDegrees(cartographic.longitude);

                var latitude = Cesium.Math.toDegrees(cartographic.latitude);

                var queryPoint = { // 查询点对象

                    x: longitude,

                    y: latitude

                };

                queryByPoint(queryPoint);

            }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

            // 去除加载动画

            $('#toolbar').show();

            $('#loadingbar').remove();

        });

        // 通过点击查询用于表示单体化的面要素,添加到场景中高亮显示。

        function queryByPoint(queryPoint) {

            var queryObj = {

                "getFeatureMode": "SPATIAL",

                "spatialQueryMode": "INTERSECT",

                "datasetNames":[dataSourceName + ":" + dataSetName],

                "geometry": {

                    id: 0,

                    style:null,

                    parts: [1],

                    points: [queryPoint],

                    type: "POINT"

                }

            };

            queryObjJSON = JSON.stringify(queryObj); // 转化为JSON字符串作为查询参数

            $.ajax({

                type: "post",

                url: dataServiceUrl,

                data: queryObjJSON,

                success: function (result) {

                    var resultObj = JSON.parse(result);

                    if (resultObj.featureCount > 0) {

                        addClapFeature(resultObj.features[0]);

                    }

                },

                error: function (msg) {

                    console.log(msg);

                }

            })

        }

        // 将数据服务查询到的要素添加到场景中高亮显示,表示选中效果。

        function addClapFeature(feature) {

            var lonLatArr = getLonLatArray(feature.geometry.points);

            viewer.entities.add({

                id: 'identify-area',

                name: '单体化标识面',

                polygon: {

                    hierarchy: Cesium.Cartesian3.fromDegreesArray(lonLatArr),

                    material: new Cesium.Color(1.0, 0.0, 0.0, 0.7),

                    classificationType: Cesium.ClassificationType.S3M_TILE // 贴在S3M模型表面

                },

                });

        }

        // 得到[经度,纬度,经度,纬度...]形式的数组,用于构造面。

        function getLonLatArray(points) {

            var point3D = [];

            points.forEach(function (point) {

                point3D.push(point.x);

                point3D.push(point.y);

            });

            return point3D;

        }

 

    }

    if (typeof Cesium !== 'undefined') {

        window.startupCalled = true;

        onload(Cesium);

    }

</script>
问题关闭原因: 已经解决了
...