【GIS】SuperMap加载三维服务

复制代码
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" 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="../libs/supermap10/Build/Cesium/Widgets/widgets.css">
        <script src="../libs/supermap10/examples/js/require.min.js" data-main="../libs/supermap10/examples/js/main.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://www.supermapol.com";
            var viewer, scene, widget;

            // 谷歌底图
            function googleMap() {
                // 删除之前影像
                viewer.imageryLayers.removeAll();
                // 创建影像图层
                var CIA_CImagery = new Cesium.UrlTemplateImageryProvider({
                    url: "http://mt1.google.cn/vt/lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}&s=Gali"
                });
                // 添加图层
                viewer.imageryLayers.addImageryProvider(CIA_CImagery);
            }


            function onload(Cesium) {
                viewer = new Cesium.Viewer('cesiumContainer');
                scene = viewer.scene;
                widget = viewer.cesiumWidget;

                googleMap(); 

                // openS3MLayerByScp(
                //     "http://www.supermapol.com/realspace/services/3D-niaocao_water/rest/realspace/datas/Tree@OlympicGreen.openrealspace"
                // ); 

                openS3MTerrainByScp("http://XXXX:8090/iserver/services/3D-nd/rest/realspace/datas/XXXX.openrealspace")
                openS3MLayerByScp(
                    "http://XXXX:8090/iserver/services/3D-nd/rest/realspace/datas/YYYY.openrealspace"
                ); 
 

                // URL_CONFIG.SiChuan_TERRAIN
                // "http://www.supermapol.com/realspace/services/3D-dixingyingxiang/rest/realspace/datas/DatasetDEM"
                // URL_CONFIG.SiChuan_IMG
                // "http://www.supermapol.com/realspace/services/3D-dixingyingxiang/rest/realspace/datas/MosaicResult"
                // var layer = viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
                //     url: "http://www.supermapol.com/realspace/services/3D-dixingyingxiang/rest/realspace/datas/MosaicResult"
                // })); 
                // openS3MTerrainByScp(
                //     "http://www.supermapol.com/realspace/services/3D-dixingyingxiang/rest/realspace/datas/DatasetDEM.openrealspace");
                // var layer = viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
                //     url: "http://www.supermapol.com/realspace/services/3D-dixingyingxiang/rest/realspace/datas/MosaicResult"
                // }));

            }

            sendRequestWithResponse = function(url, method) {
                var xhr = new XMLHttpRequest();
                xhr.open(method, url, false);
                xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
                xhr.send(null);
                return xhr.responseText;
            }

            function openS3MLayerByScp(url) {
                url = url.indexOf(".openrealspace") > -1 ? url.replace(".openrealspace", "") : url;
                var configUrl = url + "/config";
                var config = sendRequestWithResponse(configUrl, "GET");
                scene.addS3MTilesLayerByScp(configUrl, {
                    name: 1
                });
                var x = parseFloat(config.substring(config.indexOf("<sml:X>") + 7, config.indexOf("</sml:X>")));
                var y = parseFloat(config.substring(config.indexOf("<sml:Y>") + 7, config.indexOf("</sml:Y>")));
                var z = parseFloat(config.substring(config.indexOf("<sml:Z>") + 7, config.indexOf("</sml:Z>")));
                if (Math.abs(z - 0.0) < 0.000001) {
                    z = 120000;
                }
                console.log(z)
                scene.camera.setView({
                    destination: new Cesium.Cartesian3.fromDegrees(x, y, z)
                });
            }


            function openS3MTerrainByScp(url) {
                var sctUrl = url.indexOf(".openrealspace") > -1 ? url.replace(".openrealspace", "") : url;
                var configUrl = sctUrl + "/config";
                var config = sendRequestWithResponse(configUrl, "GET");
                viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
                    url: sctUrl,
                    isSct: true
                });
                var left = parseFloat(config.substring(config.indexOf("<sml:Left>") + "<sml:Left>".length, config.indexOf(
                    "</sml:Left>")));
                var right = parseFloat(config.substring(config.indexOf("<sml:Right>") + "<sml:Right>".length, config.indexOf(
                    "</sml:Right>")));
                var top = parseFloat(config.substring(config.indexOf("<sml:Top>") + "<sml:Top>".length, config.indexOf("</sml:Top>")));
                var bottom = parseFloat(config.substring(config.indexOf("<sml:Bottom>") + "<sml:Bottom>".length, config.indexOf(
                    "</sml:Bottom>")));
                var x = (left + right) / 2;
                var y = (top + bottom) / 2;
                var z = parseFloat(config.substring(config.indexOf("<sml:MaxHeight>") + "<sml:MaxHeight>".length, config.indexOf(
                    "</sml:MaxHeight>")));
                console.log(z)
                z = 80000;
                scene.camera.setView({
                    destination: new Cesium.Cartesian3.fromDegrees(x, y, z)
                });
            }
        </script>
    </body>
</html>
复制代码

 

posted @   咸鱼翻身  阅读(1480)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
历史上的今天:
2017-06-08 JavaScript jQuery 笔记
点击右上角即可分享
微信分享提示