首页 / 浏览问题 / 三维GIS / 问题详情
webgl加载自带的CBD三维服务时报错
3EXP 2018年02月28日

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>三维场景</title>
    <link rel="stylesheet" href="https://www.supermapol.com/earth/Build/Cesium/Widgets/widgets.css">
    <script type="text/javascript" src="http://cdn.bootcss.com/require.js/2.3.3/require.min.js" data-main="./entry.js"></script>
    <style>
        html,
        body,
        #cesiumContainer {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
    </style>
</head>

<body>
    <div id="cesiumContainer"></div>
    <script>

        var host = "http://localhost:8090"

        function onload(Cesium) {
            var partOfUrl = '/iserver/services/3D-CBD/rest/realspace' // returnStr();
            var viewer = new Cesium.Viewer('cesiumContainer');
            var scene = viewer.scene;
            var widget = viewer.cesiumWidget;
            
            try {
                //添加S3M图层服务
                var promise = scene.open(host + partOfUrl);
                //***为场景名称
                //定位到场景
                Cesium.loadJson(host + partOfUrl + '/scenes.json').then(function (scenes) {
                    var sname = scenes[0].name;
                    Cesium.loadJson(host + partOfUrl + '/scenes/' + sname + '.json').then(function (jsonData) {
                        var cameraPosition = jsonData.camera;
                        var tilt = Cesium.Math.toRadians(cameraPosition.tilt - 90);
                        Cesium.when(promise, function (layer) {
                            //设置相机位置、视角,便于观察场景
                            scene.camera.setView({
                                destination: new Cesium.Cartesian3.fromDegrees(cameraPosition.longitude, cameraPosition.latitude, cameraPosition.altitude),
                                orientation: {
                                    heading: cameraPosition.heading,
                                    pitch: tilt,
                                    roll: 0
                                }
                            });
                            if (!scene.pickPositionSupported) {
                                alert('不支持深度纹理,无法拾取位置!');
                            }
                        }, function (e) {
                            if (widget._showRenderLoopErrors) {
                                var title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?';
                                widget.showErrorPanel(title, undefined, e);
                            }
                        });
                    });
                });

                // scene.camera.prototype.viewBoundingSphere;

            }
            catch (e) {
                if (widget._showRenderLoopErrors) {
                    var title = '渲染时发生错误,已停止渲染。';
                    widget.showErrorPanel(title, undefined, e);
                }
            }

        }
        function returnStr() {
            var url = document.location.toString();
            var startIndex = url.indexOf("/iserver");
            var endIndex = url.indexOf("/scenes");
            return url.substring(startIndex, endIndex);
        }

    </script>
</body>

</html>
require.config({
    paths: {
        'Cesium': 'https://www.supermapol.com/earth/Build/Cesium/Cesium',
        'Zlib': 'https://www.supermapol.com/earth/Build/Cesium/Workers/zlib.min'
    },
    shim: {
        Cesium: {
            exports: 'Cesium'
        },
        Zlib: {
            exports: 'Zlib'
        }
    }
});

if (typeof Cesium !== "undefined" && typeof Zlib !== "undefined") {
    onload(Cesium, Zlib);
} else if (typeof require === "function") {
    require(["Cesium", "Zlib"], onload);
}

1个回答

您好,能定位到是运行到哪一句报的错吗?还有您用的框架是什么?
5,560EXP 2018年02月28日
超图的webgl需要配置许可吗?代码是放在nodejs服务器上运行的

解决了,我将entry.js改成这样就好了

require.config({
    paths: {
        'Cesium': './libs/Cesium/Cesium',
        'Zlib': './libs/Cesium/Workers/zlib.min'
    },
    shim: {
        Cesium: {
            exports: 'Cesium'
        },
        Zlib: {
            exports: 'Zlib'
        }
    }
});

if (typeof Cesium !== "undefined" && typeof Zlib !== "undefined") {
    onload(Cesium, Zlib);
} else if (typeof require === "function") {
    require(["Cesium", "Zlib"], onload);
}

...