zoukankan      html  css  js  c++  java
  • 【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>

  • 相关阅读:
    第25周三
    第25周二
    第25周一
    第24周日
    第24周六
    第24周五
    第24周四经验感受想法
    第24周三
    第24周二
    01背包问题
  • 原文地址:https://www.cnblogs.com/defineconst/p/13065893.html
Copyright © 2011-2022 走看看