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.loadBuildData();
                this.loadLines();
                this.loadHelius();
                this.setView();
            },

            //初始化viewer
            initViewer(el) {
                this.viewer = new Cesium.Viewer(el, {
                    infoBox: false,
                    selectionIndicator: false,
                    navigation: false,
                    animation: false,
                    timeline: false,
                    baseLayerPicker: false,
                    geocoder: false,
                    homeButton: false,
                    sceneModePicker: false,
                    navigationHelpButton: false,
                    shouldAnimate: false,
                    imageryProvider: new Cesium.ArcGisMapServerImageryProvider({
                        url: 'http://map.geoq.cn/arcgis/rest/services/ChinaOnlineStreetPurplishBlue/MapServer'
                    })
                });
                // 亮度设置
                var stages = this.viewer.scene.postProcessStages;
                this.viewer.scene.brightness = this.viewer.scene.brightness || stages.add(Cesium.PostProcessStageLibrary.createBrightnessStage());
                this.viewer.scene.brightness.enabled = true;
                this.viewer.scene.brightness.uniforms.brightness = 2;

                //是否开启抗锯齿
                this.viewer.scene.fxaa = true;
                this.viewer.scene.postProcessStages.fxaa.enabled = true;

            },

            //加载建筑物数据
            loadBuildData() {
                let tileset = this.viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
                    url: "http://www.xt3d.cn/data/country_build/chengdu_ajust_clip/tileset.json"
                }));

                tileset.readyPromise.then((tileset) => {
                    let cs = new xt3d.BuildingEffects.CustomShaderEffect(this.viewer, tileset, {
                        color: '0.2, 0.5, 1.0, 1.0', //颜色 rgba 浮点型 
                        glowRange: true, //是否显示光环
                        glowRangeHeight: '100.0', //光环范围 浮点型
                    });
                }).otherwise(function(error) {
                    console.error(error);
                });
            },

            //加载线数据
            loadLines() {
                var promise = Cesium.GeoJsonDataSource.load('/data.xt3d.cn/assets/data/chendu-daolu.json');
                promise.then((dataSource) => {
                    this.viewer.dataSources.add(dataSource);
                    let values = dataSource.entities.values;

                    for (var i = 0; i < values.length; i++) {
                        var line = values[i];
                        line.polyline.material = new Cesium.PolylineGlowMaterialProperty({ //设置Glow材质
                            color: Cesium.Color.fromCssColorString('#FF4500'),
                            glowPower: 0.2,
                            opacity: 0.8,
                        });
                        line.polyline.width = 12;
                    }
                }).otherwise(function(error) {
                    console.log(error)
                });
            },

            //添加水体数据
            loadHelius() {
                fetch("/data.xt3d.cn/assets/data/chendu-heliu.json").then(res => {
                    return res.json();
                }).then(res => {
                    let features = res.features;
                    let coordinates, positions;
                    features.map(feature => {
                        coordinates = feature.geometry.coordinates[0];
                        positions = this.coordinatesToPositions(coordinates);
                        this.addHeliu(positions);
                    })
                })
            },

            //添加一条河流
            addHeliu(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); //添加到场景 
            },

            //坐标串转为笛卡尔坐标数组
            coordinatesToPositions(coordinates) {
                let positions = [];
                coordinates.map(c => {
                    positions.push(Cesium.Cartesian3.fromDegrees(c[0], c[1], 0))
                });
                return positions;
            },

            //设置视角
            setView() {
                this.viewer.scene.camera.setView({
                    duration: 1,
                    destination: {
                        x: -1337790.7881094853,
                        y: 5330396.094162445,
                        z: 3231621.5380446212
                    },
                    orientation: {
                        heading: 6.010538181825211,
                        pitch: -0.6819480997380261,
                        roll: 6.282163306739159,
                    }
                });
            },

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

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

</html>

预览地址

xt3d 在线预览地址

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

xt3d

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

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

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

打赏作者

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

抵扣说明:

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

余额充值