Cesium|xt3d动态水面

Cesium|xt3d动态水面

效果

在这里插入图片描述

代码

 <!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>cesium|xt3d</title>
    <!-- 引入Cesium -->
    <script src="https://cdn.jsdelivr.net/npm/cesium@1.84.0/Build/Cesium/Cesium.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cesium@1.84.0/Build/Cesium/Widgets/widgets.css">

    <!--  引入xt3d -->
    <script src="http://www.xt3d.cn/xt3dlib/xt3d.min.js"></script>
    <style>
        html,
        body,
        #map3d {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }
    </style>
</head>

<body>
    <div id="map3d"></div>
    <script>
        let xt3dInit = {
            init(el) {
                this.initViewer(el);
                this.load3dtiles();
                this.addHeliuRegion();
                this.setView();
            },

            //初始化viewer
            initViewer(el) {
                this.viewer = new Cesium.Viewer(el, {
                    infoBox: false,
                    selectionIndicator: false,
                    navigation: false,
                    animation: false,
                    shouldAnimate: false,
                    timeline: false,
                    baseLayerPicker: false,
                    geocoder: false,
                    homeButton: false,
                    sceneModePicker: false,
                    navigationHelpButton: false,
                    imageryProvider: new Cesium.UrlTemplateImageryProvider({
                        url: "https://t7.tianditu.gov.cn/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=tdtTk"
                    }),
                });

            },

            //添加河流水面
            addHeliuRegion() {
                const positions = [{
                    x: -1573646.574385626,
                    y: 5327862.998114007,
                    z: 3122882.0126497806
                }, {
                    x: -1573674.4927850217,
                    y: 5327841.079208016,
                    z: 3122905.0853668815
                }, {
                    x: -1573697.300247773,
                    y: 5327824.154858261,
                    z: 3122922.2296030447
                }, {
                    x: -1573723.2566743596,
                    y: 5327804.220696046,
                    z: 3122942.8339925
                }, {
                    x: -1573758.6792294222,
                    y: 5327780.238635048,
                    z: 3122965.933496034
                }, {
                    x: -1573782.7955957302,
                    y: 5327764.660988683,
                    z: 3122980.284263632
                }, {
                    x: -1573802.0711376078,
                    y: 5327753.162159477,
                    z: 3122989.961597303
                }, {
                    x: -1573818.2256981286,
                    y: 5327743.702623943,
                    z: 3122997.8881463786
                }, {
                    x: -1573836.390515118,
                    y: 5327730.24093674,
                    z: 3123011.720182871
                }, {
                    x: -1573853.867715565,
                    y: 5327716.870771106,
                    z: 3123025.672760408
                }, {
                    x: -1573881.363708308,
                    y: 5327696.189850067,
                    z: 3123046.939113487
                }, {
                    x: -1573917.6152507644,
                    y: 5327669.018123424,
                    z: 3123074.966586196
                }, {
                    x: -1573926.9820208312,
                    y: 5327662.461066732,
                    z: 3123081.351110614
                }, {
                    x: -1573938.1098204239,
                    y: 5327654.702930395,
                    z: 3123088.759295021
                }, {
                    x: -1573954.0176107218,
                    y: 5327644.379581239,
                    z: 3123098.291348635
                }, {
                    x: -1573964.7512216873,
                    y: 5327635.925342955,
                    z: 3123104.6748915347
                }, {
                    x: -1573984.9669868168,
                    y: 5327619.909903474,
                    z: 3123116.289125795
                }, {
                    x: -1573968.8319637552,
                    y: 5327616.4065885795,
                    z: 3123130.7026131423
                }, {
                    x: -1573944.0563865206,
                    y: 5327639.361826853,
                    z: 3123111.33203873
                }, {
                    x: -1573927.7554437916,
                    y: 5327650.519985489,
                    z: 3123100.7197816116
                }, {
                    x: -1573904.7711183839,
                    y: 5327666.247100797,
                    z: 3123085.6995552983
                }, {
                    x: -1573900.0844216363,
                    y: 5327669.12337478,
                    z: 3123083.13969443
                }, {
                    x: -1573882.656988854,
                    y: 5327682.386903352,
                    z: 3123069.5155642116
                }, {
                    x: -1573852.8168025815,
                    y: 5327705.006477089,
                    z: 3123045.985478789
                }, {
                    x: -1573826.1044827306,
                    y: 5327724.060820944,
                    z: 3123027.076716561
                }, {
                    x: -1573797.9909229,
                    y: 5327743.687548958,
                    z: 3123008.816503377
                }, {
                    x: -1573768.141830067,
                    y: 5327762.834272328,
                    z: 3122990.471647622
                }, {
                    x: -1573740.1560181207,
                    y: 5327780.735847701,
                    z: 3122974.151395415
                }, {
                    x: -1573710.2984952328,
                    y: 5327801.620498089,
                    z: 3122953.746622961
                }, {
                    x: -1573666.9494654608,
                    y: 5327834.72201891,
                    z: 3122919.660895541
                }, {
                    x: -1573633.8838709379,
                    y: 5327860.265334742,
                    z: 3122893.1117008366
                }]
                this.addWaterRegion(positions);
            },


            //添加水面
            addWaterRegion(positions) {
                let waterPrimitive = new xt3d.PolygonObject.WaterPrimitive(positions, {
                    baseWaterColor: Cesium.Color.AQUA.withAlpha(0.3),
                    normalMap: '/data.xt3d.cn/assets/images/polygon/waterNormalsSmall.jpg',
                    frequency: 1000.0,
                    animationSpeed: 0.03,
                    amplitude: 10.0,
                    specularIntensity: 5,
                });
                this.viewer.scene.primitives.add(waterPrimitive); //添加到场景
                // this.viewer.scene.primitives.remove(waterPrimitive); //从场景移除 
            },

            //加载3dtiles数据
            load3dtiles() {
                var tileset = this.viewer.scene.primitives.add(
                    new Cesium.Cesium3DTileset({
                        url: "http://www.xt3d.cn/data/offset_3dtiles/tileset.json",
                    })
                );

                tileset.readyPromise
                    .then(tileset => {
                        xt3d.TilesetPlugin.setTilesetHeight(tileset, 55);
                    })
                    .otherwise(function(error) {
                        console.log(error);
                    });
            },

            //设置视角
            setView() {
                this.viewer.scene.camera.setView({
                    duration: 1,
                    destination: {
                        x: -1573619.6471639725,
                        y: 5328105.434513959,
                        z: 3123157.3345488473
                    },
                    orientation: {
                        heading: 1.769495648542554,
                        pitch: -0.885008929765446,
                        roll: 0.004446235155041833
                    }
                });
            },

            destroy() {
                this.viewer.entities.removeAll();
                this.viewer.imageryLayers.removeAll(true);
                this.viewer.destroy();
            }
        }

        xt3dInit.init("map3d");
    </script>
</body>

</html>

预览地址

xt3d 在线预览地址

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xt3d

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值